From 4ae503b29a97d06a85d8d90c44110e203c3741ec Mon Sep 17 00:00:00 2001 From: Askaholic Date: Fri, 29 Dec 2023 21:04:15 -0500 Subject: [PATCH] Always compute team outcomes --- server/games/game.py | 25 ++++++++++++------------- tests/integration_tests/test_game.py | 8 ++++---- tests/unit_tests/test_game.py | 4 ++-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/server/games/game.py b/server/games/game.py index a489005e6..f672b8b6d 100644 --- a/server/games/game.py +++ b/server/games/game.py @@ -466,20 +466,19 @@ async def resolve_game_results(self) -> EndedGameInfo: ] team_outcomes = [GameOutcome.UNKNOWN for _ in basic_info.teams] + team_player_partial_outcomes = [ + {self.get_player_outcome(player) for player in team} + for team in basic_info.teams + ] - if self.validity is ValidityState.VALID: - team_player_partial_outcomes = [ - {self.get_player_outcome(player) for player in team} - for team in basic_info.teams - ] - - try: - # TODO: Remove override once game result messages are reliable - team_outcomes = ( - self._outcome_override_hook() - or resolve_game(team_player_partial_outcomes) - ) - except GameResolutionError: + try: + # TODO: Remove override once game result messages are reliable + team_outcomes = ( + self._outcome_override_hook() + or resolve_game(team_player_partial_outcomes) + ) + except GameResolutionError: + if self.validity is ValidityState.VALID: await self.mark_invalid(ValidityState.UNKNOWN_RESULT) try: diff --git a/tests/integration_tests/test_game.py b/tests/integration_tests/test_game.py index 8ca9f39e7..d5b451205 100644 --- a/tests/integration_tests/test_game.py +++ b/tests/integration_tests/test_game.py @@ -1216,6 +1216,8 @@ async def test_galactic_war_2v1_game_ended_broadcasts_army_results(lobby_server, "sim_mod_ids": [], "teams": [ { + "outcome": "VICTORY", + "player_ids": [1, 3], "army_results": [ { "player_id": 1, @@ -1230,10 +1232,10 @@ async def test_galactic_war_2v1_game_ended_broadcasts_army_results(lobby_server, "metadata": ["recall"], }, ], - "outcome": "UNKNOWN", - "player_ids": [1, 3] }, { + "outcome": "DEFEAT", + "player_ids": [6], "army_results": [ { "player_id": 6, @@ -1242,8 +1244,6 @@ async def test_galactic_war_2v1_game_ended_broadcasts_army_results(lobby_server, "metadata": ["recall"], }, ], - "outcome": "UNKNOWN", - "player_ids": [6] }, ], "validity": "UNEVEN_TEAMS_NOT_RANKED", diff --git a/tests/unit_tests/test_game.py b/tests/unit_tests/test_game.py index 14ff3f24d..c747ed781 100644 --- a/tests/unit_tests/test_game.py +++ b/tests/unit_tests/test_game.py @@ -1056,7 +1056,7 @@ async def test_army_results_present_for_invalid_games(game: Game, game_add_playe game_results = await game.resolve_game_results() result_dict = game_results.to_dict() - assert result_dict["teams"][0]["outcome"] == "UNKNOWN" + assert result_dict["teams"][0]["outcome"] == "VICTORY" assert result_dict["teams"][0]["army_results"] == [ { "player_id": 1, @@ -1071,7 +1071,7 @@ async def test_army_results_present_for_invalid_games(game: Game, game_add_playe "metadata": [], }, ] - assert result_dict["teams"][1]["outcome"] == "UNKNOWN" + assert result_dict["teams"][1]["outcome"] == "DEFEAT" assert result_dict["teams"][1]["army_results"] == [ { "player_id": 3,