def test_1_repeated_win(): def round_runner(g): game_round = start_round_from_player_cards( [cards.Guard(), cards.Baron()], [cards.King(), cards.Princess()], first_player=0, ) object.__setattr__(g.state, "round", game_round) # work around frozen dataclass player0, player1 = game_round.players play_with_choices(player0, CardType.GUARD, player1, cards.Princess) play_random_move(player1) end = game_round.state assert end.type == RoundState.Type.ROUND_END assert end.winner is player0 game = Game(["Alice", "Bob"]) alice, bob = game.players game.start() for i in range(1, 8): assert game.state.round_no == i round_runner(game) game.advance() assert +game.points == {alice: i} assert game.ended assert game.state.winner is alice
def test_advance_pointThresholdReached_gameEnds(started_game: Game, winner): winner = started_game.players[winner % started_game.num_players] started_game.points[winner] = started_game.points_threshold force_end_round(started_game.current_round) end = started_game.advance() assert end.type == GameState.Type.END assert end.winner is winner
def test_advance_roundHasEnded_startsNewRound(started_game: Game): game_round = started_game.current_round assert not game_round.ended force_end_round(game_round) new_state: loveletter.game.PlayingRound = started_game.advance() new_round = new_state.round assert new_round is not game_round assert started_game.current_round is new_round assert not new_round.started
def test_advance_roundFinished_pointsUpdateCorrectly(started_game: Game): game_round = started_game.current_round old_points = started_game.points.copy() autoplay_round(game_round) new_state = started_game.advance() assert not new_state.round.started winners = {started_game.players[p.id] for p in game_round.state.winners} new_points = started_game.points diffs = new_points - old_points # no negative points: assert not -new_points # at most one point per player plus the extra spy point: assert all(diff <= 2 for diff in diffs.values()) # winners got at least one point each: assert all(diffs[p] >= 1 for p in winners) # at most 1 non-winner positive diff assert len(set(diffs.keys()) - winners) <= 1 # at most one diff larger than 1: assert sum(int(diff > 1) for diff in diffs.values()) <= 1
def test_advance_roundNotEnded_raises(started_game: Game): game_round = started_game.current_round if not game_round.started: game_round.start() with pytest.raises(valid8.ValidationError): started_game.advance()