Example #1
0
 def suffer_damage(self, clearing: Clearing, hits: int, opponent: Player, is_attacker: bool) -> DamageResult:
     removed_pieces = []
     points_awarded = 0
     if hits:
         warriors = clearing.get_warriors_for_player(self)  # TODO: Mercenaries
         amount_of_warriors_removed = min(hits, len(warriors))
         hits -= amount_of_warriors_removed
         for i in range(amount_of_warriors_removed):
             removed_pieces.append(warriors[i])
             points_awarded += warriors[i].get_score_for_removal()
     if hits:
         tokens = clearing.get_tokens_for_player(self)
         random.shuffle(tokens)
         amount_of_tokens_removed = min(hits, len(tokens))
         hits -= amount_of_tokens_removed
         for i in range(amount_of_tokens_removed):
             removed_pieces.append(tokens[i])
             # If the Popularity trait is used, players can't score for sympathy if they already have since last turn
             if (not self.has_trait(TRAIT_POPULARITY) or
                     opponent not in self.players_who_have_removed_sympathy_since_last_turn):
                 points_awarded += tokens[i].get_score_for_removal()
             self.players_who_have_removed_sympathy_since_last_turn.add(opponent)
     if hits:
         buildings = clearing.get_buildings_for_player(self)
         random.shuffle(buildings)
         amount_of_buildings_removed = min(hits, len(buildings))
         hits -= amount_of_buildings_removed
         for i in range(amount_of_buildings_removed):
             removed_pieces.append(buildings[i])
             points_awarded += buildings[i].get_score_for_removal()
     clearing.remove_pieces(self, removed_pieces)
     return DamageResult(removed_pieces=removed_pieces, points_awarded=points_awarded)
 def suffer_damage(self, clearing: Clearing, hits: int, opponent: Player,
                   is_attacker: bool) -> DamageResult:
     removed_pieces = []
     points_awarded = 0
     if hits:
         warriors = clearing.get_warriors_for_player(
             self)  # TODO: Mercenaries
         amount_of_warriors_removed = min(hits, len(warriors))
         hits -= amount_of_warriors_removed
         for i in range(amount_of_warriors_removed):
             removed_pieces.append(warriors[i])
             points_awarded += warriors[i].get_score_for_removal()
     if hits:
         tokens = clearing.get_tokens_for_player(self)
         random.shuffle(tokens)
         amount_of_tokens_removed = min(hits, len(tokens))
         hits -= amount_of_tokens_removed
         for i in range(amount_of_tokens_removed):
             removed_pieces.append(tokens[i])
             points_awarded += tokens[i].get_score_for_removal()
     if hits:
         buildings = clearing.get_buildings_for_player(self)
         random.shuffle(buildings)
         if self.has_trait(TRAIT_FORTIFIED):
             amount_of_buildings_removed = min(hits // 2, len(buildings))
         else:
             amount_of_buildings_removed = min(hits, len(buildings))
         for i in range(amount_of_buildings_removed):
             removed_pieces.append(buildings[i])
             points_awarded += buildings[i].get_score_for_removal()
     clearing.remove_pieces(self, removed_pieces)
     if not is_attacker:
         # Hospitals only works as the defender
         self.apply_field_hospitals(removed_pieces)
     return DamageResult(removed_pieces=removed_pieces,
                         points_awarded=points_awarded)