示例#1
0
 def apply_peddler_effect(self, player: Player) -> None:
     """Apply the effect of a peddler (neutral or player) building."""
     """
     Buy 1 cube (any resource but gold) from the stock with 1 denier.
     """
     # Remark: Hard-coded! We don't use the tags <cost><n_deniers>-1 and <gain><CHOICES>... in <game_elements><buildings><player_buildings><player_building><secondary_effect>.
     money_resource_cost, qty_cost = Money.money, -1  # type: MoneyResource, int
     if player.current_money_resources[money_resource_cost] + \
             qty_cost < 0:  # Has the player enough money or resource?
         print(indent(4) + player.txt_name_money_resources_workers_PPs_deck(True, True, False, False, False) +
               ' and can\'t apply the effect because he/she doesn\'t have enough money or resource as ' +
               str(qty_cost) + ' ' + money_resource_cost.name + '(s) required.')
     else:
         resource_gain_choices, qty_gain = [resource for resource in Resource.resources.values()
                                            if not resource.is_wild()], \
                                           +1  # type: List[Resource], int
         resource_gain = player.choose_buy_resource(money_resource_cost, qty_cost, resource_gain_choices,
                                                    qty_gain)  # type: Resource
         if resource_gain is None:
             print(indent(4) + player.txt_name_money_resources_workers_PPs_deck(True, True, False, False, False) +
                   ' and had chosen to don\'t apply the effect.')
         else:
             print(indent(4) + player.name() + ' wants to consume ' + str(qty_cost) + ' ' +
                   money_resource_cost.name + '(s) to obtain ' + str(qty_gain) + ' ' + resource_gain.name + '(s).')
             player.current_money_resources[money_resource_cost] += qty_cost
             player.current_money_resources[resource_gain] += qty_gain
             print(indent(4) + player.txt_name_money_resources_workers_PPs_deck(True, True, False, False, False) +
                   ' once the effect applied.')
示例#2
0
 def choose_buy_resource_multi(self, costs, resource_gain_choices,
                               qty_gain: int):  # -> List[Resource]
     # Remark: we only consider the case that costs is a List[Tuple[Money,int]] without resource and of length 2 or more.
     possibilities = list(
         Building.ABBREV_NO_USE_EFFECT)  # type: List[str[1..qty_gain]]
     abbrev_resource_name_resource = {
         resource.get_name_abbreviation(): resource
         for resource in resource_gain_choices
     }  # type: Dict[str[1], Resource] # E.g. {'F': food, ...}.
     possibilities.extend([
         ''.join(resource_gain.get_name_abbreviation()
                 for resource_gain in list(resource_gain_choice))
         for n_parts in range(1, qty_gain + 1)
         for resource_gain_choice in itertools.
         combinations_with_replacement(resource_gain_choices, n_parts)
     ])
     print(
         indent(4) + self.txt_name_money_resources_workers_PPs_deck(
             True, True, False, False, False) + '.')
     response = input(
         indent(4) + 'Do you want to consume either ' + ' or '.join(
             str(qty_cost) + ' ' + money_resource_cost.name + '(s) for ' +
             str(1 + i_costs) + ' resource(s)'
             for i_costs, (money_resource_cost,
                           qty_cost) in enumerate(costs)) + ' ' +
         Building.TXT_NO_USE_EFFECT + '? [' + '/'.join(possibilities) +
         '] ')  # type: str
     response = self.check_response_in_possibilities(
         response, possibilities, 5)
     choose_buy_resource_multi = list()
     if response != Building.ABBREV_NO_USE_EFFECT:
         for abbrev_resource_name in response:
             choose_buy_resource_multi.append(
                 abbrev_resource_name_resource[abbrev_resource_name])
     return choose_buy_resource_multi
