blackjack21 package
Submodules
blackjack21.dealer module
- class blackjack21.dealer.Dealer(name: str, table)[source]
Bases:
objectDealer class
- Parameters:
name – str
- property bust: bool
Dealer’s bust status
- property name: str
Dealer’s name
- play_dealer()[source]
Play the dealer once everyone has played their hands
- Returns:
True if hand is successfully played, else False
- property stand: bool
Dealer’s stand status
- property total: int
Dealer’s hand total
blackjack21.deck module
- class blackjack21.deck.Card(suit: str, rank: str, value: int)[source]
Bases:
objectCard class
- Parameters:
suit – suit of the card
rank – rank of the card
value – value of the card in the game
- property rank: str
Card rank
- property suit: str
Card suit
- property value: int
Card value
- class blackjack21.deck.Deck(suits: tuple, ranks: tuple, **kwargs)[source]
Bases:
objectDeck of cards class (Iterable)
- Parameters:
suits – tuple of 4 suits
ranks – tuple of 13 card ranks
count – int number of decks to be merged
- Raises:
InvalidSuits – if length of suits is not 4
InvalidRanks – if length of ranks is not 13
blackjack21.exceptions module
- exception blackjack21.exceptions.InvalidPlayersData[source]
Bases:
BlackjackExceptionRaised when the input player data is invalid
- exception blackjack21.exceptions.InvalidRanks(ranks: tuple)[source]
Bases:
BlackjackExceptionRaised when length of ranks tuple is not 13
blackjack21.players module
- class blackjack21.players.Player(name: str, bet: int, table)[source]
Bases:
PlayerBasePlayer class (Inherited from PlayerBase class)
- Parameters:
name – str
bet – int
table – Table class object
- property bet: int
Player’s bet amount
- property can_double_down: bool
bool if the player is eligible to play double down
- property can_split: bool
bool if the player is eligible to play split
- play_double_down() Card[source]
Double down can be played only on the first turn by doubling the bet amount and will hit only once
- Returns:
Card class object
- Raises:
PlayFailure – if player is not eligible to play this
- play_split() PlayerBase[source]
Split can be played only on the first turn by splitting the hand if both the cards have the same ranks. The bet will remain the same on both the hands. If the player bets 100 initially, so after playing split the player will have placed 100 on first hand, and 100 more on the second hand.
- Returns:
Player class object
- Raises:
PlayFailure – if player is not eligible to play this
- property split: PlayerBase | None
PlayerBase class object if split is played else none
- class blackjack21.players.PlayerBase(name: str, bet: int, table)[source]
Bases:
objectBase/Split player class
- Parameters:
name – str
bet – int
table – Table class object
- property bet: int
Player’s bet amount
- property bust: bool
Player’s bust status
- property name: str
Player name
- play_hit() Card[source]
Deals another card to the player if the player is not busted or has played stand
- Returns:
Card class object
- play_stand() bool[source]
Stop further dealing any cards to the player before being busted.
- Returns:
bool
- property result: int | None
Player result
Negative implies the player loses, positive implies the player wins, and 0 implies a draw. The key below shows the reasons for the result:
- key -2:
Player busts
- key -1:
Player has less than the dealer
- key 0:
Player has the same total as the dealer and both are not bust
- key 1:
Player has 21 (aka. blackjack)
- key 2:
Player has greater than the dealer
- key 3:
The dealer is bust
- key None:
Dealer has not finished playing yet
- property stand: bool
Player’s stand status
- property total: int
Player’s hand total
blackjack21.table module
- class blackjack21.table.Table(players: Iterable, **kwargs)[source]
Bases:
objectCreate object for this class to initialize a blackjack table
- Parameters:
players – tuple of player tuples ((name: str, bet: int), )
dealer – str: dealer name (default: “Dealer”)
auto_deal – bool (default: True)
suits – tuple of 4 suits (default: (“Hearts”, “Diamonds”, “Spades”, “Clubs”))
ranks – tuple of 13 ranks ace to king (default: (“A”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “J”, “Q”, “K”))
deck_count – int number of decks to be used
- property auto_deal: bool
Table auto deal bool value
Module contents
blackjack21 v3.0.1