fix outlaw and victory from death
This commit is contained in:
parent
1c95327b83
commit
995853e046
@ -432,7 +432,7 @@ class Game:
|
|||||||
print(f'{self.name}: WE HAVE A WINNER - pending winners')
|
print(f'{self.name}: WE HAVE A WINNER - pending winners')
|
||||||
else:
|
else:
|
||||||
print(f'{self.name}: WE HAVE A WINNER')
|
print(f'{self.name}: WE HAVE A WINNER')
|
||||||
for p in self.get_alive_players():
|
for p in self.players:
|
||||||
if winners is None:
|
if winners is None:
|
||||||
p.win_status = p in self.pending_winners
|
p.win_status = p in self.pending_winners
|
||||||
else:
|
else:
|
||||||
@ -648,7 +648,6 @@ class Game:
|
|||||||
if player.attacker and player.attacker in self.players:
|
if player.attacker and player.attacker in self.players:
|
||||||
attacker_role = player.attacker.role
|
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)]
|
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:
|
if not self.attack_in_progress and len(winners) > 0 and not self.someone_won:
|
||||||
return self.announces_winners(winners)
|
return self.announces_winners(winners)
|
||||||
elif len(winners) > 0 and not self.someone_won: # non tutti hanno risposto, ma ci sono vincitori.
|
elif len(winners) > 0 and not self.someone_won: # non tutti hanno risposto, ma ci sono vincitori.
|
||||||
|
@ -62,7 +62,9 @@ class Outlaw(Role):
|
|||||||
return True
|
return True
|
||||||
elif initial_players == 3 and attacker_role != None:
|
elif initial_players == 3 and attacker_role != None:
|
||||||
return isinstance(dead_role, Vice) and isinstance(attacker_role, Outlaw)
|
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!")
|
print("The Outlaw won!")
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -177,3 +177,37 @@ def test_5p_renegade_indiani_win():
|
|||||||
else:
|
else:
|
||||||
print(g.players[i].role.name, 'win_status:', (hasattr(g.players[i], 'win_status') and g.players[i].win_status))
|
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)
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user