From 995853e046ca044762511e53e9fa3c18f62793ae Mon Sep 17 00:00:00 2001 From: Giulio Date: Fri, 4 Mar 2022 01:44:36 +0100 Subject: [PATCH] fix outlaw and victory from death --- backend/bang/game.py | 3 +-- backend/bang/roles.py | 4 +++- backend/tests/roles_test.py | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/backend/bang/game.py b/backend/bang/game.py index d608ae7..24f2371 100644 --- a/backend/bang/game.py +++ b/backend/bang/game.py @@ -432,7 +432,7 @@ class Game: print(f'{self.name}: WE HAVE A WINNER - pending winners') else: print(f'{self.name}: WE HAVE A WINNER') - for p in self.get_alive_players(): + for p in self.players: if winners is None: p.win_status = p in self.pending_winners else: @@ -648,7 +648,6 @@ class Game: if player.attacker and player.attacker in self.players: attacker_role = player.attacker.role winners = [p for p in self.players if p.role != None and p.role.on_player_death(self.get_alive_players(), initial_players=self.initial_players, dead_role=player.role, attacker_role=attacker_role)] - #print(f'win check: ready-{self.ready_count} waiting-{self.waiting_for} winners:{len(winners)}') if not self.attack_in_progress and len(winners) > 0 and not self.someone_won: return self.announces_winners(winners) elif len(winners) > 0 and not self.someone_won: # non tutti hanno risposto, ma ci sono vincitori. diff --git a/backend/bang/roles.py b/backend/bang/roles.py index 3acb20b..32eb94d 100644 --- a/backend/bang/roles.py +++ b/backend/bang/roles.py @@ -62,7 +62,9 @@ class Outlaw(Role): return True elif initial_players == 3 and attacker_role != None: return isinstance(dead_role, Vice) and isinstance(attacker_role, Outlaw) - elif initial_players != 3 and (not any([isinstance(p.role, Sheriff) for p in alive_players])) and any([isinstance(p.role, Outlaw) for p in alive_players]): + elif (initial_players != 3 and (not any([isinstance(p.role, Sheriff) for p in alive_players])) + and (any([isinstance(p.role, Outlaw) for p in alive_players]) + or any([isinstance(p.role, Renegade) for p in alive_players]) and len(alive_players) > 1)): print("The Outlaw won!") return True return False diff --git a/backend/tests/roles_test.py b/backend/tests/roles_test.py index 33561a8..ab32b4f 100644 --- a/backend/tests/roles_test.py +++ b/backend/tests/roles_test.py @@ -176,4 +176,38 @@ def test_5p_renegade_indiani_win(): assert (hasattr(g.players[i], 'win_status') and g.players[i].win_status) else: print(g.players[i].role.name, 'win_status:', (hasattr(g.players[i], 'win_status') and g.players[i].win_status)) - assert not (hasattr(g.players[i], 'win_status') and g.players[i].win_status) \ No newline at end of file + assert not (hasattr(g.players[i], 'win_status') and g.players[i].win_status) + +# test that a game with 5 player the renegade kills the sheriff but it isn't the last alive player and the outlaws wins +def test_5p_outlaw_death_win(): + sio = DummySocket() + g = Game('test', sio) + for i in range(5): + p = Player(f'p{i}', f'p{i}', sio) + g.add_player(p) + g.start_game() + for p in g.players: + p.available_characters = [Character('test_char', 4)] + p.set_character(p.available_characters[0].name) + roles = {g.players[i].role.name:i for i in range(len(g.players))} + print(roles) + assert len(roles) == 4 + assert isinstance(g.players[g.turn].role, Sheriff) + g.players[g.turn].is_my_turn = False + for i in range(len(g.players)): + g.players[i].lives = 1 + g.players[i].hand = [] + g.players[roles['Vice']].lives = 2 + g.turn = roles['Rinnegato'] + g.play_turn() + g.players[g.turn].draw('') + g.players[g.turn].hand = [Gatling(0,0)] + g.players[g.turn].play_card(0) + for i in range(len(g.players)): + if isinstance(g.players[i].role, Outlaw): + print (g.players[i].role.name, 'win_status:', hasattr(g.players[i], 'win_status') and g.players[i].win_status) + assert (hasattr(g.players[i], 'win_status') and g.players[i].win_status) + assert (hasattr(g.players[i], 'is_dead') and g.players[i].is_dead) + else: + print(g.players[i].role.name, 'win_status:', (hasattr(g.players[i], 'win_status') and g.players[i].win_status)) + assert not (hasattr(g.players[i], 'win_status') and g.players[i].win_status)