def test_interal_game_reset_functionality(): p1 = Player("bob") p2 = Player("sharon") game = Game(deck=StandardDeck(), agents=[p1, p2], n_rounds=2, cards_per_player=10) game.play_round() assert game.turn == 11 game.play_round() assert game.turn == 21 game.reset_game() assert game.turn == 0 assert len(p1.hand) == 10 assert len(p2.hand) == 10 # def test_simulated_games_should_be_distinct(): # p1 = Player("bob") # p2 = Player("sharon") # game = Game(deck_constructor=StandardDeck, agents=[p1, p2], n_rounds=2, cards_per_player=10) # result1 = game.simulate_game() # result2 = game.simulate_game() # result3 = game.simulate_game() # result4 = game.simulate_game() # result5 = game.simulate_game() # print(result5[['action', 'player', 'round', 'reward']]) # assert result5['bob'] < 100 # assert result5['sharon'] < 100
def test_after_game_players_have_no_cards(): p1 = Player("bob") p2 = Player("sharon") game = Game(deck=StandardDeck(), agents=[p1, p2], n_rounds=1) game.play_round() assert len(p1.hand) == 0 assert len(p2.hand) == 0
def test_turns_update(): p1 = Player("bob") p2 = Player("sharon") game = Game(deck=StandardDeck(), agents=[p1, p2], n_rounds=2) game.play_round() assert game.turn == 11 game.play_round() assert game.turn == 21
def simple_egg_score_test(): p1 = Player("bob") p2 = Player("sharon") d = Deck.create([NigiriCard('egg')], [1000]) g = Game(deck=d, agents=[p1, p2], cards_per_player=10) g.play_round() g.play_round() print(g.gamelog) assert g.gamelog.shape[0] == 42 assert g.gamelog['reward'][2] == 0.0 assert g.gamelog['reward'][3] == 0.0
def test_certain_cards_carry_rewards_at_end_of_round(): p1 = Player("bob") p2 = Player("sharon") # create a deck with no cards that are worth points during a round d = Deck.create([MakiCard(3)], [100]) g = Game(deck=d, agents=[p1, p2], cards_per_player=10) g.play_round() g.play_round() print(g.gamelog) assert g.gamelog.shape[0] == 42 assert g.gamelog['reward'][0] == 0.0 assert g.gamelog['reward'][1] == 0.0
def test_simple_one_winner_one_round(): p1 = Player("bob") p2 = Player("sharon") d = Deck.create([NigiriCard('egg'), NigiriCard('salmon')], [19, 1]) g = Game(deck=d, agents=[p1, p2], cards_per_player=10, n_rounds=1) g.play_round() bob_log = g.gamelog[g.gamelog['player'] == 'bob'] bob_final_reward = bob_log['reward'].iloc[-1] sharon_log = g.gamelog[g.gamelog['player'] == 'sharon'] sharon_final_reward = sharon_log['reward'].iloc[-1] print(g.gamelog) assert g.gamelog.shape[0] == 22 assert (bob_final_reward == 10.) or (bob_final_reward == 11.) assert (sharon_final_reward == 10.) or (sharon_final_reward == 11.)
def test_after_turn_hands_exchange_two_player(): p1 = Player("bob") p2 = Player("sharon") game = Game(deck=StandardDeck(), agents=[p1, p2], n_rounds=2) print(game.scores) scores0 = game.end_results() game.play_round() scores1 = game.end_results() game.play_round() scores2 = game.end_results() print(scores1) print(scores2) assert scores0['bob'] == 0.0 assert scores1['bob'] > 0.0 assert scores2['bob'] > 0.0 assert scores2['sharon'] > 0.0
def test_after_turn_hands_exchange_three_player(): p1 = Player("bob") p2 = Player("sharon") p3 = Player("alice") game = Game(deck=StandardInfiniDeck(), agents=[p1, p2, p3], n_rounds=3) scores0 = game.end_results() game.play_round() scores1 = game.end_results() game.play_round() scores2 = game.end_results() game.play_round() scores3 = game.end_results() assert scores3['bob'] > scores1['bob'] assert scores3['alice'] > scores0['alice'] assert scores3['bob'] > scores1['bob'] assert scores3['sharon'] > scores1['sharon']