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.

Slides:



Advertisements
Similar presentations
Jacqueline Wroughton Joseph Nolan Northern Kentucky University.
Advertisements

© Glenn Rowe AC Lab 2 A simple card game (twenty- one)
CSE 332: C++ overview CSE 332 Overview and Structure CSE 332 emphasizes studio-based active learning –Introductory lecture material followed by hands-on.
Ch 7 B.
CSE 332: C++ memory management idioms C++ Memory Management Idioms Idioms are reusable design techniques in a language –We’ll look at 4 important ones.
Object Oriented Programming Elhanan Borenstein Lecture #12 copyrights © Elhanan Borenstein.
Computer Science 313 – Advanced Programming Topics.
Templates and the STL Bryce Boe 2012/09/10 CS32, Summer 2012 B.
Discrete Structures & Algorithms More Counting. + + ( ) + ( ) = ? Counting II: Recurring Problems and Correspondences.
CS 240: Data Structures Thursday, June 21 th Vector, Linked List.
Hash Tables1 Part E Hash Tables  
Intro to Probability & Games
CS 106 Introduction to Computer Science I 11 / 08 / 2006 Instructor: Michael Eckmann.
CS 410 Applied Algorithms Applied Algorithms Lecture #5 Sorting.
CS 106 Introduction to Computer Science I 04 / 21 / 2008 Instructor: Michael Eckmann.
CMSC 202 Lesson 24 Iterators and STL Containers. Warmup Write the class definition for the templated Bag class – A bag has: Random insertion Random removal.
CS 106 Introduction to Computer Science I 04 / 28 / 2010 Instructor: Michael Eckmann.
A R R A Y ! for Multiplication!!
1 The game of poker You are given 5 cards (this is 5-card stud poker) The goal is to obtain the best hand you can The possible poker hands are (in increasing.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
The Parameterized Poker Squares EAAI NSG Challenge
Permutations and Combinations
Passing Other Objects Strings are called immutable which means that once a String object stores a value, it never changes –recall when we passed a message.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Game Rules Rules define game objects and define allowable actions by the players.
Game Rules Rules define game objects and define allowable actions by the players.
Basic Counting Lecture 12: Oct 28. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations,
3.8 Counting Techniques: Combinations. If you are dealt a hand in poker (5 cards), does it matter in which order the cards are dealt to you? A  K  J.
1 Melikyan/DM/Fall09 Discrete Mathematics Ch. 6 Counting and Probability Instructor: Hayk Melikyan Today we will review sections 6.4,
Basic Counting. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations, combinations.
Please have hw out to correct.. Equations with Two Variables Lesson 8-2 p.391.
CSE 332: C++ memory management idioms C++ Memory Management Idioms Idioms are reusable design techniques in a language –We’ll look at 4 important ones.
Learning to Play KardKuro Goals: Have Fun while Practicing Addition and Subtraction. Improve Social Learning Opportunities with Classmates. Become familiar.
Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#
30/10/ Iteration Loops Do While (condition is true) … Loop.
CSE 332: C++ STL containers Review: C++ Standard Template Library (STL) The STL is a collection of related software elements –Containers Data structures:
Discrete Mathematics for Computer Science. + + ( ) + ( ) = ? Counting II: Recurring Problems and Correspondences Chapter 9 slides 1-54.
CS 106 Introduction to Computer Science I 04 / 23 / 2010 Instructor: Michael Eckmann.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Ch Counting Principles. Example 1  Eight pieces of paper are numbered from 1-8 and placed in a box. One piece of paper is drawn from the box, its.
Chapter 5 Array-Based Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
CSE 425: Control Abstraction I Functions vs. Procedures It is useful to differentiate functions vs. procedures –Procedures have side effects but usually.
CE Operating Systems Lecture 17 File systems – interface and implementation.
CSE 332: Memory management with C++ classes Memory Management with Classes Review: for non-static built-in (native) types –default constructor and destructor.
Word Create a basic TOC. Course contents Overview: table of contents basics Lesson 1: About tables of contents Lesson 2: Format your table of contents.
Chapter 5 Array-Based Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Game Procedures Who does what, where, when, and how?
LISTS. LEARNING OBJECTIVES Create a block that accepts a parameter Create a block that returns a value Create scripts that manipulates lists Incorporate.
Week 7 Part I Kyle Dewey. Overview Code from last time Array initialization Pointers vs. arrays Structs typedef Bubble sort (if time)
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
CSE 532: Lab 2 design overview Overview and Discussion of Lab 2 Design Expand the work from a single scene to entire play –I.e., process a sequence of.
Stat 35b: Introduction to Probability with Applications to Poker Outline for the day: 1.Expected value. 2.Heads up with AA. 3.Heads up with Gus vs.
C++ Functions A bit of review (things we’ve covered so far)
Unit VI.  C++ templates are a powerful mechanism for code reuse, as they enable the programmer to write code (classes as well as functions) that behaves.
Sorting and Runtime Complexity CS255. Sorting Different ways to sort: –Bubble –Exchange –Insertion –Merge –Quick –more…
Probability and statistics - overview Introduction Basics of probability theory Events, probability, different types of probability Random variable, probability.
Texas Holdem A Poker Variant vs. Flop TurnRiver. How to Play Everyone is dealt 2 cards face down (Hole Cards) 5 Community Cards Best 5-Card Hand Wins.
Motivation for Generic Programming in C++
Memory Management with Classes
Data Abstraction: The Walls
The Parameterized Poker Squares EAAI NSG Challenge
Probability of casino games
A R R A Y ! for Multiplication!!
Basic Counting.
Do While (condition is true) … Loop
Lial/Hungerford/Holcomb/Mullins: Mathematics with Applications 11e Finite Mathematics with Applications 11e Copyright ©2015 Pearson Education, Inc. All.
Counting II: Recurring Problems And Correspondences
Combinations.
Term Project: Poker Game
A R R A Y ! for Multiplication!!
Presentation transcript:

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

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

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.

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)

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

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

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

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* b* c* d* e*13 + f abcdef

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* b* c* d* 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

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

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

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.

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