Design and implement a python program which plays poker

Assignment Help Python Programming
Reference no: EM131099654

Programming Project

Assignment Overview

This assignment focuses on the design, implementation and testing of a Python program which uses classes to solve the problem described below. Note: you are using a class we provide; you are not designing a class.

Assignment Deliverable

The deliverable for this assignment is the following file: proj06.py - the source code for your Python program

Be sure to use the specified file name and to submit it for grading via the handin system before the project deadline.

Assignment Background

The goal of this project is to gain practice with use of classes and creating functions. You will design and implement a Python program which plays simplified Texas Hold'em Poker.

The program should deal two cards to two players (one card to each player, then a second card to each player), and then five community cards which players share to make their hands. A poker hand is the best five cards from the community cards plus the player's cards (i.e., best 5 out of 7 cards total). The goal of this assignment is to find the category of each player's hand and determine the winner.

The rules of this game are relatively simple and you can find information about the game and about the poker hands in the links below. Keep in mind that you will only find the category of the hands and all nine cards can be dealt at once (a real poker game deals cards in stages to allow for betting, but we aren't betting).

https://en.wikipedia.org/wiki/Texas_holdem
https://en.wikipedia.org/wiki/Poker_hands

The categories in order from lowest to highest are: High card, 1 pair, 2 pair, 3 of a kind, straight, flush, full house, 4 of a kind, 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 have hands in the same category. That is, if both of them have straights, it is considered a tie no matter who has the higher straight.

Our game is simplified in two ways:

1. We only compare categories to determine the winner, not the value of the hands. For example, in a real poker game the winner of hands with exactly one pair would be determined by which pair had the highest card rank. That is, a pair of 10s wins over a pair of 3s. In our game, two hands with exactly one pair is considered a tie 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 only comparing categories not values. In particular, the cards 10h, Jh, Qh, Kh, Ah are not considered to make a straight in our game (they would under normal poker rules).

Assignment Specifications

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

2. Your program will be subdivided into meaningful functions. Use a function for each category (except that "high-card" doesn't need a function). See hints below.

3. Your program will display each player's dealt cards, the community cards, and announce the winner of the hand. Also, your program will display the winning combination (or either of the winning combinations, if a tie) as well as the category of the winning hand (see sample output below). For example, if the winning combination is "four-of-a-kind", those four cards will be displayed; the fifth card in the hand will not be displayed. The display will be appropriately labeled and formatted.

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

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

Hints

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

2. Finding a winner is simple: start with the highest category and 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 hands because you are only trying to find the highest category that a hand fits.)

3. Think strategically for testing. Custom build a set of hands for 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 to create each card first, e.g. c1 = cards.Card(5,1) to create the 5c card in H1. It took many lines to create the testing hands, but once built they proved useful.) Test each category function separately using the custom hands you created for testing. For example, result = full_house(H1) should yield a result [5c, 5h, 5d, 2c, 2h].

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

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

Attachment:- Programming Project.zip

Reference no: EM131099654

Questions Cloud

Case study eli lilly developing cymbalta : MARKETING MANAGEMENT AND INNOVATIONS, CASE STUDY Eli Lilly Developing Cymbalta,  Identification of the strategic issues and problems. This section contains a focused paragraph defining the problem. A problem well defined is half solved,
Poses interest rate risk for the borrower : "Explain how a two-year bill facility that uses 90-day bills poses interest rate risk for the borrower. Describe FRAs, BAB futures and interest rate swaps and explain how they can be used to hedge the interest rate risk involved in a planned issue..
Implications of our business on the problem space : Implications of our business on the problem space- how our solution is effective CINDY. We have come up with solution for one of the well-needed creative industries in Sydney - ARCHITECTURE. Yes, we see countless construction of building project al..
Lack coverage for the us balance of payments : One of the questions I must address for one of my assignments is, "Why does the media lack coverage for the US balance of payments (BOP). I researched the subject for hours but came to no concrete conclusion.
Design and implement a python program which plays poker : The goal of this project is to gain practice with use of classes and creating functions. You will design and implement a Python program which plays simplified Texas Hold'em Poker.
Cost of the balance remaining on the loan : A Xerox DocuColor photocopier costing 44000 is paid off in 60 monthly installments at 7.3% APR. After three years the company wishes to sell photocopier. What is the minimum price for which they can sell the copier so they can cover the cost of th..
Accurately describes organizational life : Do you read Dilbert? Do you think it accurately describes organizational life? Are there other comic strips that reflect life and work in contemporary organizations?
How you really a child pornographer and your widget business : Six months later you are off and running, unfortunately, a defective widget was sent to a California individual who now has brought a lawsuit against you and has also started an online blog about how you are really a child pornographer and your wi..
Ideal store layout for increasing store sales : Kroger, a grocery store chain, wants to identify the ideal store layout for increasing store sales. Because it primarily uses two store designs, one a grid layout with vertical aisles divided by a center aisle and another using a traditional strai..

Reviews

Write a Review

Python Programming Questions & Answers

  The program should use a boolean= valued function

Write a program that accepts a word as input and determines wehther or not it has three consecutive letters in the alphabet. The program should use a Boolean= valued function named isTripleConsecutive that accepts an entire word as input.

  Implements authentication using needham-schroeder protocol

Write a small project which implements authentication using Needham-Schroeder protocol. Alice connects to Bob using a trusted third party.

  A stack data structure that uses a linked list for storing

In Python, implement a stack data structure that uses a linked list for storing its elements. In particular, you will need to implement the following three functions: 1. top(): This function returns the element that is at the top of the stack, but it..

  Same directory as your program

In the same directory as your program, create a file FF1, and write into it Hello (with a space at teh end). Similarly, create a file FF2, and write into it world! (with a new line, i.e., an ENTER at the end). And create a file DD and write into i..

  Write a program that will open a blastn

Write a program that will open a BLASTN (nucleotide to nucleotide search) output file, parse out specific information, and produce formatted output that will be written to STDOUT

  Write a program using the ''requetinteger''

using python/jython programming write a program using the 'requetInteger' function that will ask the user to type a value that will draw a line from one point on a picture to another. I don't need specific help just a gerneral idea.

  How do you prevent replay attacks

What was your choice of cipher? What mode of operation does it use? Why did you make these choices? How do you prevent attackers from tampering with messages in transit? How do you prevent replay attacks

  Create functions to simplify your code

Create functions to simplify your code. If you find yourself writing the same code over and over again, it should probably be made into a function.

  Write an expression whose value is the concatenation

Write an expression whose value is the concatenation of the three str values associated with name1, name2, and name3, separated by commas. So if name1, name2, and name3, were (respectively) "Neville", "Dean", and "Seamus", your expression's value wou..

  Write a python program that performs simple encryption

You are required to write a Python program that performs simple encryption and decryption on strings entered by the user. To do so, you are to use one of the simplest and most widely known encryption techniques known as the Caesar Cipher

  Python programming to solve this problem

Write a statement that adds 1 to deansList and prints studentName to standard out if gpa exceeds 3.5.

  Calculate the accuracy of your linear classifier

Plot X,Y and the decision boundary. Make sure that you use a good plotting technique so that it is easy to distinguish which datapoint is X and which is Y. Calculate the accuracy of your linear classifier.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd