easier to read

This commit is contained in:
Alberto Xamin 2020-12-22 15:11:47 +01:00
parent 83359eb497
commit db2173beea
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
2 changed files with 28 additions and 32 deletions

View File

@ -428,6 +428,7 @@ class Game:
'lives': self.players[j].lives, 'lives': self.players[j].lives,
'max_lives': self.players[j].max_lives, 'max_lives': self.players[j].max_lives,
'is_sheriff': isinstance(self.players[j].role, roles.Sheriff), 'is_sheriff': isinstance(self.players[j].role, roles.Sheriff),
'cards': len(self.players[j].hand)+len(self.players[j].equipment)
} for j in range(len(self.players)) if i != j] } for j in range(len(self.players)) if i != j]
def notify_all(self): def notify_all(self):

View File

@ -223,43 +223,38 @@ class Player:
elif self.pending_action == PendingAction.DRAW: elif self.pending_action == PendingAction.DRAW:
self.draw('') self.draw('')
elif self.pending_action == PendingAction.PLAY: elif self.pending_action == PendingAction.PLAY:
equippables = [c for c in self.hand if (c.is_equipment or c.usable_next_turn) and not isinstance(c, cs.Prigione) and not self.game.check_event(ce.IlGiudice) and not any([type(c) == type(x) for x in self.equipment])] equippables = [c for c in self.hand if (c.is_equipment or c.usable_next_turn) and not isinstance(c, cs.Prigione) and not any([type(c) == type(x) for x in self.equipment])]
if len(equippables) > 0: misc = [c for c in self.hand if isinstance(c, cs.WellsFargo) or isinstance(c, cs.Diligenza) or isinstance(c, cs.Emporio) or (isinstance(c, cs.Birra) and self.lives < self.max_lives)]
need_target = [c for c in self.hand if c.need_target and c.can_be_used_now and not (c.need_with and len(self.hand) < 2) and not (self.has_played_bang and not (any([isinstance(c, cs.Volcanic) for c in self.equipment]) and not self.game.check_event(ce.Lazo)))]
green_cards = [c for c in self.equipment if not self.game.check_event(ce.Lazo) and not isinstance(c, cs.Mancato) and c.usable_next_turn and c.can_be_used_now]
if len(equippables) > 0 and not self.game.check_event(ce.IlGiudice):
for c in equippables: for c in equippables:
if self.play_card(self.hand.index(c)): if self.play_card(self.hand.index(c)):
return return
elif any([isinstance(c, cs.WellsFargo) or isinstance(c, cs.Diligenza) or isinstance(c, cs.Emporio) or isinstance(c, cs.Birra) for c in self.hand]): elif len(misc) > 0:
for i in range(len(self.hand)): for c in misc:
c = self.hand[i] if self.play_card(self.hand.index(c)):
if isinstance(c, cs.WellsFargo) or isinstance(c, cs.Diligenza) or isinstance(c, cs.Emporio) or (isinstance(c, cs.Birra) and self.lives < self.max_lives): return
if self.play_card(i): elif len(need_target) > 0:
return for c in need_target:
elif len([c for c in self.hand if c.need_target and c.can_be_used_now and not (c.is_equipment and self.game.check_event(ce.IlGiudice)) and not (self.has_played_bang and not (any([isinstance(c, cs.Volcanic) for c in self.equipment]) and not self.game.check_event(ce.Lazo)))]) > 0: _range = self.get_sight() if c.name == 'Bang!' or c.name == "Pepperbox" else c.range
for i in range(len(self.hand)): others = [p for p in self.game.get_visible_players(self) if _range >= p['dist'] and not (isinstance(self.role, r.Vice) and p['is_sheriff']) and p['lives'] > 0 and not ((isinstance(c, cs.CatBalou) or isinstance(c, cs.Panico)) and p['cards'] == 0) and not (p['is_sheriff'] and isinstance(c, cs.Prigione))]
if self.hand[i].need_target and not (self.has_played_bang and not any([isinstance(c, cs.Volcanic) for c in self.equipment])): if len(others) == 0:
if self.hand[i].need_with and len(self.hand) < 2: continue
continue target = others[randrange(0, len(others))]
_range = self.get_sight() if self.hand[i].name == 'Bang!' or self.hand[i].name == "Pepperbox" else self.hand[i].range if target['is_sheriff'] and isinstance(self.role, r.Renegade):
others = [p for p in self.game.get_visible_players(self) if _range >= p['dist'] and not (isinstance(self.role, r.Vice) and p['is_sheriff']) and p['lives'] > 0]
if len(others) == 0:
continue
target = others[randrange(0, len(others))] target = others[randrange(0, len(others))]
if target['is_sheriff'] and isinstance(self.role, r.Renegade): if not c.need_with:
target = others[randrange(0, len(others))] if self.play_card(self.hand.index(c), against=target['name']):
if not self.hand[i].need_with: return
if self.play_card(i, against=target['name']): else:
return if self.play_card(self.hand.index(c), against=target['name'], _with=sample([j for j in range(len(self.hand)) if j != self.hand.index(c)], 1)[0]):
else: return
if self.play_card(i, against=target['name'], _with=sample([j for j in range(len(self.hand)) if j != i], 1)[0]): elif len(green_cards) > 0:
return for c in green_cards:
break
elif any([not isinstance(c, cs.Mancato) and c.usable_next_turn and c.can_be_used_now for c in self.equipment if not self.game.check_event(ce.Lazo)]):
print('hmm', [not isinstance(c, cs.Mancato) and c.usable_next_turn and c.can_be_used_now for c in self.equipment])
for i in range(len(self.equipment)):
c = self.equipment[i]
if not isinstance(c, cs.Mancato) and c.usable_next_turn and c.can_be_used_now: if not isinstance(c, cs.Mancato) and c.usable_next_turn and c.can_be_used_now:
if not c.need_target: if not c.need_target:
if self.play_card(len(self.hand)+i): if self.play_card(len(self.hand)+self.equipment.index(c)):
return return
else: else:
_range = self.get_sight() if c.name == "Pepperbox" else c.range _range = self.get_sight() if c.name == "Pepperbox" else c.range
@ -269,7 +264,7 @@ class Player:
target = others[randrange(0, len(others))] target = others[randrange(0, len(others))]
if target['is_sheriff'] and isinstance(self.role, r.Renegade): if target['is_sheriff'] and isinstance(self.role, r.Renegade):
target = others[randrange(0, len(others))] target = others[randrange(0, len(others))]
if self.play_card(len(self.hand)+i, against=target['name']): if self.play_card(len(self.hand)+self.equipment.index(c), against=target['name']):
return return
break break
maxcards = self.lives if not isinstance(self.character, chd.SeanMallory) else 10 maxcards = self.lives if not isinstance(self.character, chd.SeanMallory) else 10