def play(stake, players): game = Game(stake, players) print(f"\nGoing to start with ${stake} stake and {len(players)} players") game.start() r = 1 while game.winner == None: print(f'Round {r}; current player - {game.players[0].name}') print(format_game_state(game)) r += 1 game.next_turn() print(format_game_state(game)) winner_name = game.winner.name game.finish() print( f'{winner_name} has won the game!\n Players: {format_players_balance(players)}' ) for p in players: if p.balance == 0: print(f"{p.name} does not have enough money to continue...") sys.exit(0) ask_replay(players)
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)
def test_complete_dealers_hand(self): # Cards given to the player. players_cards = [ Card(1, SUIT_SPADES), Card(2, SUIT_SPADES), ] # Cards given to the dealer. dealers_cards = [ Card(3, SUIT_SPADES), Card(7, SUIT_SPADES), Card(8, SUIT_SPADES), ] deck = players_cards + dealers_cards + [ Card(9, SUIT_SPADES), ] with patch.object(Game, 'shuffle_deck', autospec=True): game = Game(deck) game.start() game.complete_dealers_hand() dealer = game.dealer self.assertEqual(dealers_cards, dealer.hand.cards)
def test_complete_dealers_hand_does_not_hit_on_hard_17(self): # Cards given to the player. players_cards = [ Card(4, SUIT_SPADES), Card(5, SUIT_SPADES), ] # Cards given to the dealer. dealers_cards = [ Card(10, SUIT_SPADES), Card(6, SUIT_SPADES), Card(1, SUIT_SPADES), ] deck = players_cards + dealers_cards + [ Card(9, SUIT_SPADES), ] with patch.object(Game, 'shuffle_deck', autospec=True): game = Game(deck) game.start() game.complete_dealers_hand() dealer = game.dealer self.assertEqual(dealers_cards, dealer.hand.cards, 'Dealer must not hit on a hard 17')