Ejemplo n.º 1
0
def run(rounds=1):
    rounds = int(rounds)
    players = [Player(role="Dealer"), Player(role="Player")]
    game = Game(players, Shoe())
    for i in range(rounds):
        hands = game.start_round
        winners = Game.getWinners(hands)
        displayResult(winners)
Ejemplo n.º 2
0
 def test_moreThan1_dealer_raises_ValueErr(self):
     player0 = Player(role="Dealer")
     player1 = Player(role="Dealer")
     player2 = Player(role="Player")
     players = [player0, player1, player2]
     shoe = Shoe(1)
     with pytest.raises(ValueError):
         Game(players, shoe)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
def dealer_hand():
    return Hand(Player(role.DEALER))
Ejemplo n.º 5
0
def dealer():
    return Player(role.DEALER)
Ejemplo n.º 6
0
def player():
    return Player()
Ejemplo n.º 7
0
 def test_role_defaults_to_player(self):
     assert Player().role == 'Player'