Action Strategies

Base class to create your own movers

class action_strategies.BaseMover

Base mover. The parent class of all movers.

static get_move(hand_value, hand_has_ace, dealer_up_card, can_double, can_split, can_surrender, can_insure, hand_cards, cards_seen, deck_number, dealer_peeks_for_blackjack, das, dealer_stands_soft_17)

Raise NotImplementedError. To be overwritten in the other classes.

Parameters:
  • hand_value (int) – The value of the hand (e.g. 18).

  • hand_has_ace (bool) – Whether the hand has an ace that is counted as 11.

  • dealer_up_card (int) – The dealer’s up card.

  • can_double (bool) – Whether we can double.

  • can_split (bool) – Whether we can split.

  • can_surrender (bool) – Whether we can surrender.

  • can_insure (bool) – Whether we can take insurance.

  • hand_cards (list[int]) – The cards in our hand (e.g. 8, 7, 3).

  • cards_seen (list[int]) – The cards we have already seen from the shoe. Used when card counting.

  • deck_number (int) – The number of decks in the starting shoe.

  • dealer_peeks_for_blackjack (bool) – Whether the dealer peeks for blackjack.

  • das (bool) – Whether we can double after splitting.

  • dealer_stands_soft_17 (bool) – Whether the dealer stands on soft 17.

Returns:

The action to do, and whether to take insurance.

Return type:

tuple[str, bool]

Example custom mover:

class MyMover(BaseMover):
    @staticmethod
    def get_move(hand_value: int, hand_has_ace: bool, dealer_up_card: int, can_double: bool, can_split: bool,
                 can_surrender: bool, can_insure: bool, hand_cards: list[int], cards_seen: list[int], deck_number: int,
                 dealer_peeks_for_blackjack: bool, das: bool, dealer_stands_soft_17: bool) -> tuple[str, bool]:
        if hand_value < 17:
            return "d" if can_double and hand_value in [10, 11] else "h", False
        return "s", False

Pre-built movers

class action_strategies.SimpleMover

Simple mover. Moves like the dealer in a Stand 17 game.

static get_move(hand_value, hand_has_ace, dealer_up_card, can_double, can_split, can_surrender, can_insure, hand_cards, cards_seen, deck_number, dealer_peeks_for_blackjack, das, dealer_stands_soft_17)

Hit (value <= 16) or stand (value >= 17). Never take insurance.

Parameters:
  • hand_value (int) – The value of the hand (e.g. 18).

  • hand_has_ace (bool) – Whether the hand has an ace that is counted as 11.

  • dealer_up_card (int) – The dealer’s up card.

  • can_double (bool) – Whether we can double.

  • can_split (bool) – Whether we can split.

  • can_surrender (bool) – Whether we can surrender.

  • can_insure (bool) – Whether we can take insurance.

  • hand_cards (list[int]) – The cards in our hand (e.g. 8, 7, 3).

  • cards_seen (list[int]) – The cards we have already seen from the shoe. Used when card counting.

  • deck_number (int) – The number of decks in the starting shoe.

  • dealer_peeks_for_blackjack (bool) – Whether the dealer peeks for blackjack.

  • das (bool) – Whether we can double after splitting.

  • dealer_stands_soft_17 (bool) – Whether the dealer stands on soft 17.

Returns:

The action to do, and whether to take insurance.

Return type:

tuple[str, bool]

class action_strategies.BasicStrategyDeviationsMover(filename)

Move according to the basic strategy with the most common deviations.

Get the move to play for each hand-dealer combination.

Parameters:

filename (str) – The file where the basic strategy is stored.

get_move(hand_value, hand_has_ace, dealer_up_card, can_double, can_split, can_surrender, can_insure, hand_cards, cards_seen, deck_number, dealer_peeks_for_blackjack, das, dealer_stands_soft_17)

Get the move to play from basic strategy.

Parameters:
  • hand_value (int) – The value of the hand (e.g. 18).

  • hand_has_ace (bool) – Whether the hand has an ace that is counted as 11.

  • dealer_up_card (int) – The dealer’s up card.

  • can_double (bool) – Whether we can double.

  • can_split (bool) – Whether we can split.

  • can_surrender (bool) – Whether we can surrender.

  • can_insure (bool) – Whether we can take insurance.

  • hand_cards (list[int]) – The cards in our hand (e.g. 8, 7, 3).

  • cards_seen (list[int]) – The cards we have already seen from the shoe. Used when card counting.

  • deck_number (int) – The number of decks in the starting shoe.

  • dealer_peeks_for_blackjack (bool) – Whether the dealer peeks for blackjack.

  • das (bool) – Whether we can double after splitting.

  • dealer_stands_soft_17 (bool) – Whether the dealer stands on soft 17.

Returns:

The action to do, and whether to take insurance.

Return type:

tuple[str, bool]

read_file()

Read the file with the basic strategy with the most common deviations.