示例#3
0
 def print_buildings_by_location(self, n_indent: int) -> None:
     """Display the player buildings of the player that is the location of the buildings in the deck: in the pile, the hand and the discard (but neither along the road nor replaced) ."""
     print(
         indent(n_indent) + self.name() + ', location of your buildings: ')
     for location in Location:
         player_building_names_by_location = sorted([
             player_building.name for player_building in
             self.get_player_buildings_by_location(location)
         ])  # type: List[PlayerBuilding]
         if player_building_names_by_location:
             print(
                 indent(n_indent + 1) + location.name.lower() + ': ' +
                 TXT_SEPARATOR.join(player_building_names_by_location) +
                 '.')
示例#4
0
 def apply_primary_effect(self, player: Player) -> None:
     """Apply the (default) primary effect of a player building."""
     print(
         indent(3) + 'Primary effect of the player building ' +
         self.txt_name_owner(True) + ' for a worker of the player ' +
         player.name() + ': ' + self.primary_effect.text)
     pass  # Nothing to do!
示例#5
0
 def apply_no_cost_only_gain_effect(self, money_resources_gain, player: Player = None) -> None:
     """Apply the effect of a building for (the worker of) the player. This effect doesn't require any cost and give some gain; so, we don't ask it hte player want it and give him."""
     if player is None:
         player = self.color_player.player
     money_resource, qty = money_resources_gain  # type: Tuple[MoneyResource, int]
     player.current_money_resources[money_resource] += qty
     print(indent(4) + player.txt_name_money_resources_workers_PPs_deck(True, True, False, False, False) + '.')
示例#6
0
 def choose_n_batches_to_castle(self, n_max_batches_to_castle: int) -> int:
     response = input(
         indent(3) +
         'How many batches do you want to offer to the castle? [0..' +
         str(n_max_batches_to_castle) + '] ')  # type: str
     return self.check_response_in_interval(response, 0,
                                            n_max_batches_to_castle, 4)
示例#7
0
 def apply_primary_effect(self, player: Player) -> None:
     """Apply the effect of a peddler neutral building."""
     """
     Buy 1 cube (any resource but gold) from the stock with 1 denier.
     """
     # Remark: Hard-coded! We don't use the tags <cost><n_deniers>-1 and <gain><CHOICES>... in <game_elements><buildings><neutral_buildings><neutral_building>.
     print(indent(3) + 'Effect of the neutral building ' + self.name +
           ' for a worker of the player ' + player.name() + ': ' + self.primary_effect.text)
     self.apply_peddler_effect(player)
示例#8
0
 def apply_secondary_effect(self) -> None:
     """Apply the secondary effect of this small production player building."""
     super().apply_secondary_effect()
     if self.current_n_cubes_into_area == 0:
         print(
             indent(4) +
             'There is no cube left in this small production player building, the owner gets nothing.'
         )
     else:
         self.current_n_cubes_into_area -= 1
         print(
             indent(4) + 'There is now ' +
             str(self.current_n_cubes_into_area) +
             ' cube(s) into the area of this small production player building.'
         )
         self.apply_no_cost_only_gain_effect(
             self.secondary_effect.money_resources_gain,
             self.color_player.player)
