Problem Set 4: Video Poker

Similar documents
CS Project 1 Fall 2017

A Case Study. Overview. References. Video poker Poker.Card & Poker.Hand General.dll & game variants

Programming Assignment 4

PROBLEM SET 2 Due: Friday, September 28. Reading: CLRS Chapter 5 & Appendix C; CLR Sections 6.1, 6.2, 6.3, & 6.6;

DELIVERABLES. This assignment is worth 50 points and is due on the crashwhite.polytechnic.org server at 23:59:59 on the date given in class.

CS Programming Project 1

Project 2 - Blackjack Due 7/1/12 by Midnight

Poker Hands. Christopher Hayes

To play the game player has to place a bet on the ANTE bet (initial bet). Optionally player can also place a BONUS bet.

CS 210 Fundamentals of Programming I Fall 2015 Programming Project 8

CS 210 Fundamentals of Programming I Spring 2015 Programming Assignment 8

CARIBBEAN. The Rules

Poker: Further Issues in Probability. Poker I 1/29

Activity 6: Playing Elevens

CSE 231 Fall 2012 Programming Project 8

CATFISH BEND CASINOS RULES OF THE GAME THREE CARD POKER

TABLE GAMES RULES OF THE GAME

{ a, b }, { a, c }, { b, c }

HEADS UP HOLD EM. "Cover card" - means a yellow or green plastic card used during the cut process and then to conceal the bottom card of the deck.

CS 241 Data Organization using C. Project: Identifying the Rank of a Poker Hand and an Empirical Calculation of Probabilities

TABLE OF CONTENTS TEXAS HOLD EM... 1 OMAHA... 2 PINEAPPLE HOLD EM... 2 BETTING...2 SEVEN CARD STUD... 3

FOUR CARD POKER. Hand-- means the best four card poker hand that can be formed by each player and the dealer from the cards they are dealt.

TEXAS HOLD EM BONUS POKER

FLOP POKER. Rank-- or ranking means the relative position of a card or hand as set forth in Section 5.

Poker Rules Friday Night Poker Club

CATFISH BEND CASINOS, L.C. RULES OF THE GAME FOUR CARD POKER

A. Rules of blackjack, representations, and playing blackjack

Texas Hold'em $2 - $4

CS 152 Computer Programming Fundamentals Lab 8: Klondike Solitaire

FAST ACTION HOLD EM. Copy hand-- means a five-card hand of a player that is identical in rank to the five-card hand of the dealer.

COMP 9 Lab 3: Blackjack revisited

Counting Poker Hands

For this assignment, your job is to create a program that plays (a simplified version of) blackjack. Name your program blackjack.py.

Inheritance Inheritance

Electronic Wireless Texas Hold em. Owner s Manual and Game Instructions #64260

LEARN HOW TO PLAY MINI-BRIDGE

Ante or ante wager means the initial wager required to be made prior to any cards being dealt in order to participate in the round of play.

AP Computer Science Project 22 - Cards Name: Dr. Paul L. Bailey Monday, November 2, 2017

