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)
Example #2
0
 def get_warriors_to_move(self, origin_clearing: Clearing,
                          suit: Suit) -> list[Warrior]:
     own_rule_value = self.get_rule_value(origin_clearing)
     max_enemy_rule_value = self.get_max_enemy_rule_value_in_clearing(
         origin_clearing)
     warrior_count_to_move_and_keep_rule = own_rule_value - max_enemy_rule_value
     # Move the minimum between (most you can without losing rule) and (X - #cards in column)
     warrior_count_to_move = min(
         warrior_count_to_move_and_keep_rule,
         (origin_clearing.get_warrior_count_for_player(self) -
          self.decree.get_count_of_suited_cards_in_decree(suit)))
     return origin_clearing.get_warriors_for_player(
         self)[:warrior_count_to_move]
 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)