示例#9
0
 def apply_secondary_effect(self) -> None:
     """Apply the secondary effect of a bank player building."""
     """
     Buy 1 gold from the stock with 2 deniers.
     """
     # Remark: Hard-coded! We don't use the tags <cost><n_deniers>-2 and <gain><n_gold_cubes>+1 in <game_elements><buildings><player_buildings><player_building><secondary_effect>.
     super().apply_secondary_effect()
     money_resource_cost, qty_cost = Money.money, -2  # type: Money, int
     player = self.color_player.player  # type: Player
     if player.current_money_resources[money_resource_cost] + \
             qty_cost < 0:  # Has the player enough money or resource?
         print(
             indent(4) + player.txt_name_money_resources_workers_PPs_deck(
                 True, True, False, False, False) +
             ' and can\'t apply the effect because he/she doesn\'t have enough money or resource as '
             + str(qty_cost) + ' ' + money_resource_cost.name +
             '(s) required.')
     else:
         resource_gain_choices, qty_gain = [
             Resource.get_wild_resource()
         ], +1  # type: List[Resource], int
         resource_gain = player.choose_buy_resource(
             money_resource_cost, qty_cost, resource_gain_choices,
             qty_gain)  # type: Resource
         if resource_gain is None:
             print(
                 indent(4) +
                 player.txt_name_money_resources_workers_PPs_deck(
                     True, True, False, False, False) +
                 ' and had chosen to don\'t apply the effect.')
         else:
             print(
                 indent(4) + player.name() + ' wants to consume ' +
                 str(qty_cost) + ' ' + money_resource_cost.name +
                 '(s) to obtain ' + str(qty_gain) + ' ' +
                 resource_gain.name + '(s).')
             player.current_money_resources[money_resource_cost] += qty_cost
             player.current_money_resources[resource_gain] += qty_gain
             print(
                 indent(4) +
                 player.txt_name_money_resources_workers_PPs_deck(
                     True, True, False, False, False) +
                 ' once the effect applied.')
示例#10
0
 def choose_n_provost_movement(self, n_min_provost_movements_player: int,
                               n_max_provost_movements_player: int) -> int:
     response = input(
         indent(3) + 'How long do you want to move the Provost? [' +
         str(n_min_provost_movements_player) + '..' +
         str(n_max_provost_movements_player) + '] ')  # type: str
     return self.check_response_in_interval(response,
                                            n_min_provost_movements_player,
                                            n_max_provost_movements_player,
                                            4)
示例#11
0
 def apply_secondary_effect(self) -> None:
     """Apply the secondary effect of a gold mine player building."""
     """
     Exchange 1 cube from your personal stock with 1 gold cube from the stock.
     """
     # Remark: Hard-coded! We don't use the tags <cost><CHOICES>... and <gain><n_gold_cubes>+1... in <game_elements><buildings><player_buildings><player_building><secondary_effect>.
     super().apply_secondary_effect()
     money_resource_cost, qty_cost = None, -1  # type: Resource, int # None for any resource but we eliminate wild (to avoid the case to exchange 1 wild with 1 wild!).
     money_resource_gain, qty_gain = Resource.get_wild_resource(
     ), +1  # type: Resource, int
     player = self.color_player.player  # type: Player
     money_resource_cost_choices = [
         money_resource
         for money_resource, qty in player.current_money_resources.items()
         if money_resource != Money.money and not money_resource.is_wild()
         and qty + qty_cost >= 0
     ]  # type: List[Resource] # All suffisant available resources excepted wild.
     if not money_resource_cost_choices:
         print(
             indent(4) + player.txt_name_money_resources_workers_PPs_deck(
                 True, True, False, False, False) +
             ' and can\'t apply the effect because he/she doesn\'t have resource (wild is not considered) as '
             + str(qty_cost) + ' required.')
     else:
         # The player can have or not the choice of the resource.
         if len(money_resource_cost_choices) == 1:
             money_resource_cost = money_resource_cost_choices[0]
             print(
                 indent(4) + player.name() + 'can only exchange resource ' +
                 money_resource_cost.name + ', and it is done.')
         else:
             money_resource_cost = player.choose_exchange_resource(
                 False, qty_cost, money_resource_cost_choices,
                 money_resource_gain, qty_gain)
         # We apply the exchange.
         player.current_money_resources[money_resource_cost] += qty_cost
         player.current_money_resources[money_resource_gain] += qty_gain
         print(
             indent(4) + player.txt_name_money_resources_workers_PPs_deck(
                 True, True, False, False, False) + '.')