10, J, Q, K, A all of the same suit. Any five card sequence in the same suit. (Ex: 5, 6, 7, 8, 9.) All four cards of the same index. (Ex: A, A, A, A.

CSCI 4150 Introduction to Artificial Intelligence, Fall 2004 Assignment 7 (135 points), out Monday November 22, due Thursday December 9

ULTIMATE TEXAS HOLD EM

The Birds of a Feather Research Challenge. Todd W. Neller Gettysburg College November 9 th, 2017

CATFISH BEND CASINOS, L.C. RULES OF THE GAME FORTUNE PAI GOW

Poker Hand Rankings Highest to Lowest A Poker Hand s Rank determines the winner of the pot!

After receiving his initial two cards, the player has four standard options: he can "Hit," "Stand," "Double Down," or "Split a pair.

CHAPTER 649a. THREE CARD POKER

13:69E-1.13Z Criss cross poker; physical characteristics

Maryland State Lottery and Gaming Control Agency Standard Rules Criss Cross Poker

To use one-dimensional arrays and implement a collection class.

More Probability: Poker Hands and some issues in Counting

Maryland State Lottery and Gaming Control Agency Standard Rules - Double Draw Poker

Problem A. Worst Locations

GAMBLING ( ) Name: Partners: everyone else in the class

BRIDGE is a card game for four players, who sit down at a

UNIT 9B Randomness in Computa5on: Games with Random Numbers Principles of Compu5ng, Carnegie Mellon University - CORTINA

HIGH CARD FLUSH 1. Definitions

6/24/14. The Poker Manipulation. The Counting Principle. MAFS.912.S-IC.1: Understand and evaluate random processes underlying statistical experiments

PHASE 10 CARD GAME Copyright 1982 by Kenneth R. Johnson

Lab Exercise #10. Assignment Overview

9 Video Poker Paytables in 1 Game Ultimate X Triple Play Draw Poker provides a rich selection of the most popular video poker paytables:

LET IT RIDE POKER. Stub-- means the remaining portion of the deck after all cards in the round of play have been dealt or delivered.

Poker: Probabilities of the Various Hands

ProgrammingAssignment #7: Let s Play Blackjack!

E-GENTING PROGRAMMING COMPETITION 2016 General instructions:

Homework Assignment #2

Name: Checked: Answer: jack queen king ace

Assignment 1. Due: 2:00pm, Monday 14th November 2016 This assignment counts for 25% of your final grade.

No Flop No Table Limit. Number of

PLAYERS AGES MINS.

Problem A: Code Breaking

FORTUNE PAI GOW POKER

Welcome to the Best of Poker Help File.

13:69E 1.13Z 5 Card Hi Lo table; physical characteristics. (a) 5 card hi lo shall be played at a table having on one side

Live Casino game rules. 1. Live Baccarat. 2. Live Blackjack. 3. Casino Hold'em. 4. Generic Rulette. 5. Three card Poker

Up & Down GOAL OF THE GAME UP&DOWN CARD A GAME BY JENS MERKL & JEAN-CLAUDE PELLIN ART BY CAMILLE CHAUSSY

FreeCell Puzzle Protocol Document

2. A separate designated betting area at each betting position for the placement of the ante wager;

Roll & Make. Represent It a Different Way. Show Your Number as a Number Bond. Show Your Number on a Number Line. Show Your Number as a Strip Diagram

Poker: Probabilities of the Various Hands

Discrete Finite Probability Probability 1

Cards: Virtual Playing Cards Library

(e) Each 3 Card Blitz table shall have a drop box and a tip box attached to it on the same side of the table as, but on opposite sides of the dealer.

Activity 1: Play comparison games involving fractions, decimals and/or integers.

CSE231 Spring Updated 04/09/2019 Project 10: Basra - A Fishing Card Game

HOW TO PLAY BLACKJACK

CHAPTER 671a. LUNAR POKER. 671a.2. Lunar Poker table physical characteristics.

Item Description - MC Phi - Please note: any activity that is not completed during class time may be set for homework or undertaken at a later date.

Name: Checked: jack queen king ace

POKER. Bet-- means an action by which a player places gaming chips or gaming plaques into the pot on any betting round.

Simple Poker Game Design, Simulation, and Probability

Ch. 670a SIX-CARD FORTUNE PAI GOW POKER a.1. CHAPTER 670a. SIX-CARD FORTUNE PAI GOW POKER

P a g e 1 HOW I LEARNED POKER HAND RANKINGS

CRISS-CROSS POKER. Community cards Cards which are used by all players to form a five-card Poker hand.

CHAPTER 69F RULES OF THE GAMES

PAI GOW POKER PROCEDURES

CHAPTER 641a. FOUR CARD POKER

Philadelphia Classic 2013 Hosted by the Dining Philosophers University of Pennsylvania

BLACKJACK Perhaps the most popular casino table game is Blackjack.

CS107L Handout 06 Autumn 2007 November 2, 2007 CS107L Assignment: Blackjack

OALCF Task Cover Sheet. Apprenticeship Secondary School Post Secondary Independence

Transcription:

Problem Set 4: Video Poker Class Card In Video Poker each card has its unique value. No two cards can have the same value. A poker card deck has 52 cards. There are four suits: Club, Diamond, Heart, and Spade. Each suit has thirteen individual cards: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace. We define the following order over cards: For example: Club < Diamond < Heart < Spade 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < Jack < Queen < King < Ace 4D 4S KD JS is smaller than, whereas is greater than. The ICard interface: public interface ICard : IComparable { // Returns the number (2 14) of a Poker card. int Number { get; } // Returns the suit of a Poker card. // enum CardSuit {Club, Diamond, Heart, Spade} CardSuit Suit { get; } // Returns the two character name of a Poker card. string Name { get; } // overridden Equals method bool Equals( object aother ); // overridden GetHashCode method int GetHashCode(); } // Returns a string that represents the current card. // For example, Suit = CardSuit.Spade, Number = 10 => TS string ToString(); 1

The class Card should define two public constructors: public Card( int anumber, CardSuit asuit ) { } This constructor takes an integer and a CardSuit argument Card KingOfHearts = new Card( 13, CardSuit.Heart); public Card( string aname ) { } This constructor takes one Card-string argument Card EightOfDiamonds = new Card( 8D ); The class Card does not define a default constructor. Class Deck A Poker deck contains 52 different cards. Since the size of the deck never changes, we can use an array of fixed size to store all cards in the deck. Note, however, that you may need an additional array to arrange the cards in a random order. public interface IDeck : IEnumerable { // Arranges all 52 cards in the deck in a random order. void Shuffle(); // Returns a string representation of the deck. That is, a string // containing of 52 card names separated by space. string Text { get; } } // See Text. string ToString(); The class Deck defines one public constructor that takes no argument. The purpose of the constructor is to instantiate a Poker deck consisting of 52 cards. 2

Class Tray The tray is a container that can hold up to 5 cards. A Tray object is used to transfer cards between different parts of the Video Poker application. public interface ITray { // Adds a set of cards to the tray. // May throw InvalidOperationException, if tray is full. void AddRange( ICard[] asetofcards ); // Adds one card to the tray. // May throw InvalidOperationException, if tray is full. void Add( ICard acard ); // Removes all cards from the tray. void Clear(); // Returns the number of cards currently stored in the tray. int Count { get; } } // Returns the card at index. // May throw ArgumentOutOfRangeException. ICard this [int index] { get; } The class Tray may define one constructor that takes no argument to set up the internal infrastructure to hold up to five cards. 3

Class Hand The class Hand represents a Poker hand. A hand contains exactly 5 cards. The class Hand does not only implement an abstraction to represent a Poker hand, but it also partly defines the Poker game logic, since it defines a method to calculate the score of a given hand. public interface IHand : IComparable { // Returns the score of the current hand. int Score { get; } // Returns a text representation of the score. // For example: Full House string Title { get; } // Returns a string representation of the current hand. // For example: 3D 3H 3S KC KS string Text{ get; } // Returns the Card object indexed by a card name. // May throw ArgumentOutOfRangeException if the requested card // cannot be found. ICard this [string i] { get; } // Returns the Card object indexed by its position. // May throw ArgumentOutOfRangeException. ICard this [int i] { get; } // Fills atray with the cards specified in aholdstring. void DiscardCards( ITray atray, string aholdstring ); // Replaces the cards specified in aholdstring. void ReplaceCards( ITray atray, string aholdstring ); } // See Text. string ToString(); The class Hand defines one public constructor: public Hand( ICard[] acardset ) So, to create a new Hand object one has to put the cards into an array. The constructor always expects 5 cards. If the constructor is called with fewer cards, the an exception will be thrown (e.g., ArgumentOutOfRangeException). 4

Hand Score Table: Score Title 0 No Score 2 Jacks or Better 3 Two Pair 4 Three of a Kind 5 Straight 6 Flush 7 Full House 8 Four of a Kind 9 Straight Flush 10 Royal Flush A Poker Scenario At the beginning of each new Poker round the dealer shuffles the deck and deals out 5 cards to each Player (in the case of Video Poker there is only one player). The dealer has to use a tray to transfer the cards to the corresponding player. The player receiving the filled tray has to construct a fresh Hand object based of the received cards. Since the class Hand only provides a public constructor with the following signature: public Hand( ICard[] acardset ), the cards in the tray have to be taken out of it and put in an array without changing the order. The constructor stores the cards in the order they have been dealt (i.e., the external visible order of the cards in the Hand object has to remain the same at all times). Now, the player can chose to discard none, some, or all of these cards in an attempt to improve the hand s score. That is, the player specifies a hold string consisting of the positions of the cards (1 5) and calls the Hand s method DiscardCards. This method will fill the tray with the selected cards. The player uses the tray to request replacement cards from the dealer. Once the dealer receives the tray, the dealer will replace the discarded cards with new cards and return the tray to the player. The player will use the cards in the tray to substitute the discarded cards. The class Hand provides two methods to replace cards: DiscardCards and ReplaceCards. Both methods have two arguments: a Tray object and a hold string. The method DiscardCards fills the tray with the cards to be discarded, whereas the method ReplaceCards exchanges the discarded cards. 5

Calculating the Score of a Hand In order to calculate the score of a hand, the cards of the hand have to be sorted first. This operation must preserve the external view of the hand. That is, if we have the following hand: 5H KD 5C 2S AH then a proper internally sorted hand is 2S 5C 5H KD AH The cards in the hand should be stored in an array. The.NET Array class has a method public static void Sort( Array array ) that sorts the array using QuickSort on elements that implement the IComparable interface. In order to calculate the score, use an integer array, which contains the card numbers: int[] SortedHand. For example, using the above card set, the array SortedHand contains {2, 5, 5, 13, 14}. To facilitate the score calculation you may also define the following auxiliary methods: bool IsStraight( ICard[] SortedCards ) { } returns true if SortedHand is a straight (e.g. 3D 4S 5C 6H 7H ) bool IsStraightToAce( ICard[] SortedCards ) { } returns true if SortedHand is a straight to the ace (e.g. TD JS QC KH AH ) bool IsStraightFromAce( ICard[] SortedCards ) { } returns true if SortedHand is a straight from the ace (e.g. 2S 3C 4H 5H AD ) bool IsFlush( ICard[] SortedCards ) { } returns true if SortedHand is a flush (e.g. 3H 5H 7H TH QH ). 6

Score calculation is decribed by the following Pseudo code: if ( IsStraightToAce && IsFlush ) then Score = 10; if ( IsStraight && IsFlush ) then Score = 9; if ( (first four elements in SortedHand are equal) (last four elements in SortedHand are equal) ) then Score = 8; if ( ((first three elements in SortedHand are equal) && (last two elements in SortedHand are equal)) ((first two elements in SortedHand are equal) && (last three elements in SortedHand are equal)) ) then Score = 7; if ( IsFlush ) then Score = 6; if ( IsStraight ) then Score = 5; if ( (first three elements in SortedHand are equal) (second, third, and fourth element in SortedHand are equal) (last three elements in SortedHand are equal) then Score = 4; if ( ((first and second element in SortedHand are equal) && (third and fourth element in SortedHand are equal)) ((first and second element in SortedHand are equal) && (fourth and fifth element in SortedHand are equal)) ((second and third element in SortedHand are equal) && (fourth and fifth element in SortedHand are equal)) ) then Score = 3; if ( ((first and second element in SortedHand are equal) && (first element in SortedHand > 10)) ((second and third element in SortedHand are equal) && (second element in SortedHand > 10)) ((third and fourth element in SortedHand are equal) && (third element in SortedHand > 10)) ((fourth and fifth element in SortedHand are equal) && (fourth element in SortedHand > 10)) ) then Score = 2; else Score = 0; 7

Hand Ranking To decide, which poker hand is better, we define the following order over hands: Royal Flush: Straight Flush: Four of a Kind: Full House: Flush: Straight: Three of a Kind: Two Pair: Jacks or Better: If two royal flushes tie, use suit. When two straights tie, the higher straight wins. If two straights have the same value, use suit. If there are two or more hands that qualify, the hand with the higherranked Four of a Kind wins. When there are two full houses the tie is broken by the Three of a kind. When flushes tie, follow the rule for High Card. When two straights tie, the higher straight wins. If two straights have the same value, then High Card breaks ties. The highest-ranking Three of a Kind wins. The highest-ranking pair wins ties. High Card breaks ties between the sets of Two Pair. The highest-ranking pair wins. High Card breaks ties. High Card (not used in Video Poker): The highest-ranking card wins. This rule has a unique solution due to problem statement. 8

Class Dealer & Player The class Dealer implements the Poker dealer logic. However, the dealer is eventbased, that is, the player and dealer communicate using events. The following diagram illustrates the interaction: The necessary definitions: // Dealer notifies player to pick up cards. public delegate void CardsAvailableHandler( ITray atray ); // Player notifies dealer to start a new round. public delegate void StartRoundHandler(); // Player notifies dealer to replace cards in tray. public delegate void RequestCardsHandler( ITray atray ); // Player notifies dealer to stop round. public delegate void EndRoundHandler( ITray atray ); public interface IDealer { // Event to signal that new cards are available to the player. event CardsAvailableHandler OnCardsAvailable; // Event handler for the player s OnRequestCards event. void RequestCards( ITray atray ); // Event handler for the player s OnStartRound event. void StartRound(); // Event handler for the player s OnEndRound event. void EndRound( ITray atray ); } // Register a specific player. void RegisterPlayer( IPlayer aplayer ); 9

// Player notifies console that the hand has changed. public delegate void DataReadyHandler(); public interface IPlayer { // Event to signal that the dealer should start a new round. event StartRoundHandler OnStartRound; // Event to signal that the dealer should deal new cards. event RequestCardsHandler OnRequestCards; // Event to signal that the dealer should end the current round. event EndRoundHandler OnEndRound; // Event to signal that the console to display the player s hand. event DataReadyHandler OnDataReadyStart; // Event to signal that the console to display the player s hand. event DataReadyHandler OnDataReadyDraw; // Returns the current hand of the player. IHand Hand { get; } // Event handler for the dealer s OnCardsAvailable event. void CardsAvailable( ITray atray ); // Initiate a new game. This method will fire the OnStartRound // event. void NewGame(); // Discard and replace cards. This method will fire the // OnRequestCards event. void Draw( string aholdstring ); } // End current game. This method will fire the OnEndRound // event. void EndGame(); Problem 1 Create an empty Visual Studio.NET solution named VideoPoker. Add a new class library project PokerGeneral.dll to the solution that contains all the above-mentioned classes and interfaces. Problem 2 Add a new Windows application project WinVideoPoker to the solution that uses the PokerGeneral assembly (i.e., the DLL). Create a class Game and a class Player that implement a Video Poker console application. The Main Form must also implement two event handlers, one for the OnDataReadyStart event and one for the OnDataReadyDraw event, which are part of the game logic. 10

Game sequence: Start: Game started using the Player s NewGame method, which triggers the OnDataReadyStart event (handler must enable Draw button): Cards-to-hold selected and Draw button pressed. Draw click event handler invokes the Player s Draw method using an appropriate hold string. This will trigger the Players OnDataReadyDraw event. 11

To manage the bitmaps of the card it is recommended to use ImageList objects: Also, set the BackColor to MidnightBlue, the ForColor to Yellow, and the Font size of the label in the center and to two game control buttons to 14pts. Submission deadline: Monday, October 17, 2004, 4:10 p.m. Submission procedure: on paper in class (.cs files only) and electronically using the turnin-hw4 script, which is located in ~cs430x/public/bin. Please use the printout of the submission confirmation email as cover page and check the problems that you have solved. In order to submit your homework solutions, go (using your CS UNIX account) into the directory that contains your solution (i.e., C#-source files and all related project files). In that directory run the command ~cs430x/public/bin/turnin-hw4. After a successful submission, your will receive a confirmation email. Before the due date, you can resubmit your solutions as often as you like. On the department s Windows XP systems you can use the command csc to compile C#-programs. However, it is recommended to use Visual Studio.NET, because most assignments require some GUI work. 12