1 / 11

Lecture 36: BlackJack!

Computer Science 313 – Advanced Programming Topics. Lecture 36: BlackJack!. Rules of Blackjack. Give each 2 cards at the very start When dealt cards match, make two hands (split) Request extra cards during turn (take a hit) Double bet & take one more card (double down)

xannon
Download Presentation

Lecture 36: BlackJack!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science 313 – Advanced Programming Topics Lecture 36:BlackJack!

  2. Rules of Blackjack • Give each 2 cards at the very start • When dealt cards match, make two hands (split) • Request extra cards during turn (take a hit) • Double bet & take one more card (double down) • Try to get close to 21, without going bust • Number cards (2, 3, 4, 5, …, 10) worth value • 10 points for each face card (Jack, Queen, King) • Each player can use Ace as 1 or 11 • Players win if they beat dealers hand

  3. Dealer Follows Rules • Dealer automatically wins when starting at 21 • Equal scores considered tie, otherwise • Very simple set of rules followed by dealer • Must take hit when hand is under 17 • Stands in when hand is high enough (18+) • On “soft-17” casino rules vary • Players should be able to win regularly • Casinos not built on losing • Many “winning” systems exist, however

  4. How To Not Lose Quickly • Track cards remaining in deck • Counting cards legal, but hard… • …counting relative values far easier • Remember how “rich” deck is • For each 10 or higher, subtract 1 point • Add 1 for 7s or lower seen so far • As deck score over many hands • Change strategies to reflect situation

  5. Developing this Program • Simple, straightforward program to write • Make decisions using deck’s current value • Deck’s score stored in a field • Update value each time a card is seen • To beat the house, develop complex set of rules • Write needHit(), doubleDown() and others • Each method has huge if-elseor switch • Hard to make minor changes to your strategy • Thinking about reusing code? Do not bother.

  6. Was That a Hint? • I left a big clue to solution in last slide • Hopefully, you started thinking design pattern • We already discussed this design pattern • Should be obvious choice to encourage reuse • Algorithm family changed dynamically needed

  7. Developing this Program • Simple, straightforward program to write • Make decisions using deck’s current value • Deck’s score stored in a field • Update value each time a card is seen • To beat the house, develop complex set of rules • Write needHit(), doubleDown()and others • Each method has huge if-else or switch • Hard to make minor changes to your STRATEGY • Thinking about reusing code? Do not bother.

  8. I’m Master of the Lost Art

  9. Close but not Quite • Strategy pattern holds obvious allure • Several reasons NOT to use this pattern, however • Reasons why strategy pattern inappropriate • Strategy changes internal to context instance • Means of tracking current state is lacking • Unable to find current strategy being used • For this to work, need to update strategies

  10. State Pattern Intent • Instances alter strategy when state changes • Includes Strategy pattern to define actions • Strategies responsible for changing themselves • Actions & state transitions delegated by instance • Perfect for use with finite state machines • Common tool from theory & software engineering • Can be found in many, many systems • Parsers • Systems performing real-time computing • User interface subsystems

  11. For Next Class • Lab due 1 week from today • Please, please, please do not wait until last minute… • Design is hard, but code is very simple • Give yourself time to think and ask questions • Read up on how we implement State pattern • Prepare so we can have fun activity next week

More Related