示例#12
0
 def apply_primary_effect(self, player: Player) -> None:
     """Apply the primary effect of a market player building."""
     """
     Exchange 1 cube from your personal stock with 4 deniers.
     """
     # Remark: Hard-coded! We don't use the tags <cost><CHOICES>... and <gain><n_deniers>+4... in <game_elements><buildings><player_buildings><player_building><primary_effect>.
     super().apply_primary_effect(player)
     money_resource_cost, qty_cost = None, -1  # type: Resource, int # None for any resource (including wild).
     money_resource_gain, qty_gain = Money.money, +4  # type: Money, int
     money_resource_cost_choices = [
         money_resource
         for money_resource, qty in player.current_money_resources.items()
         if money_resource != Money.money and qty + qty_cost >= 0
     ]  # type: List[Resource] # All suffisant available resources.
     if not money_resource_cost_choices:
         print(
             indent(4) + player.txt_name_money_resources_workers_PPs_deck(
                 True, True, False, False, False) +
             ' and can\'t apply the effect because he/she doesn\'t have resource as '
             + str(qty_cost) + ' required.')
     else:
         # The player do not have to use the effect; otherwie, the exchange is applied.
         money_resource_cost = player.choose_exchange_resource(
             True, qty_cost, money_resource_cost_choices,
             money_resource_gain, qty_gain)
         # We apply the exchange if the player wants to do it.
         if money_resource_cost is None:
             print(
                 indent(4) +
                 player.txt_name_money_resources_workers_PPs_deck(
                     True, True, False, False, False) +
                 ' and didn\'t use the effect.')
         else:
             player.current_money_resources[money_resource_cost] += qty_cost
             player.current_money_resources[money_resource_gain] += qty_gain
             print(
                 indent(4) +
                 player.txt_name_money_resources_workers_PPs_deck(
                     True, True, False, False, False) + '.')
示例#13
0
 def apply_effect_multi(self, player: Player, all_costs, resource_gain_choices, single_qty_gain: int) -> None:
     """Apply an effect with several choices (e.g. primary effects of bank and peddler player buildings)."""
     # :param all_costs:  # type: List[Tuple[Money, int]] # Must be ordered!
     # :param resource_gain_choices: # type: List[Resource]
     costs = [(money_resource_cost, qty_cost) for (money_resource_cost, qty_cost) in all_costs
              if player.current_money_resources[money_resource_cost] + qty_cost >= 0]
     if not costs:  # Has the player enough money or resource?
         print(indent(4) + player.txt_name_money_resources_workers_PPs_deck(True, True, False, False, False) +
               ' and can\'t apply the effect because he/she doesn\'t have enough money or resource as ' +
               'either ' + ' or '.join(str(qty_cost) + ' ' + money_resource_cost.name + '(s)'
                                       for (money_resource_cost, qty_cost) in all_costs) + ' required.')
     elif len(costs) == 1:
         print(indent(4) + 'There exists only one choice according to money and resources you have.')
         money_resource_cost, qty_cost = costs[0]
         resource_gain = player.choose_buy_resource(money_resource_cost, qty_cost, resource_gain_choices,
                                                    single_qty_gain)  # type: Resource
         if resource_gain is None:
             print(indent(4) + player.txt_name_money_resources_workers_PPs_deck(True, True, False, False, False) +
                   ' and had chosen to don\'t apply the effect.')
         else:
             print(indent(4) + player.name() + ' wants to consume ' +
                   str(qty_cost) + ' ' + money_resource_cost.name + '(s) to obtain ' +
                   str(single_qty_gain) + ' ' + resource_gain.name + '(s).')
             player.current_money_resources[money_resource_cost] += qty_cost
             player.current_money_resources[resource_gain] += single_qty_gain
             print(indent(4) + player.txt_name_money_resources_workers_PPs_deck(True, True, False, False, False) +
                   ' once the effect applied.')
     else:
         resources_gain = player.choose_buy_resource_multi(costs, resource_gain_choices,
                                                           len(costs) * single_qty_gain)
         if not resources_gain:
             print(indent(4) + player.txt_name_money_resources_workers_PPs_deck(True, True, False, False, False) +
                   ' and had chosen to don\'t apply the effect.')
         else:
             money_resource_cost, qty_cost = costs[len(resources_gain) - 1]  # costs must be ordered!
             print(indent(4) + player.name() + ' wants to consume ' +
                   str(qty_cost) + ' ' + money_resource_cost.name + '(s).')
             player.current_money_resources[money_resource_cost] += qty_cost
             for resource_gain, qty_gain in collections.Counter(resources_gain).items():  # To group by resource.
                 print(indent(4) + player.name() + ' wants to obtain ' +
                       str(single_qty_gain * qty_gain) + ' ' + resource_gain.name + '(s).')
                 player.current_money_resources[resource_gain] += single_qty_gain * qty_gain
             print(indent(4) + player.txt_name_money_resources_workers_PPs_deck(True, True, False, False, False) +
                   ' once the effect applied.')
