Пример #1
0
    def test_play_hand_stand(self):
        game = Game()

        game.add_player()

        game.players[-1].hands.append(build_hand('hard'))
        game.players[0].hands.append(build_hand('hard'))

        self.assertEqual(2, len(game.players[0].hands[0].cards))
Пример #2
0
    def test_start(self):
        game = Game(GameSettings(num_decks=1))

        game.add_player()

        num_rounds = 10
        game.start(rounds=num_rounds)

        self.assertEqual(num_rounds, game.round_count)
Пример #3
0
    def test_add_player_default(self):
        game = Game()

        bankroll = 100
        game.add_player(player_settings={'bankroll': bankroll})

        self.assertEqual(2, len(game.players))
        self.assertEqual(bankroll, game.players[0].bankroll)
        self.assertEqual(False, game.players[0].dealer)
        self.assertEqual(1, game.players[0].number)
Пример #4
0
    def test_play_hand_hit(self):
        game = Game()

        game.add_player()

        game.players[-1].hands.append(build_hand('hard'))
        game.players[0].hands.append(build_hand('soft'))

        game.play_hand(game.players[0], game.players[0].hands[0])

        self.assertLess(2, len(game.players[0].hands[0].cards))
Пример #5
0
    def test_add_player_multiple(self):
        game = Game()

        num_players = 3
        for _ in range(num_players):
            game.add_player()

        self.assertEqual(num_players + 1, len(game.players))

        for i in range(num_players):
            self.assertEqual(i + 1, game.players[i].number)
Пример #6
0
    def test_play_hand_split(self):
        game = Game()

        game.add_player()

        game.players[-1].hands.append(build_hand('hard'))
        game.players[0].hands.append(build_hand('hard_pair'))

        self.assertEqual(game.settings.min_bet, game.players[0].hands[0].bet)
        game.play_hand(game.players[0], game.players[0].hands[0])
        self.assertEqual(game.settings.min_bet, game.players[0].hands[1].bet)
        game.play_hand(game.players[0], game.players[0].hands[1])

        self.assertLessEqual(2, len(game.players[0].hands[0].cards))
        self.assertLessEqual(2, len(game.players[0].hands[1].cards))
Пример #7
0
    def test_play_round(self):
        game = Game()

        game.add_player()

        pre_round_count = game.round_count
        game.play_round()

        self.assertEqual(pre_round_count + 1, game.round_count)

        for player in game.players:
            self.assertLess(0, len(player.hands[0].cards))

        for player in game.players[:-1]:
            self.assertNotEqual(None, player.hands[0].result)
Пример #8
0
    def assign_player(self, player):
        game = None
        for gameId, potentialGame in self.games.iteritems():
            if not potentialGame.is_full():
                game = potentialGame
                break
        if game is None:
            gameId = str(uuid.uuid4())
            game = Game(gameId)
            self.games[gameId] = game
            print 'created new game with ID {}'.format(gameId)

        game.add_player(player)
        self.playerAssignments[player.id] = game
        print 'added player {} to game {}'.format(player.id, game.id)
        return game
Пример #9
0
    def test_play_hand_double_down(self):
        game = Game()

        bankroll = 100
        game.add_player(player_settings={'bankroll': bankroll})

        game.players[-1].hands.append(build_hand('soft'))
        game.players[0].hands.append(build_hand('double_down'))
        game.players[0].bankroll -= game.settings.min_bet

        game.play_hand(game.players[0], game.players[0].hands[0])

        self.assertEqual(bankroll - (game.settings.min_bet * 2),
                         game.players[0].bankroll)
        self.assertEqual(game.settings.min_bet * 2,
                         game.players[0].hands[0].bet)
        self.assertEqual(3, len(game.players[0].hands[0].cards))
Пример #10
0
    def test_add_player_options(self):
        game = Game()

        bankroll = 100
        bet_limit = 25
        bet_strategy_type = BetStrategyType.MARTINGALE

        game.add_player(player_settings={
            'bet_strategy_type': bet_strategy_type,
            'bet_limit': bet_limit
        })

        self.assertEqual(2, len(game.players))
        self.assertEqual(bankroll, game.players[0].bankroll)
        self.assertEqual(bet_strategy_type,
                         game.players[0].bet_strategy.strategy_type)
        self.assertEqual(False, game.players[0].dealer)
        self.assertEqual(bet_limit, game.players[0].bet_limit)
        self.assertEqual(1, game.players[0].number)