Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LINK NEEDED FOR THE ASSIGNMENT----->http://www.cse.msu.edu/~cse231/Projects/Project06/ The goal of this project is to gain practice with use of classesand creating functions. You will design and implement

LINK NEEDED FOR THE ASSIGNMENT----->http://www.cse.msu.edu/~cse231/Projects/Project06/

The goal of this project is to gain practice with use of classesand creating functions. You will design and implement a Pythonprogram which plays simplified Texas Hold’em Poker. The programshould deal two cards to two players (one card to each player, thena second card to each player), and then five community cards whichplayers share to make their hands. A poker hand is the best fivecards from the community cards plus the player’s cards (i.e., best5 out of 7 cards total).

The goal of this assignment is to find the category of eachplayer’s hand and determine the winner. The rules of this game arerelatively simple and you can find information about the game andabout the poker hands in the links below. Keep in mind that youwill only find the category of the hands and all nine cards can bedealt at once (a real poker game deals cards in stages to allow forbetting, but we aren’t betting).http://en.wikipedia.org/wiki/Texas_holdem

http://en.wikipedia.org/wiki/Poker_hands

The categories in order from lowest to highest are: High card, 1pair, 2 pair, 3 of a kind, straight, flush, full house, 4 of akind, straight flush. You will not find a player’s hand’s value,but just the category of the hand. It is a tie if both players havehands in the same category. That is, if both of them havestraights, it is considered a tie no matter who has the higherstraight.

Our game is simplified in two ways:

1. We only compare categories to determine the winner, not thevalue of the hands. For example, in a real poker game the winner ofhands with exactly one pair would be determined by which pair hadthe highest card rank. That is, a pair of 10s wins over a pair of3s. In our game, two hands with exactly one pair is considered atie with no consideration given to the card ranks.

2. The Card class ranks an Ace as the lowest card in a suit;whereas traditional poker ranks an Ace as highest. For simplicity,we will keep Aces as the lowest ranked card because we are onlycomparing categories not values. In particular, the cards 10h, Jh,Qh, Kh, Ah are not considered to make a straight in our game (theywould under normal poker rules).

Assignment Specifications

1. Your program will use the Card and Deck classes found in thefile named cards.py. You may not modify the contents of that file:we will test your project using our copy of cards.py. We haveincluded a cardsDemo.py program to illustrate how to use the Cardand Deck classes.

2. Your program will be subdivided into meaningful functions.Use a function for each category (except that “high-card” doesn’tneed a function). See hints below.

3. Your program will display each player’s dealt cards, thecommunity cards, and announce the winner of the hand. Also, yourprogram will display the winning combination (or either of thewinning combinations, if a tie) as well as the category of thewinning hand (see sample output below). For example, if the winningcombination is “four-of-a-kind”, those four cards will bedisplayed; the fifth card in the hand will not be displayed. Thedisplay will be appropriately labeled and formatted.

4. After each run, the program will prompt the user if they wantto see another hand: “do you want to continue: y or n”. The programshould continue if user enters “y” or “Y”; otherwise, the programshould halt. Also, if there are fewer than 9 cards left in thedeck, the program should halt. Do not shuffle between hands; onlyshuffle at the beginning of the program.

5. Using dictionaries in this assignment is very useful as youcan find how many cards have the same suit, or how many of themhave the same rank. Most of my functions used a dictionary that hadrank as the key, so I created a separate function to build such adictionary from a hand.

Hints

1. There are 9 categories of hands. For each category (excepthigh-card), I wrote a function that would take as an argument alist of 7 cards and return either a sub-list of cards thatsatisfied that category or an empty list. That design let me usethe functions in Boolean expressions since an empty list evaluatesto False whereas a non-empty list evaluates to True. Returning alist of cards also allowed me to use functions within functions,e.g., a straight flush must be a flush. Returning a list of cardsalso made testing easier because I could see not only that thefunction had found a combination of that type, but I also couldeasily check that it was correct. By the way, the function to finda straight was the hardest function to write.

2. Finding a winner is simple: start with the highest categoryand work your way down the categories in a cascade of “if” and“elif” statements. The result is a long, but repetitive structure.(You do not need to check all possible combinations of handsbecause you are only trying to find the highest category that ahand fits.)

3. Think strategically for testing. Custom build a set of handsfor testing by creating particular cards, e.g. H1 = [5c, 2c, 5h,4s, 3d, 2h, 5d] can be used to test for a full house (I had tocreate each card first, e.g. c1 = cards.Card(5,1) to create the 5ccard in H1. It took many lines to create the testing hands, butonce built they proved useful.) Test each category functionseparately using the custom hands you created for testing. Forexample, result = full_house(H1) should yield a result [5c, 5h, 5d,2c, 2h].

4. I found dictionaries useful within functions. Sometimes usingthe rank as key worked best; other times using the suit as key wasbest.

5. In order for sort() and sorted() to work on any data type theless-than operation must be defined. That operation is not definedin the Cards class so neither sort() nor sorted() work on Cards.(We tried to make the Cards class as generic as possible to workwith a wide variety of card games, and the ordering of cardsconsidering both rank and suit varies across card games.)

SAMPLE OUTPUT

(Note that this output uses the default suit_list from cards.py:suit_list = ['x','c','d','h','s'] )

---------------------------------------- Let's play poker!

Community cards: [9d, 3d, 6s, 2s, 2d]

Player 1: [4h, 5c]

Player 2: [9c, 5h]

Player 1 wins with a straight:[2s, 3d, 4h, 5c, 6s]

Do you wish to play anotherhand?(Y or N) y

----------------------------------------

Let's play poker!

Community cards: [Ks, 6d, Kc, 5s,9h]

Player 1: [4c, 10s]

Player 2: [7s, Qc]

TIE with one pair: [Ks, Kc] Doyou wish to play another hand?(Y or N) y

----------------------------------------

Let's play poker!

Community cards: [Jc, 8h, Jd, Js,3c]

Player 1: [3h, 4d]

Player 2: [As, 7c]

Player 1 wins with a full house:[Jc, Jd, Js, 3h, 3c]

Do you wish to play anotherhand?(Y or N) y

----------------------------------------

Let's play poker!

Community cards: [Qs, 4s, 8d, 2h,Qd]

Player 1: [7d, 6c]

Player 2: [2c, 8s]

Player 2 wins with two pairs:[8s, 8d, 2c, 2h]

Do you wish to play anotherhand?(Y or N) y

----------------------------------------

Let's play poker!

Community cards: [10h, 7h, 10d,Kh, Ah]

Player 1: [9s, Ad]

Player 2: [Ac, 3s]

TIE with two pairs: [10h, 10d,Ad, Ah]

Deck has too few cards so game isdone.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions

Question

Describe the common characteristics of organizational culture. LO.1

Answered: 1 week ago