Пример #1
0
def test_overall_play():

    wager_amts = [1, 1, 1, 1, 1, 1, 4, 8, 16]
    ranges = [-3, -2, -1, 0, 0, 1, 2, 3]
    betting_policy = (wager_amts, ranges)

    player = Player(
        bankroll=100,
        hard_policy=hard_policy,
        soft_policy=soft_policy,
        split_policy=split_policy,
        betting_policy=betting_policy,
    )
    deck = Deck()
    # first hand player wins and wins 1 count is now 4
    cards_1 = [
        Cards.TEN,
        Cards.THREE,
        Cards.TEN,
        Cards.FOUR,
        Cards.THREE,
        Cards.FOUR,
        Cards.TWO,
        Cards.FOUR,
    ]
    cards_2 = [
        Cards.TEN,
        Cards.THREE,
        Cards.TEN,
        Cards.FOUR,
        Cards.JACK,
        Cards.ACE,
        Cards.TEN,
        Cards.TEN,
    ]
    # second hand player wagers 16 and wins 16*1.5 = 24
    deck.set_cards(cards_2 + cards_1)

    resolve_environment(player, deck, 8, 1, 0.001)
    assert player.get_bankroll() == 101
    assert deck.get_count() == 4
    assert player.calculate_wager(deck.get_true_count()) == 16
    resolve_environment(player, deck, 8, 1, 0.001)
    assert player.get_bankroll() == 125
Пример #2
0
def test_true_count_and_wager():
    wager_amts = [1, 1, 1, 1, 1, 1, 4, 8, 16]
    ranges = [-3, -2, -1, 0, 0, 1, 2, 3]
    betting_policy = (wager_amts, ranges)
    player = Player(
        bankroll=100,
        hard_policy=hard_policy,
        soft_policy=soft_policy,
        split_policy=split_policy,
        betting_policy=betting_policy,
    )
    deck = Deck()
    deck.set_cards([
        Cards.TEN,
        Cards.QUEEN,
        Cards.KING,
        Cards.TEN,
        Cards.KING,
        Cards.ACE,
        Cards.TEN,
        Cards.QUEEN,
        Cards.QUEEN,
        Cards.JACK,
        Cards.TEN,
    ])
    assert deck.get_num_decks() == 1
    assert deck.get_cards_left() == 11

    for i in range(10):
        deck.deal()

    assert deck.get_true_count() == -10 / (1 / 52)
    assert player.calculate_wager(deck.get_true_count()) == 1

    deck = Deck()
    deck.set_cards(
        [Cards.FOUR, Cards.TWO, Cards.SEVEN, Cards.TEN, Cards.NINE, Cards.TWO])
    for i in range(5):
        deck.deal()
    assert deck.get_true_count() == 1 / (1 / 52)
    assert player.calculate_wager(deck.get_true_count()) == 16

    deck = Deck()
    deck.set_cards(
        [Cards.FOUR, Cards.TWO, Cards.SEVEN, Cards.TEN, Cards.NINE, Cards.TWO
         ] * 100)
    for i in range(6 * 50):
        deck.deal()
    assert deck.get_true_count() == (2 * 50) / ((600 - 6 * 50) / 52)
    assert player.calculate_wager(deck.get_true_count()) == 16

    deck = Deck()
    deck.set_cards([
        Cards.TWO,
        Cards.THREE,
        Cards.FOUR,
        Cards.FIVE,
        Cards.SIX,
        Cards.SEVEN,
        Cards.EIGHT,
        Cards.NINE,
        Cards.TEN,
        Cards.JACK,
        Cards.QUEEN,
        Cards.KING,
        Cards.ACE,
    ] * 100)
    for i in range(13 * 69):
        deck.deal()
    assert deck.get_true_count() == 0
    assert player.calculate_wager(deck.get_true_count()) == 1

    deck = Deck()
    deck.set_cards([Cards.FOUR, Cards.TWO, Cards.FOUR, Cards.FOUR] * 13)

    # +1
    deck.deal()
    assert deck.get_true_count() == 1 / (51 / 52)
    assert player.calculate_wager(deck.get_true_count()) == 4

    # +2
    deck.deal()
    assert deck.get_true_count() == 2 / (50 / 52)
    assert player.calculate_wager(deck.get_true_count()) == 8

    # +3
    deck.deal()
    assert deck.get_true_count() == 3 / (49 / 52)
    assert player.calculate_wager(deck.get_true_count()) == 16

    deck = Deck()
    deck.set_cards([Cards.QUEEN, Cards.JACK, Cards.ACE, Cards.TEN] * 13)
    wager_amts = [-16, -8, -4, -1, 0, 1, 4, 8, 16]
    ranges = [-3, -2, -1, 0, 0, 1, 2, 3]
    betting_policy_alt = (wager_amts, ranges)
    player = Player(
        bankroll=100,
        hard_policy=hard_policy,
        soft_policy=soft_policy,
        split_policy=split_policy,
        betting_policy=betting_policy_alt,
    )

    assert player.calculate_wager(deck.get_true_count()) == 0
    # +1
    deck.deal()
    assert deck.get_true_count() == -1 / (51 / 52)
    assert player.calculate_wager(deck.get_true_count()) == -4

    # +2
    deck.deal()
    assert deck.get_true_count() == -2 / (50 / 52)
    assert player.calculate_wager(deck.get_true_count()) == -8

    # +3
    deck.deal()
    assert deck.get_true_count() == -3 / (49 / 52)
    assert player.calculate_wager(deck.get_true_count()) == -16