Skip to content

Classes

Rahul Nanwani edited this page Oct 5, 2022 · 10 revisions

Table

Table(players, **kwargs)

Parameters:

  • players: A tuple of player tuples, where a player tuple is as (name: str, bet: int) (Min. 1 player, Max. 5 players)

Keyword Arguments:

  • dealer_name: Name of the dealer as a string (Default: "Dealer")
  • auto_deal: Change this to False only if you want to create your own dealing method (default: True)
  • suits: A tuple of 4 suits (Default: ("Hearts", "Diamonds", "Spades", "Clubs"))
  • ranks: A tuple of 13 ranks ace to king (Default: ("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"))

Attributes:

  • players: A tuple of Player objects
  • dealer: Dealer class
  • deck: A list of Card objects in the deck

PlayerBase

This object will be created from the method split() from the Player object.

Attributes:

  • name: Player name string
  • hand: A list of Card objects in the player's hand
  • total: Sum of the card values in the hand
  • bet: Bet placed by the player
  • bust: A bool if the player's hand total is more than 21
  • stand: A bool if the player has called for no further dealing of cards for the current round
  • result: Check the key for this below
-2: Player busts
-1: Player has less than the dealer
0: Player has the same total as the dealer and both are not bust
1: Player has 21 (aka. blackjack)
2: Player has greater total than the dealer
3: The dealer is bust
None: player or dealer has not finished playing their hand yet

Methods:

  • play_hit(): This will deal an extra card to the player, returns the Card objects for the card dealt
  • play_stand(): This will stop further dealing of any cards to the player for the current round, returns a bool

Player

A tuple of these objects will be created on creating the Table object.

Attributes:

  • name: Player name string
  • hand: A list of Card objects in the player's hand
  • total: Sum of the card values in the hand
  • bet: Bet placed by the player
  • bust: A bool if the player's hand total is more than 21
  • stand: A bool if the player has called for no further dealing of cards for the current round
  • can_double_down: a bool if the player can play double down
  • can_split: a bool if the player can play split
  • split: A PlayerBase object if method split() is used, else False
  • result: Check the key for this below
-2: Player busts
-1: Player has less than the dealer
0: Player has the same total as the dealer and both are not bust
1: Player has 21 (aka. blackjack)
2: Player has greater total than the dealer
3: The dealer is bust
None: player or dealer has not finished playing their hand yet

Methods:

  • play_hit(): This will deal an extra card to the player, returns the Card object for the card dealt
  • play_stand(): This will stop further dealing of any cards to the player for the current round, returns a bool
  • play_double_down(): Double the bet in exchange for just one hit, returns the Card object for the card dealt
  • play_split(): The pair will split into two hands, keeping the bet the same on both hands. If the player bets 100 initially, so after playing split the player will have placed 100 on the first hand, and 100 more on the second hand. Returns the PlayerBase object

Dealer

This object will be created by creating a Table object.

Attributes:

  • name: Dealer name string
  • hand: A list of Card objects in the dealer's hand
  • total: Sum of the card values in the hand
  • bust: A bool if the dealer has a total of more than 21
  • stand: A bool if the dealer has a total of more than 17

Methods:

  • play_dealer(): Use this method after all players have finished playing their hand, returns a bool

Card

A list of these objects will be created under the list deck attribute of the Table objects.

Attributes:

  • suit: Suit of the card as a string
  • rank: Rank of the card as a string