Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ICS 33 Programming Assignment 2

Objectives:

1.   Getting familiar with how to use concepts from object-oriented programming in implementing a program.

2.  Getting familiar with how to deine and use classes in Python.

3.  Getting hands-on experience with designing an OOP-based Python program

Description:

In this project, you will extend and modify your code from Programming Assignment 1 to make it in OOP style. Besides determining who the winner(s) is/are, your code for this assignment should also implement additional functionalities to make it look more like a real game. Below is a brief description of how the game is played.

Game rule (The rule you will use for this assignment will be diferent and simpler than the real game rule.)

A game can have multiple players. Each player starts with $10. Once the game starts, each player will be randomly given 2 cards. Then 3 random cards (called community cards) will be drawn from the rest of the cards. With 2 cards in hand and 3 cards on the table (so the 3 cards can be used by all players), each player needs to decide whether he/ she has a good chance to continue. You can use the functions you wrote for PA 1 to decide the rank for each player. Set a threshold for the ranking. If a player’s rank is below the threshold (e.g., rank 7, meaning that the player will have at least two pairs to bet or otherwise will quit the game immediately), the player will fold (quitting the game). The rest of the players will bet. The amount they bet is up to your choice. You can implement the program so that when they bet, the amount is based on their current rank (e.g., the higher the rank is, the more they bet). Or you can simply set a ixed amount for betting. After players bet, 2 additional random community cards are drawn from the rest of the cards. Out of the 7 cards in total for each player (5 community cards and 2 cards at hand), you need to compute the highest rank possible with 5 cards (out of the 7 cards) for each player. Then based on which player wins, you subtract the amount of bets from those who loses, and add them to the winner. This concludes a game. One game can have at most two rounds: the irst round with 3 community cards and the second round with 5 community cards in total (2 additional on top of the 3 from the irst round). If there is a next game, the money left for each player will be carried over to the next game. Players who have $0 left should leave the game.

Program implementation

Your program for PA2 should be based on your code for PA1. You should use at least one class in this program.

Assumptions

Assume you are drawing cards from one deck of cards.

Tie situations

Your program is expected to handle simple tie situations. Because we are using only one deck of cards, when the program randomly draws cards, it is very rare for two players to have the same rank. You are expected to handle, e.g., when two players both have a pair, then you need to compare who has the largest pair value.

Input format

The  input will  take  two  integers:  n_player  (denoting  the  number  of players  at  the beginning of the game), and n_games (denoting the number of games).

Output format

For each round, you should print out each round’s players’ cards, community cards, amount of betting, and ranking. At the end of each game, you should print out the inal winner and the money left for each player. Below is an example output (with n_player = 3 and n_games = 2). The example is only for illustration purpose, and your output does not have to be in the exact same format.

——————Initialization Game 1 ————————

Player 1: C2, S3

Player 2: S4, S9

Player3: S10, H3

Community Cards: C4, C8, H7

——————Round 1 ————————

Player 1: rank 9, bet $1

Player 2: rank 8, bet $2

Player 3: rank 9, bet $1

——————Round 2 ————————

Player 1: C2, S3

Player 2: S4, S9

Player3: S10, H3

Community Cards: C4, C8, H7, H10, H9

Player 1: rank 9, bet $1

Player 2: rank7, bet $2

Player3: rank 8, bet $1

—————Results————————

Winner: Player 2

Player 1: $8

Player 2: $14

Player3: $8

—————End ofGame 1 ————————


——————Initialization Game 2 ————————

Player 1: C5, S2

Player 2: H10, D11

Player3: S3, H2

Community Cards: C7, C9, H4

——————Round 1 ————————

Player 1: rank 9, bet $1

Player 2: rank 9, bet $1

Player 3: rank 9, bet $1

——————Round 2 ————————

Player 1: C5, S2

Player 2: H10, D11

Player3: S3, H2

Community Cards: C7, C9, H4, H5, D3*

Player 1: rank 8, bet $2

Player 2: rank 9, bet $1

Player3: rank 8, bet $1

—————Results————————

Winner: Player 2

Player 1: $12

Player 2: $12

Player3: $6

—————End ofGame 2 ————————

*Note: Though Player 1 and Player 3 have the same rank, the pair value for Player 1 (5) is greater than the pair value for Player 3 (3).

Submission

Python programs (Name should be: PA2_FirstName_LastName.py) should be submitted to Canvas by 7/17/2022, 11:59pm. You can submit as many times as you want before the deadline.  No  late  submissions  will  be  accepted  unless  you  communicate  with  the instructor  ahead  of  time.  If  you  have  special  circumstances  that  need  to  be accommodated, please contact the instructor and TA immediately.                                   Request for extension

Request for extension should be communicated directly with the instructor and no later than 48 hours before the due date. Request for extension sent on weekends will not be responded or approved.

Grading

The assignment will be worth 100 points, with the following breakdowns:

50 pt: We test with diferent combinations of n_player and n_game and your program print-out is correct for all of them. *

30 pt: Your program uses at least one class to properly represent elements of the game (e.g., player, card, deck of cards, etc.)

10  pt:  Your  program  has  good  coding  styles,  e.g.,  variable  and  function  naming, comments, code reuse, etc. Excessive copying and pasting code segments throughout your program will lose points.

10 pt:  Your program has some error handling mechanisms to take care of inputs such as n_player = 0 and n_game = 0.                                                                                               *Note: For large n_game, your program may print a long list on terminal. You can use the following command to write the print-out on the terminal to a ile so that you can store the results of your program                                                                                                  python script_name.py > output.txt

Plagiarism

There are Texas Hold’em programs implemented in Python online. However, in this programming assignment, we have speciic requirements such as the data types you can use. You can refer to the ideas of how those programs were written, but you should not directly duplicate their codes. Put references to those resources in your submission. Discussion with your classmates is encouraged, but you should not directly duplicate their codes. If direct duplication of codes is found, you will receive no points in this assignments.

More notes about the assignment

1.   If you have any questions, please approach the TA and the instructor as soon as possible. Do not delay to the very last minute.

2.   The next two programming assignments and the project will be based on the irst one. So it would be the best if your programs have the lexibility to be extended, though this is not part of the grading.

References

[1] https://en.wikipedia.org/wiki/Texas_hold_%27em

*Table is adapted based on the Wikipedia source.