blackjack21 package

Submodules

blackjack21.dealer module

class blackjack21.dealer.Dealer(name: str, table)[source]

Bases: object

Dealer class

Parameters:

name – str

property bust: bool

Dealer’s bust status

property hand: List[Card]

List of Card class objects in the dealer’s hand

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: object

Card 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: object

Deck 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:
property cards: List[Card]

List of Card class objects currently in the deck

draw_card() Card[source]

Draw a card from the deck

Returns:

Card object

property drawn_cards: List[Card]

List of Card class objects drawn from the deck

shuffle()[source]

Shuffle the cards in the deck

blackjack21.exceptions module

exception blackjack21.exceptions.InvalidPlayersData[source]

Bases: BlackjackException

Raised when the input player data is invalid

exception blackjack21.exceptions.InvalidRanks(ranks: tuple)[source]

Bases: BlackjackException

Raised when length of ranks tuple is not 13

exception blackjack21.exceptions.InvalidSuits(suits: tuple)[source]

Bases: BlackjackException

Raised when length of suits tuple is not 4

exception blackjack21.exceptions.PlayDealerFailure(name: str)[source]

Bases: BlackjackException

exception blackjack21.exceptions.PlayFailure(name: str, action: str)[source]

Bases: BlackjackException

Raised when player tries to play double down/split when they are not eligible

blackjack21.players module

class blackjack21.players.Player(name: str, bet: int, table)[source]

Bases: PlayerBase

Player 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: object

Base/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 hand: List[Card]

List of Card class objects in the player’s hand

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: object

Create 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

property dealer: Dealer

Table’s Dealer class object

property deck: Deck

Table’s Deck class object

property players: Tuple[Player]

List of Player class objects for the Table

Module contents

blackjack21 v3.0.1