def test_getCard(self): """Getting the next card should produces cards in sequencial index order""" deck = Deck(5) deck.shuffle() a = [] for i in range(len(deck._Deck__deck)): card = deck.getCard() a.append(card) for i in range(len(deck._Deck__deck)): assert(a[i] == deck._Deck__deck[i])
class deck_shuffleTest(unittest.TestCase): def setUp(self): """Call before every test case.""" self.deck = Deck() def testAddCard(self): assert self.deck.shuffle() == dummy(self), 'Deck.shuffle() does not provide the right return value'
def test_createDeckShuffled(self): """Cards in a shuffled deck should be in a different order than it was previously """ a1 = [] a2 = [] deck = Deck(5) for card in deck._Deck__deck: a1.append(card) deck.shuffle() for card in deck._Deck__deck: a2.append(card) different = False for i in range(len(a1)): if a1[i] != a2[i]: different = True assert(different == True)
class deck_dealCardTest(unittest.TestCase): def setUp(self): """Call before every test case.""" self.deck = Deck() def testDealCard(self): test_card = self.deck.cards[len(self.deck.cards)-1] assert self.deck.deal_card() == test_card, 'Deck.deal_card() does not provide the right return value'
def test_compareShuffledDecks(self): """The same Deck shuffled at different times should have different ordering """ a1 = [] a2 = [] deck = Deck(5) deck2 = copy.deepcopy(deck) deck.shuffle() deck2.shuffle() for card in deck._Deck__deck: a1.append(card) for card in deck2._Deck__deck: a2.append(card) different = False for i in range(len(a1)): if a1[i] != a2[i]: different = True
class TestDeck(unittest.TestCase): def setUp(self): self.deck = Deck(shuffle_func) def test_cards(self): self.assertEqual(52, len(self.deck.cards)) def test_shuffle(self): cards_before = list(self.deck.cards) self.deck.shuffle() cards_after = list(self.deck.cards) self.assertNotEqual(cards_before, cards_after) def test_deal(self): expected = self.deck.cards[0] card = self.deck.deal() self.assertEqual(expected, card) def test_deal_card_gone(self): card = self.deck.deal() self.assertEqual(51, len(self.deck.cards))
def test_getCardEnd(self): """Getting the next card should return None if no more cards are left""" deck = Deck(3) a = [] for i in range(len(deck._Deck__deck)): card = deck.getCard() a.append(card) last_card = deck.getCard() last_card2 = deck.getCard() last_card3 = deck.getCard() last_card4 = deck.getCard() assert(last_card is None and last_card2 is None and last_card3 is None and last_card4 is None) assert(deck.getCardIndex() == len(deck._Deck__deck)) assert(deck.getCardIndex() == deck.getTotalCards())
def test_deck_draw(self): """A test which checks the draw method of the deck class.""" deck = Deck(1) self.assertEqual(len(deck), 52, msg="Incorrect number of inital cards in deck.") card = deck.draw() self.assertEqual(len(deck), 51, msg="Incorrect number of cards in deck after draw.") # Make sure that the card object drawn is actually a card self.assertTrue(isinstance(card, Card), msg="The card returned by the draw method of " + \ "Deck is not a Card object.") # Make sure that all cards can be drawn deck = Deck(1) for x in range(52): deck.draw() self.assertEqual(len(deck), 0) # Make sure that an error is raised when the deck is empty success = False try: deck.draw() except InvalidDeckDraw: success = True self.assertTrue(success, msg="Deck does not raise error when drawing from an empty deck.")
def test_play_set2(): player = Player( bankroll=100, hard_policy=hard_policy, soft_policy=soft_policy, split_policy=split_policy, betting_policy=betting_policy, ) deck = Deck(99) hands_1 = [Cards.TEN, Cards.FIVE, Cards.SEVEN, Cards.ACE, Cards.TEN, Cards.TWO] # test stand with dupl;icate hands hands_1 = [Cards.NINE, Cards.NINE, Cards.TEN, Cards.SEVEN] hands_2 = [Cards.NINE, Cards.NINE, Cards.NINE, Cards.ACE] hands_3 = [Cards.NINE, Cards.NINE, Cards.TEN, Cards.QUEEN] # test hits with duplicate hands hands_4 = [Cards.TEN, Cards.SEVEN, Cards.TWO, Cards.TWO, Cards.TEN, Cards.QUEEN] hands_5 = [Cards.TEN, Cards.FOUR, Cards.FOUR, Cards.TEN, Cards.QUEEN] # test surredern with 8,8 hands_6 = [Cards.EIGHT, Cards.EIGHT, Cards.NINE, Cards.ACE] # test softs hits into soft 16-18 but does not double hands_7 = [ Cards.SEVEN, Cards.FIVE, Cards.TWO, Cards.ACE, Cards.NINE, Cards.TWO, ] # becomes, soft 18, stands since you can't double with 3 cards, push hands_8 = [ Cards.EIGHT, Cards.SIX, Cards.FOUR, Cards.TWO, Cards.ACE, Cards.NINE, Cards.THREE, ] # becomes, hard 13, stands and loses hands_9 = [ Cards.NINE, Cards.NINE, Cards.FIVE, Cards.FOUR, Cards.TWO, Cards.ACE, Cards.NINE, Cards.THREE, ] # becomes, hard 12 hits, makes 21 push # test bunch of weird surredner hit surredner stand,... etc rules hands_10 = [ Cards.TEN, Cards.EIGHT, Cards.FOUR, Cards.FOUR, Cards.NINE, Cards.ACE, ] # does not split 44, hits into 16, but doesn't surrender, busts. hands_11 = [Cards.TEN, Cards.SEVEN, Cards.NINE, Cards.ACE] # surrender 17 hands_12 = [ Cards.TEN, Cards.SEVEN, Cards.TEN, Cards.ACE, ] # dealer BJ can't surrender hands_13 = [ Cards.FIVE, Cards.TEN, Cards.TWO, Cards.NINE, Cards.ACE, ] # hits into surrender can't surrender, stands deck.set_cards( deck.get_cards() + hands_13 + hands_12 + hands_11 + hands_10 + hands_9 + hands_8 + hands_7 + hands_6 + hands_5 + hands_4 + hands_3 + hands_2 + hands_1 ) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 + (1) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 101 - 1 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 - 1 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 99 + 1 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 - 1 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 99 - 0.5 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 98.5 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 98.5 - 1 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 97.5 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 97.5 - 1 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 96.5 - 0.5 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 96 - 1 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 95 - 1 print("yo?")
def test_play(): player = Player( bankroll=100, hard_policy=hard_policy, soft_policy=soft_policy, split_policy=split_policy, betting_policy=betting_policy, ) deck = Deck(99) # blackjacks hands_1 = [ Cards.ACE, Cards.JACK, Cards.TWO, Cards.FOUR, ] # player black jack dealer no blackjack hands_2 = [ Cards.ACE, Cards.JACK, Cards.ACE, Cards.JACK, ] # player black jack dealer blackjack hands_3 = [ Cards.FOUR, Cards.TWO, Cards.ACE, Cards.JACK, ] # player no black jack dealer blackjack # hits hands_4 = [ Cards.TEN, Cards.EIGHT, Cards.TWO, Cards.TEN, Cards.TEN, ] # Dealer shows T, has another T, Player hits with 10 to get to 20, push hands_5 = [ Cards.TEN, Cards.TEN, Cards.EIGHT, Cards.TWO, Cards.TWO, Cards.TEN, ] # Dealer shows T, has a Two, Player hits with 10 to get to 20, dealer busts to 22 hands_6 = [ Cards.SEVEN, Cards.EIGHT, Cards.TWO, Cards.TEN, Cards.TEN, ] # Dealer shows T, has a another T, Player hits with 10 to get to 17, stands and lose hands_7 = [Cards.SEVEN, Cards.EIGHT, Cards.TEN, Cards.TEN] # Surrender 15 hands_8 = [ Cards.TEN, Cards.THREE, Cards.TEN, Cards.TWO, Cards.JACK, Cards.TWO, ] # Dealer Shows two, player has 12, player hits and stands at 15, dealer hits and busts at 22 hands_9 = [ Cards.FIVE, Cards.THREE, Cards.TEN, Cards.TWO, Cards.JACK, Cards.TWO, ] # Dealer Shows two, player has 12, player hits and stands at 15, dealer hits and wins busts at 17 # player stands hands_10 = [ Cards.FIVE, Cards.THREE, Cards.TEN, Cards.THREE, Cards.JACK, Cards.TWO, ] # Dealer Shows two, player has 13 and stands, dealer wins with 20 hands_11 = [ Cards.TEN, Cards.SEVEN, Cards.JACK, Cards.JACK, ] # Player has 17 stands and loses hands_12 = [ Cards.TEN, Cards.TEN, Cards.JACK, Cards.NINE, ] # Player has 20 stands and wins # regular surredners hands_13 = [ Cards.FIVE, Cards.TEN, Cards.JACK, Cards.TEN, ] # Player has 15 surrenders to 10 and loses hands_14 = [ Cards.FIVE, Cards.TEN, Cards.NINE, Cards.ACE, ] # Player has 15 surrenders to 11 and loses hands_15 = [ Cards.SIX, Cards.TEN, Cards.JACK, Cards.NINE, ] # Player has 16 surrenders to 9 and loses hands_16 = [ Cards.SIX, Cards.TEN, Cards.JACK, Cards.KING, ] # Player has 16 surrenders to 10 and loses hands_17 = [ Cards.SIX, Cards.TEN, Cards.SEVEN, Cards.ACE, ] # Player has 16 surrenders to A and loses hands_18 = [ Cards.SEVEN, Cards.TEN, Cards.SEVEN, Cards.ACE, ] # Player has 17 surrenders to A and loses hands_19 = [ Cards.FIVE, Cards.TEN, Cards.JACK, Cards.ACE, ] # Player has opportunity to surrender but blackjack overrules and dealer wins # regular splits, max 4 hands_20 = [ Cards.SEVEN, Cards.TEN, Cards.JACK, Cards.TEN, Cards.EIGHT, Cards.SEVEN, Cards.ACE, Cards.EIGHT, Cards.TWO, Cards.TWO, Cards.TWO, Cards.TWO, Cards.TEN, Cards.SEVEN, ] # split twos 4 times. DOuble the first, Win with 21, Second to 9 does not double. Hits to 17 to push, Third bust at 22, Fourth stays at 19 to win. hands_21 = [ Cards.TEN, Cards.TEN, Cards.FIVE, Cards.ACE, Cards.ACE, Cards.SEVEN, Cards.FOUR, Cards.FOUR, Cards.FOUR, Cards.TWO, Cards.SIX, ] # Split 4 three times, doubles to 12 to lose, Doubles to 20 to win, Stays at 14 to lose hands_22 = [ Cards.EIGHT, Cards.THREE, Cards.TWO, Cards.TEN, Cards.ACE, Cards.ACE, Cards.ACE, Cards.ACE, Cards.NINE, Cards.ACE, ] # Split Aces 4 times, Win first, lose all three others # soft hands hands_23 = [ Cards.SIX, Cards.THREE, Cards.TWO, Cards.ACE, Cards.TEN, Cards.SIX, ] # Doubles Ace and wins to a dealer bust hands_24 = [ Cards.FIVE, Cards.TEN, Cards.TWO, Cards.ACE, Cards.TEN, Cards.SIX, ] # Doubles Ace to 13 and and loses to dealer 21 hands_25 = [ Cards.ACE, Cards.SEVEN, Cards.ACE, Cards.SEVEN, Cards.TEN, ] # Hits soft 18 vs ten and wins with 18 to 17 hands_26 = [ Cards.ACE, Cards.SEVEN, Cards.ACE, Cards.TEN, Cards.TEN, ] # Hits soft 18 vs ten and loses with 18 to 20 hands_27 = [ Cards.FOUR, Cards.SIX, Cards.ACE, Cards.TEN, Cards.TEN, ] # Hits soft 17 and stays at 21 and wins hands_28 = [ Cards.NINE, Cards.NINE, Cards.SIX, Cards.ACE, Cards.TEN, Cards.TEN, ] # Hits soft 17 and busts hands_29 = [ Cards.SEVEN, Cards.THREE, Cards.FOUR, Cards.TWO, Cards.ACE, Cards.TEN, Cards.THREE, ] # Hits soft 13, gets to soft 17 vs 3, can't double and push at 20 hands_30 = [ Cards.TEN, Cards.FIVE, Cards.SEVEN, Cards.ACE, Cards.TEN, Cards.TWO, ] # Doubles 18 vs 2 wins to bust # hits many cards into doubles, doesn't double and wins deck.set_cards( deck.get_cards() + hands_30 + hands_29 + hands_28 + hands_27 + hands_26 + hands_25 + hands_24 + hands_23 + hands_22 + hands_21 + hands_20 + hands_19 + hands_18 + hands_17 + hands_16 + hands_15 + hands_14 + hands_13 + hands_12 + hands_11 + hands_10 + hands_9 + hands_8 + hands_7 + hands_6 + hands_5 + hands_4 + hands_3 + hands_2 + hands_1 ) # test blackjacks plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 + (1 * 1.5) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 + (1 * 1.5) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 + (0.5) # test regular hits plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 + (0.5) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 + (1 * 1.5) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 + (1 * 0.5) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 + (1) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 100 # test regular stands plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 99 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 98 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 99 # test regular surrenders plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 98.5 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 98 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 97.5 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 97 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 96.5 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 96 plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == 95 # test regular splits plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == (95 + 2 + 0 - 1 + 1) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == (97 - 2 + 2 - 1) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == (96 + 1 - 3) # test soft hands plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == (94 + 2) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == (96 - 2) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == (94 + 1) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == (95 - 1) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == (94 + 1) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == (95 - 1) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == (94) plays = play(player, deck=deck, wager=1) player.next_round() assert player.get_bankroll() == (94 + 2)
def test_player_final_hands(): # lots of splits, doesn't split more than 4 deck = Deck() player = Player( bankroll=np.inf, hard_policy=hard_policy, soft_policy=soft_policy, split_policy=split_policy, betting_policy=betting_policy, ) player.increment_num_hands() deck.set_cards( [ Cards.TEN, Cards.QUEEN, Cards.KING, Cards.NINE, Cards.EIGHT, Cards.ACE, Cards.TEN, Cards.FOUR, Cards.EIGHT, Cards.NINE, Cards.TWO, Cards.TWO, Cards.TWO, Cards.TWO, Cards.TWO, Cards.TWO, Cards.TWO, ] ) output = resolve_player_action( Hand([Cards.TWO, Cards.TWO]), Cards.SEVEN, player, deck ) assert output == [ (PlayerResultTypes.LIVE, 21), (PlayerResultTypes.DOUBLE, 14), (PlayerResultTypes.LIVE, 21), (PlayerResultTypes.DOUBLE, 21), ] player.next_round() player.increment_num_hands() deck.set_cards( [ Cards.FIVE, Cards.FIVE, Cards.TWO, Cards.KING, Cards.ACE, Cards.ACE, Cards.ACE, Cards.ACE, ] ) output = resolve_player_action( Hand([Cards.ACE, Cards.ACE]), Cards.SEVEN, player, deck ) assert output == [ (PlayerResultTypes.LIVE, 12), (PlayerResultTypes.LIVE, 12), (PlayerResultTypes.LIVE, 21), (PlayerResultTypes.LIVE, 13), ] player.next_round() player.increment_num_hands() output = resolve_player_action( Hand([Cards.ACE, Cards.JACK]), Cards.SEVEN, player, deck ) assert output == [(PlayerResultTypes.BLACKJACK, 21)] player.next_round() player.increment_num_hands() deck.set_cards( [ Cards.FIVE, Cards.FIVE, Cards.TWO, Cards.KING, Cards.ACE, Cards.ACE, Cards.ACE, Cards.ACE, ] ) output = resolve_player_action( Hand([Cards.ACE, Cards.SIX]), Cards.SIX, player, deck ) assert output == [(PlayerResultTypes.DOUBLE, 18)] player.next_round() player.increment_num_hands() output = resolve_player_action( Hand([Cards.JACK, Cards.SIX]), Cards.ACE, player, deck ) assert output == [(PlayerResultTypes.SURRENDER, 16)] player.next_round() player.increment_num_hands() output = resolve_player_action( Hand([Cards.JACK, Cards.SEVEN]), Cards.ACE, player, deck ) assert output == [(PlayerResultTypes.SURRENDER, 17)] player.next_round() player.increment_num_hands() deck.set_cards([Cards.TEN, Cards.THREE]) output = resolve_player_action( Hand([Cards.ACE, Cards.TWO]), Cards.TWO, player, deck ) assert output == [(PlayerResultTypes.LIVE, 16)] player.next_round() player.increment_num_hands() deck.set_cards([Cards.SIX, Cards.TEN, Cards.THREE]) output = resolve_player_action( Hand([Cards.ACE, Cards.TWO]), Cards.SEVEN, player, deck ) assert output == [(PlayerResultTypes.BUST, 22)] player.next_round() player.increment_num_hands() deck.set_cards([Cards.THREE]) output = resolve_player_action( Hand([Cards.ACE, Cards.SEVEN]), Cards.TWO, player, deck ) assert output == [(PlayerResultTypes.DOUBLE, 21)] player.next_round() player.increment_num_hands() deck.set_cards([Cards.FIVE]) output = resolve_player_action( Hand([Cards.ACE, Cards.SEVEN]), Cards.TWO, player, deck ) assert output == [(PlayerResultTypes.DOUBLE, 13)] player.next_round() player.increment_num_hands() deck.set_cards([Cards.FIVE]) output = resolve_player_action( Hand([Cards.ACE, Cards.EIGHT]), Cards.TWO, player, deck ) assert output == [(PlayerResultTypes.LIVE, 19)] player.next_round() player.increment_num_hands() deck.set_cards([Cards.FIVE]) output = resolve_player_action( Hand([Cards.NINE, Cards.NINE]), Cards.SEVEN, player, deck ) assert output == [(PlayerResultTypes.LIVE, 18)] player.next_round() player.increment_num_hands() deck.set_cards([Cards.FIVE]) output = resolve_player_action( Hand([Cards.EIGHT, Cards.EIGHT]), Cards.ACE, player, deck ) assert output == [(PlayerResultTypes.SURRENDER, 16)] player.next_round() player.increment_num_hands() deck.set_cards([Cards.FIVE]) output = resolve_player_action( Hand([Cards.TEN, Cards.TEN]), Cards.ACE, player, deck ) assert output == [(PlayerResultTypes.LIVE, 20)]
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
def test_card_count(): 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, ]) for i in range(11): deck.deal() assert deck.get_count() == -11 cards = [ Cards.FOUR, Cards.FIVE, Cards.SIX, Cards.SEVEN, Cards.EIGHT, Cards.TEN, Cards.ACE, ] deck = Deck() deck.set_cards(cards) for i in range(len(cards)): deck.deal() assert deck.get_count() == 1
def test_setter_encapsulation(): deck = Deck() with pytest.raises(AssertionError): deck.set_cards_left("51")
def test_new_deck_has_right_cards_in_it(): deck = Deck() assert Card('Q', 'Hearts') in deck.cards assert Card('A', 'Spades') in deck.cards
def setUp(self): self.myTestDeck = Deck() self.myTestDeck.generate_deck_cards()
def setUp(self): self.deck = Deck(shuffle_func)
def __init__(self): self.deck = Deck() self.dealer = Player('Dealer', self.deck, []) self.player = Player('Player', self.deck, [])
def test_init_deck(): deck = Deck() assert len(deck.cards) == 52
def test_deal_hands(): deck = Deck() assert isinstance(deck.deal_card(), Card) card1, card2 = deck.deal_hand() assert isinstance(card1, Card) assert isinstance(card2, Card) assert card1 != card2 deck = Deck() deck.shuffle() card1, card2 = deck.deal_hand() assert card1 != card2 card1, card2 = deck.deal_card(), deck.deal_card() assert card1 != card2
def setUp(self): self.numbers = ["2", "3", "4", "5", "6", "7", "8", "9", "10"] self.letters = ["A", "Q", "J", "K"] self.suits = ["♣", "♦", "♥", "♠"] self.deck = Deck().deck
def test_deck_basic_functions(): deck = Deck() assert deck.get_cards_left() == 52 deck = Deck(2) assert deck.get_cards_left() == 52 * 2 deck = Deck(6) assert deck.get_cards_left() == 52 * 6 deck.deal() assert deck.get_cards_left() == 52 * 6 - 1
def test_len_deck(): deck = Deck() assert len(deck) == 52
def test_new_deck_has_52_cards(): deck = Deck() assert len(deck.cards) == 52
def setUp(self): """Call before every test case.""" self.deck = Deck()
def push(player, dealer): print("Dealer and player tie! PUSH!") ''' GAME LOOP ''' while True: print("WELLCOME TO BLACKJACK") #create and shuffle the deck, deal two cards to each player deck = Deck() deck.shuffle() player_hand = Hand() player_hand.add_card(deck.deal()) player_hand.add_card(deck.deal()) dealer_hand = Hand() dealer_hand.add_card(deck.deal()) dealer_hand.add_card(deck.deal()) # Set up plauer's chips player_chips = Chips() # prompt the player for their bet take_bet(player_chips)