Skip to content

Commit

Permalink
Always compute team outcomes
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic committed Dec 30, 2023
1 parent d0152da commit 4ae503b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
25 changes: 12 additions & 13 deletions server/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions tests/integration_tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 4ae503b

Please sign in to comment.