示例#14
0
 def check_response_in_interval(self, response: str, n_min: int, n_max: int,
                                n_indent: int) -> int:
     """Check that a (string) response is in an interval (of numeric values)."""
     is_response_ok = False  # type: bool
     while not is_response_ok:
         try:
             response_ok = int(response)  # type: int
             is_response_ok = n_min <= response_ok <= n_max  # Is in the interval?
         except ValueError:
             is_response_ok = False  # Not a numeric.
         if not is_response_ok:
             response = input(indent(n_indent) + 'Please: ')
     return response_ok
示例#15
0
 def choose_buy_castle_multi(self, costs,
                             castle_gain_choices):  # -> List[Castle]
     n_min_castle_gain = 0  # type: int
     n_max_castle_gain = len(castle_gain_choices)  # type: int
     response = input(
         indent(4) + 'How many tokens of parts of the castle among [' +
         ', '.join(castle.name for castle in castle_gain_choices) +
         '] do you want to buy with: ' + ' or '.join(
             str(qty_cost) + ' ' + money_resource_cost.name + '(s)'
             for (money_resource_cost, qty_cost) in costs) + '? [' +
         str(n_min_castle_gain) + '..' + str(n_max_castle_gain) +
         '] ')  # type: str
     return castle_gain_choices[:self.check_response_in_interval(
         response, n_min_castle_gain, n_max_castle_gain, 5)]
示例#16
0
 def choose_buy_resource(self, money_resource_cost: MoneyResource,
                         qty_cost: int, resource_gain_choices,
                         qty_gain: int) -> Resource:
     possibilities = list(
         Building.ABBREV_NO_USE_EFFECT)  # type: List[str[1]]
     abbrev_resource_name_resource = {
     }  # type: Dict[str[1], Resource] # E.g. {'F': food, ...}.
     for resource in resource_gain_choices:
         abbrev_resource_name = resource.get_name_abbreviation()
         abbrev_resource_name_resource[abbrev_resource_name] = resource
         possibilities.append(abbrev_resource_name)
     print(
         indent(4) + self.txt_name_money_resources_workers_PPs_deck(
             True, True, False, False, False) + '.')
     response = input(
         indent(4) + 'Do you want to consume ' + str(qty_cost) + ' ' +
         money_resource_cost.name + '(s) to obtain ' + str(qty_gain) +
         ' resource ' + Building.TXT_NO_USE_EFFECT + '? [' +
         '/'.join(possibilities) + '] ')  # type: str
     response = self.check_response_in_possibilities(
         response, possibilities, 5)
     return None if response == Building.ABBREV_NO_USE_EFFECT else abbrev_resource_name_resource[
         response]
示例#17
0
 def choose_action(self, possible_actions):
     self.print_buildings_by_location(3)
     n_possible_actions = len(
         possible_actions
     )  # type: int # >= 1 because it must contain the passing action.
     if n_possible_actions == 1:
         print(
             indent(3) +
             'You don\'t have any choice and you have to do the action: ' +
             possible_actions[0][1])
         return possible_actions[0]
     else:
         print(indent(3) + 'Here are all the possible action(s):')
         for i_possible_actions, possible_action in enumerate(
                 possible_actions):
             print(
                 indent(4) + str(i_possible_actions) + ': ' +
                 possible_action[1])
         response = input(
             indent(3) + 'Which action do you choose? [0..' +
             str(n_possible_actions - 1) + '] ')  # type: str
         return possible_actions[self.check_response_in_interval(
             response, 0, n_possible_actions - 1, 4)]
