Download presentation

Presentation is loading. Please wait.

Published byJevon Monk Modified over 2 years ago

1
CSE 332: Lab 6 overview Overview of Lab 6 Your Lab 6 program will –Correct a glitch in the lab 5 specification Use exceptions only for abnormal flow control –Replace native arrays with STL class template containers (and update code accordingly) E.g., set, map, vector –Add two (or three) new games 5 card stud poker –Polynomial function to construct a unique integer for each hand 5 card draw poker –Deal cards, rank and print, replace some cards, rank and print Hold ‘em poker (team projects only) –Each player has two of their own cards –Combine with “best 3” of 3 then 4 then 5 common cards

2
CSE 332: Lab 6 overview Exceptions and Flow Control Lab 5 check_players method –Threw an exception if too few players in game –Behavior “guarded” game’s continuation If there were too few/many players, threw exception –However, this used exceptions for “normal” control Even if briefly (i.e., the remainder of the check_players method) Lab 6 check_players method –Has a boolean result, returns true if and only if the number of players is acceptable for that game –Called as the first thing in each game’s deal_cards method –Game’s deal_cards method throws an exception if false –Still guards game’s continuation –Exception path is better distinguished from normal path

3
CSE 332: Lab 6 overview Replacing Native Arrays with STL Containers Replacing arrays with STL containers –Relieves much of the burden of implementing, debugging, and testing memory management –Provides additional flexibility (e.g., via functors) Which containers should we use, and when? –Let’s look both at what’s being contained … Players vs. cards vs. pointers to players or cards –… and also for what use the container is needed Enforcing different orders, sorting after dealing, etc.

4
CSE 332: Lab 6 overview Replacing Native Arrays with STL Containers (2) Keeping cards in a deck or a hand –Low overhead of copying card objects –Card objects are not polymorphic –Different orders are enforced for different uses E.g., rank then suit vs. suit then rank Which container(s) should we use, and when? 7D AH 7S AD AC Suggestion: set (or multi-set)

5
CSE 332: Lab 6 overview Replacing Native Arrays with STL Containers (3) Keeping players in a game –Higher overhead than copying card objects But not too expensive –Order depends on only one field player’s name Which container(s) should we use, and when? Suggestion: map or multimap key: player’s name item: player object

6
CSE 332: Lab 6 overview Replacing Native Arrays with STL Containers (4) Ranking players hands –Need to alias existing objects Rather than making an expensive deep copy –Order is (re)established at run-time As cards are dealt and drawn Which container(s) should we use, and when? Suggestion: vector of pointers

7
CSE 332: Lab 6 overview Replacing Native Arrays with STL Containers (5) Different combinations of cards (team project) –Again want to alias existing objects Rather than making a (albeit less expensive) deep copy Also can make the solution less complex –Order and membership (re)established at run-time As cards are dealt and new combinations are tried Which container(s) should we use, and when? Suggestion: set or vector (shown) of pointers vector: random access to positions set: maintains invariant order

8
CSE 332: Lab 6 overview 5 Card Stud Poker 5 cards dealt to each of 5-8 players Reuses most of lab 5 infrastructure –Can use a polynomial function to construct a unique integer for each hand’s score –6 digit base 13 number is one approach –Bounded by 13 6 = 4,826,809 (much less than 2 32 ) hand rank card rank card rank card rank card rank card rank score = a*13 5 + b*13 4 + c*13 3 + d*13 2 + e*13 + f abcdef

9
CSE 332: Lab 6 overview 5 Card Stud Poker, Continued Ranks of poker hands (for all lab 6 games) straight flush > four-of-a-kind > full-house > flush > straight > three-of-a-kind > two-pair > one-pair > nothing –Can simply number these 8 down to 0 to value a Then, for each hand set some of b through f to card ranks, and set the others to zero –E.g., for card rank ace is 12 down to 2 which is 0 –E.g., for straight flush a = 8, b = rank of high card –E.g., for full house a = 6, b = the rank of the triple, and c = the rank of the pair hand rank card rank card rank card rank card rank card rank score = a*13 5 + b*13 4 + c*13 3 + d*13 2 + e*13 + f abcdef Note: you are welcome to choose a different polynomial, or even a different ordering mechanism as long as it ranks hands correctly

10
CSE 332: Lab 6 overview 5 Card Draw Poker 5 cards dealt to each of 5-8 players Depending on the hand, replace 0-5 cards –Keep the most valuable cards, replace others But only if doing so has higher chance of improving E.g., replacing odd card in 4 of a kind doesn’t affect relative hand ranking in non-wild card games (why?), but specified to do so if the chances favor improving QSQHQDQC7C |{A,K,J,10,9,8}| > |{6,5,4,3,2}| so draw

11
CSE 332: Lab 6 overview 5 Hold ‘em Poker 2 cards dealt to each of 5-8 players 3 cards, then a 4 th then a 5 th dealt on table –All players share the table cards –All players make 5 card hands from theirs + three cards from the table (in the best combination) QSQH QD2C KDJD 7D7CAD 7S7H QSQH QD7D7C full house QD7DAD KDJD flushfour-of-a-kind 7D7CAD 7S7H

12
CSE 332: Lab 6 overview A Few More Comments Design decisions are largely yours to make If the specification differs from what you think should be done, please ask –If it’s a reasonable alternative, I’ll approve it Extra credit (up to 5 points) is available for writing up your design decisions thoroughly –Please do this as you go so you can remember what you did and why and what alternatives you discarded along the way Please start early so we can be of the most help in answering questions etc.

13
CSE 332: Lab 6 overview For Next Time (a Week from Today) Topic: More on C++ Typedefs and Traits Reading Assignment –pp. 210, 1075-1076

Similar presentations

OK

Week 7 Part I Kyle Dewey. Overview Code from last time Array initialization Pointers vs. arrays Structs typedef Bubble sort (if time)

Week 7 Part I Kyle Dewey. Overview Code from last time Array initialization Pointers vs. arrays Structs typedef Bubble sort (if time)

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Doc to ppt online converter free Ppt on transportation class 10 Ppt on zener diode current Ppt online shopping cart Ppt on online mobile recharge Balance sheet reading ppt on ipad Seminar ppt on cloud computing Ppt on pi in maths the ratio Mp ppt online counselling 2012 Ppt on sixth sense technology free download