def test_add_card_and_add_A(self): card_A = Card(Suit.SPADE, Rank.A) card = Card(Suit.SPADE, Rank.J) self.hand.add_card(card) self.hand.add_card(card_A) self.assertEqual(len(self.hand.hand_value), 2) self.assertEqual(self.hand.hand_value, [11, 21]) self.assertEqual(self.hand.status, HandStatus.BLACKJACK)
def test_card(self): self.view_card_helper(Card(Suit.SPADE, Rank.A), '♠ A') self.view_card_helper(Card(Suit.HEART, Rank.A), '♥️ A') self.view_card_helper(Card(Suit.CLUB, Rank.A), '♣ A') self.view_card_helper(Card(Suit.DIAMOND, Rank.A), '♦ A') self.view_card_helper(Card(Suit.SPADE, Rank.TWO), '♠ 2') self.view_card_helper(Card(Suit.SPADE, Rank.TEN), '♠ 10') self.view_card_helper(Card(Suit.SPADE, Rank.J), '♠ J') self.view_card_helper(Card(Suit.SPADE, Rank.Q), '♠ Q') self.view_card_helper(Card(Suit.SPADE, Rank.K), '♠ K')
def setUp(self): self.game_viewer = GameViewer() self.card_A = Card(Suit.SPADE, Rank.A) self.card_10 = Card(Suit.SPADE, Rank.TEN) self.hand_1, self.hand_2, self.hand_3, self.hand_4 = Hand(), Hand( ), Hand(), Hand() self.hand_1.add_card(self.card_A) self.hand_2.add_card(self.card_10), self.hand_2.add_card(self.card_A) self.hand_3.add_card(self.card_10), self.hand_3.add_card(self.card_10) self.hand_4.add_card(self.card_10), self.hand_4.add_card( self.card_10), self.hand_4.add_card(self.card_A) self.dealer = Dealer(16) self.dealer.hand = self.hand_3 self.players = [Player('test_1'), Player('testing_2')] self.players[0].hand = self.hand_1 self.players[1].hand = self.hand_2
def distribute_card_that_exist_with_specified_suit_and_rank(self): player = self.game.players[0] flag = self.game.distribute_card(player, Suit.SPADE, Rank.TWO) self.assertTrue(flag) self.assertEqual(len(player.hand.hand), 1) self.assertEqual(player.hand.hand[0], Card(Suit.SPADE, Rank.TWO)) self.assertEqual(len(self.game.card_deck.deck), self.num_card - 1)
def distribute_card_to_dealer(self): flag = self.game.distribute_card(self.game.dealer, Suit.SPADE, Rank.TWO) self.assertTrue(flag) self.assertEqual(len(self.game.dealer.hand.hand), 1) self.assertEqual(self.game.dealer.hand.hand[0], Card(Suit.SPADE, Rank.TWO)) self.assertEqual(len(self.game.card_deck.deck), self.num_card - 1)
def setUp(self): self.card_A = Card(Suit.SPADE, Rank.A) self.card_10 = Card(Suit.SPADE, Rank.TEN) self.player_me = Player('me', is_npc=False) self.player_npc = Player('npc') self.dealer = Dealer(16) self.player_me.add_card(self.card_10), self.player_me.add_card( self.card_10) self.player_npc.add_card(self.card_10), self.player_npc.add_card( self.card_10) self.dealer.add_card(self.card_10), self.dealer.add_card(self.card_10) self.game = Game(ConfigLoader()) self.game.init() self.game.players = [self.player_me, self.player_npc] self.game.dealer = self.dealer self.simulator = Simulator(ConfigLoader())
def setUp(self): self.hand = Hand() self.card_8 = Card(Suit.SPADE, Rank.EIGHT) self.card_9 = Card(Suit.SPADE, Rank.NINE) self.card_10 = Card(Suit.SPADE, Rank.TEN) self.card_J = Card(Suit.SPADE, Rank.J) self.card_A = Card(Suit.SPADE, Rank.A) self.card_A_2 = Card(Suit.SPADE, Rank.A)
def update_hand_value(self, card: Card) -> None: # handle special case of A if card.rank == Rank.A: if len(self.hand_value) == 0: self.hand_value.append(1) self.hand_value.append(11) elif len(self.hand_value) == 1: self.hand_value.append(self.hand_value[0] + 11) self.hand_value[0] += 1 elif len(self.hand_value) == 2: self.add_hand_value(1) else: card_value = card.get_value() self.add_hand_value(card_value) # handle bust for value in self.hand_value: if value > 21: self.hand_value.remove(value)
def setUp(self): self.dealer = Dealer(16) self.card_A = Card(Suit.SPADE, Rank.A) self.card_9 = Card(Suit.SPADE, Rank.NINE)
def init(self): self.deck = list() for _ in range(self.num_card_set): for suit in Suit: for rank in Rank: self.add_card(Card(suit, rank))
def setUp(self): self.player = Player('Test') self.card_A = Card(Suit.SPADE, Rank.A) self.card_9 = Card(Suit.SPADE, Rank.NINE)
def setUp(self): self.card_A = Card(Suit.SPADE, Rank.A) self.card_A_2 = Card(Suit.SPADE, Rank.A) self.card_different_suit = Card(Suit.DIAMOND, Rank.A) self.card_different_rank = Card(Suit.SPADE, Rank.TWO)
def test_conclude_player_status_hand_value(self): hand_16 = [Card(Suit.SPADE, Rank.TEN), Card(Suit.SPADE, Rank.SIX)] hand_17 = [Card(Suit.SPADE, Rank.TEN), Card(Suit.SPADE, Rank.SEVEN)] hand_21 = [ Card(Suit.SPADE, Rank.TEN), Card(Suit.SPADE, Rank.SEVEN), Card(Suit.SPADE, Rank.FOUR) ] hand_blackjack = [Card(Suit.SPADE, Rank.TEN), Card(Suit.SPADE, Rank.A)] hand_fivecard = [ Card(Suit.SPADE, Rank.TWO), Card(Suit.SPADE, Rank.THREE), Card(Suit.SPADE, Rank.THREE), Card(Suit.SPADE, Rank.FOUR), Card(Suit.SPADE, Rank.FOUR) ] self.hand_value_helper(hand_16, hand_16, PlayerStatus.LOSE, PlayerStatusReason.DEALER_HAND_VALUE) self.hand_value_helper(hand_16, hand_17, PlayerStatus.WIN, PlayerStatusReason.HAND_VALUE) self.hand_value_helper(hand_17, hand_16, PlayerStatus.LOSE, PlayerStatusReason.DEALER_HAND_VALUE) self.hand_value_helper(hand_21, hand_blackjack, PlayerStatus.WIN, PlayerStatusReason.BLACKJACK) self.hand_value_helper(hand_21, hand_fivecard, PlayerStatus.WIN, PlayerStatusReason.FIVECARD)