示例#18
0
 def choose_exchange_resource(self, can_no_use_effect: bool, qty_cost: int,
                              resource_cost_choices,
                              money_resource_gain: MoneyResource,
                              qty_gain: int) -> Resource:
     abbrev_resource_name_resources = Resource.get_name_abbreviation_resources(
         resource_cost_choices)
     possibilities = list()  # type: List[str[1]]
     if can_no_use_effect:
         possibilities.append(Building.ABBREV_NO_USE_EFFECT)
     possibilities += list(abbrev_resource_name_resources.keys())
     print(
         indent(4) + self.txt_name_money_resources_workers_PPs_deck(
             True, True, False, False, False) + '.')
     response = input(
         indent(4) + 'Do you want to exchange ' + str(qty_cost) +
         ' of some resource with ' + str(qty_gain) + ' ' +
         money_resource_gain.name +
         (' or not use the effect ' +
          Building.TXT_NO_USE_EFFECT if can_no_use_effect else '') + '? [' +
         '/'.join(possibilities) + '] ')  # type: str
     response = self.check_response_in_possibilities(
         response, possibilities, 5)
     return None if response == Building.ABBREV_NO_USE_EFFECT else abbrev_resource_name_resources[
         response]
示例#19
0
 def choose_construct_residence(
         self, resource_costs,
         i_road_buildings_on_road):  # -> Optional[Tuple[int, Building]]
     n_min_i_building = 0  # type: int
     n_max_i_building = len(i_road_buildings_on_road)  # type: int
     response = input(
         indent(4) + 'Which of your ' + str(n_max_i_building) +
         ' building(s) [' + ', '.join(
             building_on_road.name
             for (i_road, building_on_road) in i_road_buildings_on_road) +
         '] do you want to choose (or ' + str(n_min_i_building) +
         ' if you don\'t want to use the effect)? [' +
         str(n_min_i_building) + '..' + str(n_max_i_building) +
         '] ')  # type: str
     response = self.check_response_in_interval(response, n_min_i_building,
                                                n_max_i_building,
                                                5)  # type: int
     return None if response == n_min_i_building else i_road_buildings_on_road[
         response - 1]