Return type:

None

class action_strategies.BasicStrategyMover(filename)

Move according to the basic strategy.

Get the move to play for each hand-dealer combination.

Parameters:

filename (str) – The file where the basic strategy is stored.

get_move(hand_value, hand_has_ace, dealer_up_card, can_double, can_split, can_surrender, can_insure, hand_cards, cards_seen, deck_number, dealer_peeks_for_blackjack, das, dealer_stands_soft_17)

Get the move to play from basic strategy.

Parameters:
  • hand_value (int) – The value of the hand (e.g. 18).

  • hand_has_ace (bool) – Whether the hand has an ace that is counted as 11.

  • dealer_up_card (int) – The dealer’s up card.

  • can_double (bool) – Whether we can double.

  • can_split (bool) – Whether we can split.

  • can_surrender (bool) – Whether we can surrender.

  • can_insure (bool) – Whether we can take insurance.

  • hand_cards (list[int]) – The cards in our hand (e.g. 8, 7, 3).

  • cards_seen (list[int]) – The cards we have already seen from the shoe. Used when card counting.

  • deck_number (int) – The number of decks in the starting shoe.

  • dealer_peeks_for_blackjack (bool) – Whether the dealer peeks for blackjack.

  • das (bool) – Whether we can double after splitting.

  • dealer_stands_soft_17 (bool) – Whether the dealer stands on soft 17.

Returns:

The action to do, and whether to take insurance.

Return type:

tuple[str, bool]

read_file()

Read the file with the basic strategy.

Return type:

None

class action_strategies.CardCountMover(filenames)

Move according to the basic strategy and the deviations using the card count.

Get the move to play for each hand-dealer combination.

The format of filenames is: Key: Minimum TC to play a strategy (inclusive), Maximum TC to play a strategy (exclusive). Value: The filename of the strategy to follow for a range of TCs (TC can be decimal).

Example: (-1000, 2.5): General Basic Strategy (2.5, 5): Basic Strategy TC +4 (5, 1000): Basic strategy TC +6

Parameters:

filenames (dict[tuple[float, float], str]) – The filenames where the basic strategy and deviations are stored, and when should each strategy be played.

get_move(hand_value, hand_has_ace, dealer_up_card, can_double, can_split, can_surrender, can_insure, hand_cards, cards_seen, deck_number, dealer_peeks_for_blackjack, das, dealer_stands_soft_17)

Get the move to play.

Parameters:
  • hand_value (int) – The value of the hand (e.g. 18).

  • hand_has_ace (bool) – Whether the hand has an ace that is counted as 11.

  • dealer_up_card (int) – The dealer’s up card.

  • can_double (bool) – Whether we can double.

  • can_split (bool) – Whether we can split.

  • can_surrender (bool) – Whether we can surrender.

  • can_insure (bool) – Whether we can take insurance.

  • hand_cards (list[int]) – The cards in our hand (e.g. 8, 7, 3).

  • cards_seen (list[int]) – The cards we have already seen from the shoe. Used when card counting.

  • deck_number (int) – The number of decks in the starting shoe.

  • dealer_peeks_for_blackjack (bool) – Whether the dealer peeks for blackjack.

  • das (bool) – Whether we can double after splitting.

  • dealer_stands_soft_17 (bool) – Whether the dealer stands on soft 17.

Returns:

The action to do, and whether to take insurance.

Return type:

tuple[str, bool]

read_files()

Read the files with the basic strategy and deviations.

Return type:

None

class action_strategies.PerfectMover

Get the best move to play using all available information.

static get_move(hand_value, hand_has_ace, dealer_up_card, can_double, can_split, can_surrender, can_insure, hand_cards, cards_seen, deck_number, dealer_peeks_for_blackjack, das, dealer_stands_soft_17)

Get the best move to play by taking into account every available information. Uses the best move analysis.

Very slow to be used in large EV calculations.

Parameters:
  • hand_value (int) – The value of the hand (e.g. 18).

  • hand_has_ace (bool) – Whether the hand has an ace that is counted as 11.

  • dealer_up_card (int) – The dealer’s up card.

  • can_double (bool) – Whether we can double.

  • can_split (bool) – Whether we can split.

  • can_surrender (bool) – Whether we can surrender.

  • can_insure (bool) – Whether we can take insurance.

  • hand_cards (list[int]) – The cards in our hand (e.g. 8, 7, 3).

  • cards_seen (list[int]) – The cards we have already seen from the shoe. Used when card counting.

  • deck_number (int) – The number of decks in the starting shoe.

  • dealer_peeks_for_blackjack (bool) – Whether the dealer peeks for blackjack.

  • das (bool) – Whether we can double after splitting.

  • dealer_stands_soft_17 (bool) – Whether the dealer stands on soft 17.

Returns:

The action to do, and whether to take insurance.

Return type:

tuple[str, bool]