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

        mock_deck = MagicMock()
        mock_deck.remove_cards.side_effect = [
            self.first_two_cards,
            self.next_two_cards,
            self.flop_cards,
            self.turn_card,
            self.river_card
        ]

        mock_player1 = MagicMock()
        mock_player2 = MagicMock()
        players = [mock_player1, mock_player2]

        game_round = GameRound(
            deck = mock_deck,
            players = players
        )

        game_round.play()

        mock_deck.remove_cards.assert_has_calls([
            call(2), call(2)
        ])

        mock_player1.add_cards.assert_has_calls([
            call(self.first_two_cards)
        ])
        mock_player2.add_cards.assert_has_calls([
            call(self.next_two_cards)
        ])
    def test_deals_each_player_3_flop_1_turn_and_1_river_cards(self):
        mock_player1 = MagicMock()
        mock_player1.wants_to_fold.return_value = False
        mock_player2 = MagicMock()
        mock_player2.wants_to_fold.return_value = False

        players = [mock_player1, mock_player2]

        mock_deck = MagicMock()
        mock_deck.remove_cards.side_effect = [
            self.first_two_cards, self.next_two_cards, self.flop_cards,
            self.turn_card, self.river_card
        ]

        game_round = GameRound(deck=mock_deck, players=players)
        game_round.play()

        mock_deck.remove_cards.assert_has_calls([call(3), call(1), call(1)])

        calls = [
            call(self.flop_cards),
            call(self.turn_card),
            call(self.river_card)
        ]

        for player in players:
            player.add_cards.assert_has_calls(calls)
Пример #3
0
 def _create_players(self, number):
     names = Names()
     self.hide_player_buttons()
     self._root.update()
     deck = CardDeck()
     cards = Card.create_cards()
     deck.add_cards(cards)
     hand = Hand()
     player = Player(f"Player", hand)
     self._players.append(player)
     human = Human(player=player, gui=self)
     for i in range(number):
         hand = Hand()
         # player = Player(f"Opponent {i + 1}", hand)
         player = Player(names.get_random_name(), hand)
         self._players.append(player)
         ai = AI(player=player)
     self.hide_player_buttons()
     for player in self._players:
         player.add_chips(60)
     game = GameRound(players=self._players, deck=deck, gui=self)
     # game.set_game_qty(game_qty=10)
     game.set_game_qty(infinite=True)
     game.play()
     self.stop()
Пример #4
0
    def test_game_play_shuffles_deck(self):
        mock_deck = MagicMock()

        players = [MagicMock(), MagicMock()]

        game_round = GameRound(deck=mock_deck, players=players)

        game_round.play()
        mock_deck.shuffle.assert_called_once()
    def test_removes_player_if_not_willing_to_make_bet(self):
        deck = MagicMock()
        player1 = MagicMock()
        player2 = MagicMock()

        player1.wants_to_fold.return_value = True
        player2.wants_to_fold.return_value = False
        players = [player1, player2]

        game_round = GameRound(deck=deck, players=players)
        game_round.play()

        self.assertEqual(game_round.players, [player2])
Пример #6
0
def create_players(number):
    deck = CardDeck()
    cards = Card.create_cards()
    deck.add_cards(cards)
    hand = Hand()
    player = Player(f"Player", hand)
    players.append(player)
    human = Human(player=player)
    for i in range(number):
        hand = Hand()
        player = Player(f"Opponent {i}", hand)
        players.append(player)
        ai = AI(player=player)
    hide_buttons()
    for player in players:
        player.add_chips(60)
    game = GameRound(players=players, deck=deck)
    # game.set_game_qty(game_qty=10)
    game.set_game_qty(infinite=True)
    game.play()
Пример #7
0
from poker.card import Card
from poker.deck import Deck
from poker.game_round import GameRound
from poker.hand import Hand
from poker.player import Player

deck = Deck()
cards = Card.create_standard_52_cards()
deck.add_cards(cards)

hand1 = Hand()
hand2 = Hand()

player1 = Player(name="Boris", hand=hand1)
player2 = Player(name="Boby", hand=hand2)
players = [player1, player2]

game_round = GameRound(deck=deck, players=players)
game_round.play()

for player in players:
    print(f"{player.name} receives a {player.hand}.")
    index, hand_name, hand_cards = player.best_hand()
    hand_cards_strings = [str(card) for card in hand_cards]
    hand_cards_string = " and ".join(hand_cards_strings)
    print(f"{player.name} has a {hand_name} with a {hand_cards_string}.")

winning_player = max(players)

print(f"The winner is {winning_player.name}.")