示例#20
0
 def apply_effect_buy_castle_multi(self, player: Player, all_costs) -> None:
     """Apply the primary or secondary effect of a church player building that is buy Castle tokens with deniers."""
     remaining_n_castle_tokens = Building.game_element.game.get_remaining_n_castle_tokens(
     )  # type: int
     if remaining_n_castle_tokens == 0:
         print(
             indent(4) +
             'The effect can\'t be applied because there are not tokens anymore in the castle.'
         )
     else:
         # Display the tokens in the castle.
         print(
             indent(4) + 'The tokens in the castle are: ' +
             TXT_SEPARATOR.join(
                 str(castle.current_n_castle_tokens) + ' of ' +
                 str(castle.n_prestige_pts) + ' prestige point(s) (' +
                 castle.name + ')'
                 for castle in Building.game_element.castle
                 if castle.current_n_castle_tokens > 0) + '.')
         # Prepare costs and gains.
         castle_gain_choices = [
             castle for castle in Building.game_element.castle
             for _counter in range(castle.current_n_castle_tokens)
         ]  # type: List[Castle]
         single_qty_gain = +1  # type: int # Unused. # Must be equals to one!
         costs = [(money_resource_cost, qty_cost)
                  for (money_resource_cost, qty_cost) in all_costs
                  if player.current_money_resources[money_resource_cost] +
                  qty_cost >= 0]
         n_choices = min(len(costs), len(castle_gain_choices))  # type: int
         costs = costs[:n_choices]
         castle_gain_choices = castle_gain_choices[:n_choices]
         # Has the player enough money or resource?
         if n_choices == 0:
             print(
                 indent(4) +
                 player.txt_name_money_resources_workers_PPs_deck(
                     True, False, False, True, False) +
                 ' and can\'t apply the effect because he/she doesn\'t have enough money or resource as '
                 + 'either ' + ' or '.join(
                     str(qty_cost) + ' ' + money_resource_cost.name + '(s)'
                     for (money_resource_cost, qty_cost) in all_costs) +
                 ' required.')
         else:
             castles_gain = player.choose_buy_castle_multi(
                 costs, castle_gain_choices)
             if not castles_gain:
                 print(
                     indent(4) +
                     player.txt_name_money_resources_workers_PPs_deck(
                         True, False, False, True, False) +
                     ' and had chosen to don\'t apply the effect.')
             else:
                 n_castles_gain = len(castles_gain)  # type: int
                 money_resource_cost, qty_cost = costs[
                     n_castles_gain -
                     1]  # type: List[MoneyResource], int # costs must be ordered!
                 print(
                     indent(4) + player.name() + ' wants to consume ' +
                     str(qty_cost) + ' ' + money_resource_cost.name +
                     '(s).')
                 player.current_money_resources[
                     money_resource_cost] += qty_cost
                 for castle_gain, qty_gain in collections.Counter(
                         castles_gain).items():  # To group by castle part.
                     print(
                         indent(4) + player.name() + ' wants to obtain ' +
                         str(qty_gain) + ' ' + castle_gain.name +
                         '(s) each giving ' +
                         str(castle_gain.n_prestige_pts) +
                         ' prestige point(s).')
                     player.current_n_prestige_pts += castle_gain.n_prestige_pts * qty_gain
                     castle_gain.current_n_castle_tokens -= qty_gain
                 print(
                     indent(4) +
                     player.txt_name_money_resources_workers_PPs_deck(
                         True, False, False, True, False) +
                     ' once the effect applied.')
示例#21
0
 def income_effect(self, income_phase: Phase = None) -> None:
     """Give some money to the player owing this hotel prestige building on the road."""
     n_deniers = income_phase.n_deniers_if_hotel  # type: int
     print(indent(2) + self.color_player.player.name() + ' obtains ' + str(n_deniers) + ' ' + Money.money.name +
           '(s) for a(n) ' + self.name + ' building along the road.')
     self.color_player.player.current_money_resources[Money.money] += n_deniers
