def test_deck_stop(): d = Deck(MakiCard(1), MakiCard(2)) _ = next(d) _ = next(d) try: _ = next(d) raise RuntimeError('Deck returns too many cards') except StopIteration: pass
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_certain_cards_carry_no_rewards_within_rounds(): p1 = Player("bob") p2 = Player("sharon") # create a deck with no cards that are worth points during a round d = Deck.create([PuddingCard(), WasabiCard(), MakiCard(3)], [8, 4, 4 * 7]) g = Game(deck=d, agents=[p1, p2], cards_per_player=5) g.play_turn() assert g.gamelog.shape[0] == 4 assert g.gamelog['reward'][0] == 0.0 assert g.gamelog['reward'][1] == 0.0 g.play_turn() g.play_turn() g.play_turn() assert g.gamelog['reward'].iloc[-1] == 0.0
def test_deck_init(): d = Deck(MakiCard(1), MakiCard(2)) assert len(d.cards) == 2 assert len(d.initial_cards) == 2
def test_deck_reshuffle(): d = Deck(MakiCard(1), MakiCard(2)) _ = next(d) d.reset() _ = next(d) _ = next(d)
def test_reward_in_log_needs_to_accumulate(): p1 = Player("bob") p2 = Player("sharon") d = Deck.create([DumplingCard()], [1000]) game = Game(deck=d, agents=[p1, p2], n_rounds=2)