Use CherryPy add a web interface to a Python script
The Player Class
The player
class (lines 150-175) represents each player in the game. This includes money, bet amounts, cards, and flags for whether or not they are currently the dealer, have placed a bet, or have folded.
The init function initializes all of the player's variables:
self.name
– The player's nickname.self.cash
– The player's cash. Change this value to start the game with more or less cash.self.hand
– The player's private cards stored as tuples in a list.self.betAmount
– The amount the player has bet this hand.self.placedBet
– True, if the player has had the opportunity to bet (even if they didn't); false otherwise.self.fold
– True, if the player has folded; false otherwise.self.dealer
– True, if the player is currently the dealer; false otherwise.
Each of the class methods is a utility function to adjust a player's stats:
- The
credit
function increases the player's cash by the given amount. - The
debit
function decreases the player's cash by the given amount. - The
bet
function increases the player's bet by the given amount. - The
addCard
function adds the provided card to the player's hand. - The
reset
function clearshand
andbetAmount
and setsfold
toFalse
. The player is now ready for the next hand.
With these functions in place, I can turn my attention to game play.
The Table Class
The table
class (lines 177-386) represents the poker game itself. It tracks whose turn it is and who the dealer is, and it determines the hand winner. Much like the other init functions, the table's __init__
sets up the variables for the game itself:
self.players
is a dictionary of players. The key is the player's nickname.self.tableCards
is a list of cards currently visible on the table.self.state
is the current state of the card game."WAITING"
signifies that no hand is currently in progress.self.shoe
is an instance of thedeck()
class. After initializing the shoe, it is shuffled.self.pot
represents the money currently on the table.
Buy this article as PDF
Express-Checkout as PDF
Pages: 8
Price $2.95
(incl. VAT)
(incl. VAT)