示例#22
0
 def apply_primary_effect(self, player: Player) -> None:
     """Apply the primary effect of a lawyer player building."""
     """
     Construct a residential building by paying 1 food cube and turning over one of your cards along the road (except a Lawyer).
     """
     # Remark: Hard-coded! We don't use the tags <cost><n_food_cubes>-1 and <gain><n_residence_to_construct>+1 AND algorithm... in <game_elements><buildings><player_buildings><player_building><primary_effect>.
     super().apply_primary_effect(player)
     print(
         indent(4) + 'The road consists in: ' +
         self.game_element.game.txt_road(False) + '.')
     resource_cost, qty_cost = Resource.get_resource(
         'food'), -1  # type: Resource, int
     if player.current_money_resources[resource_cost] + \
             player.current_money_resources[Resource.get_wild_resource()] + qty_cost < 0:
         print(
             indent(4) + player.txt_name_money_resources_workers_PPs_deck(
                 True, True, False, False, False) +
             ' and can\'t apply the effect because he/she doesn\'t have enough resource as '
             + str(qty_cost) + ' ' + resource_cost.name +
             '(s) required (even by considering wild resource).')
     else:
         i_road_buildings_on_road = [
             (i_road, building_worker[0])
             for (i_road,
                  building_worker) in enumerate(self.game_element.game.road)
             if building_worker[0].get_building_type() == BuildingType.
             PLAYER and building_worker[0].color_player.player == player
             and building_worker[0].can_be_a_residential_building
         ]  # type: List[Tuple[PlayerBuilding]]
         if not i_road_buildings_on_road:
             print(
                 indent(4) +
                 player.txt_name_money_resources_workers_PPs_deck(
                     True, True, False, False, False) +
                 ' and can\'t apply the effect because he/she has no building to be constructed as a residential building along the road.'
             )
         else:
             resource_costs = None  # type: List[Tuple[Resource, int]]
             qty_current_resource_cost = player.current_money_resources[
                 resource_cost]
             if qty_current_resource_cost == 0:
                 resource_costs = [(Resource.get_wild_resource(), qty_cost)]
             elif qty_current_resource_cost >= abs(qty_cost):
                 resource_costs = [(resource_cost, qty_cost)]
             else:
                 resource_costs = [(resource_cost,
                                    -qty_current_resource_cost),
                                   (Resource.get_wild_resource(),
                                    qty_cost + qty_current_resource_cost)]
             i_road_building_to_construct_as_residence = player.choose_construct_residence(
                 resource_costs, i_road_buildings_on_road)
             if i_road_building_to_construct_as_residence is None:
                 print(
                     indent(4) +
                     player.txt_name_money_resources_workers_PPs_deck(
                         True, True, False, False, False) +
                     ' and had chosen to don\'t apply the effect.')
             else:
                 i_road = i_road_building_to_construct_as_residence[
                     0]  # type: int
                 building_to_construct_as_residence = i_road_building_to_construct_as_residence[
                     1]  # type: PlayerBuilding
                 print(
                     indent(4) + player.name() + ' wants to consume ' +
                     ' and '.join(
                         str(qty_cost) + ' ' + resource_cost.name + '(s)'
                         for (resource_cost, qty_cost) in resource_costs) +
                     ' to construct his/her ' +
                     i_road_building_to_construct_as_residence[1].name +
                     ' building (the ' + ordinal_number(i_road + 1) +
                     ' building along the road) as a residential building.')
                 for (resource_cost, qty_cost) in resource_costs:
                     player.current_money_resources[
                         resource_cost] += qty_cost
                 if self.game_element.game.road[i_road][1] is not None:
                     # Remark: building_to_construct_as_residence is equals to self.game_element.game.road[i_road][0].
                     self.game_element.game.road[i_road].append(
                         building_to_construct_as_residence)
                 self.game_element.game.road[i_road][
                     0] = player.get_residence_building()
                 player.deck[
                     building_to_construct_as_residence] = Location.REPLACED
                 print(
                     indent(4) + 'The road consists in: ' +
                     self.game_element.game.txt_road(False) + '.')
                 print(
                     indent(4) +
                     player.txt_name_money_resources_workers_PPs_deck(
                         True, True, False, False, False) +
                     ' once the effect applied.')
示例#23
0
 def check_response_in_possibilities(self, response: str, possibilities,
                                     n_indent: int) -> str:
     """Check that a (string) response is in a list of (str[1..2]) possibilities."""
     while len(response) == 0 or response.upper() not in possibilities:
         response = input(indent(n_indent) + 'Please: ')
     return response.upper()
示例#24
0
 def apply_secondary_effect(self) -> None:
     """Apply the (default) secondary effect of a player building."""
     print(
         indent(3) + 'Secondary effect of the player building ' +
         self.txt_name_owner(True) + ': ' + self.secondary_effect.text)
     pass  # Nothing to do!
示例#25
0
 def apply_primary_effect(self, player: Player) -> None:
     """Apply the (default that is for park, forest, quarry and trading post) effect of a neutral building."""
     print(indent(3) + 'Effect of the neutral building ' + self.name +
           ' for a worker of the player ' + player.name() + ': ' + self.primary_effect.text)
     self.apply_no_cost_only_gain_effect(self.primary_effect.money_resources_gain, player)