コード例 #1
0
ファイル: test_hand.py プロジェクト: emmy-omega/blackjack
 def test_is_blackjack(self, player, sec_hand):
     hand = Hand(player)
     ace = Card.generate('A')
     hand.cards.append(ace)
     hand.cards.append(Card.generate(sec_hand))
     assert len([c for c in hand.cards if c.type == 'high']) == 2
     assert hand.is_soft
     assert hand.is_blackjack
コード例 #2
0
ファイル: test_hand.py プロジェクト: emmy-omega/blackjack
 def test_is_paired(self, player):
     hand = Hand(player)
     hand.cards.append(Card.generate('T'))
     hand.cards.append(Card.generate('T'))
     assert hand.is_paired
     hand.cards.pop()
     hand.cards.append(Card.generate('8'))
     assert not hand.is_paired
コード例 #3
0
ファイル: test_hand.py プロジェクト: emmy-omega/blackjack
 def test_is_soft(self, player):
     hand = Hand(player)
     ace = Card.generate('A')
     hand.cards.append(ace)
     hand.cards.append(Card.generate('9'))
     assert hand.is_soft
     hand.cards.remove(ace)
     hand.cards.append(Card.generate('T'))
     assert not hand.is_soft
コード例 #4
0
ファイル: game.py プロジェクト: emmy-omega/blackjack
    def start_round(self):
        """
        Execute a round of blackjack game.

            :returns
            hands(list): List of Hand that took part

        """
        self.shoe.shuffle()
        hands = [Hand(self.dealer), Hand(self.player)]
        player_hand = getPlayerHand(hands)
        dealer_hand = getDealerHand(hands)

        self.deal_init_cards(hands)

        # check if dealer has blackjack
        if dealer_hand.is_blackjack:
            dealer_hand.cards[1].is_face_up = True
            display_cards(hands)
            # end round
            return hands
        # check if player has is blackjack
        elif player_hand.is_blackjack:
            dealer_hand.cards[1].is_face_up = True
            display_cards(hands)
            # end round
            return hands

        if not player_hand.is_blackjack:
            player_hands = getPlayerHands(hands)
            while len(player_hands) != 0:
                hand = player_hands.pop()
                if not hand.is_blackjack:
                    self.play_player_hand(hand, hands, player_hands)
                else:
                    break
        # check if all player hands are bust
        bust_player_hands = [
            hand for hand in hands
            if hand.owner.role == role.PLAYER and hand.state == state.BUST
        ]
        if not len(bust_player_hands) == len(getPlayerHands(hands)):
            self.play_dealer_hand(hands)
        return hands
コード例 #5
0
ファイル: game.py プロジェクト: emmy-omega/blackjack
    def play_player_hand(self, hand, hands, player_hands):
        """
        Executes a player hand sequence of action.

        The updates the state of the player's hand in reaction to player decisions and changes to cards in the hand

        :param hand: the players hand(one of) being acted upon
        :param hands: All hands participating in the round
        :param player_hands: All hands the belong to the player
        """
        while hand.state == state.IN:
            if not hand.is_splittable and len(hand.cards) == 1:
                hand.cards.append(self.shoe.deal())
                display_cards(hands)
            if hand.total > 21:
                hand.state = state.BUST
                break
            decision = Player.act(hand)
            if decision == "stand":
                hand.state = state.STAND

            elif decision == "double":
                # deal only one more card
                hand.cards.append(self.shoe.deal())
                display_cards(hands)
                break

            elif decision == "split":
                card = hand.cards.pop()
                split_hand = Hand(hand.owner)
                split_hand.cards.append(card)
                hands.append(split_hand)
                player_hands.append(split_hand)
                hand.is_splittable = False
                split_hand.is_splittable = False
                display_cards(hands)
                self.play_player_hand(hand, hands, player_hands)

            elif decision == "surrender":
                hand.state = state.SURRENDER
            else:
                hand.cards.append(self.shoe.deal())
                display_cards(hands)
コード例 #6
0
def dealer_hand():
    return Hand(Player(role.DEALER))
コード例 #7
0
def hand(player):
    return Hand(owner=player)
コード例 #8
0
ファイル: test_hand.py プロジェクト: emmy-omega/blackjack
 def test_aces_not_blackjack(self, player):
     hand = Hand(player)
     hand.cards.append(Card.generate('A'))
     hand.cards.append(Card.generate('A'))
     assert not hand.is_blackjack
コード例 #9
0
ファイル: test_hand.py プロジェクト: emmy-omega/blackjack
 def test_non_aced_is_hard(self, player):
     hand = Hand(player)
     hand.cards.append(Card.generate('T'))
     hand.cards.append(Card.generate('T'))
     assert not hand.is_soft