def checking_if_player_changed_settings(self, player_option): if player_option != "skip": settings.translate_slow_print("input_error") else: self.movement_string_compilation() return
def main(self): self.game_presetting() self.game_loop() # ending game settings.translate_slow_print("game_ended") return self.results()
def player_has_no_moves(self): if not self.current_player.undeployed: settings.translate_slow_print("rolled_st", (self.dice.dice_roll, ), no_record=self.rules["no_record"]) settings.translate_slow_print("no_moves") self.current_player.inactive_turns += 1 return
def choosing_rule(rule_mess="", rule_ans_1="", rule_ans_2=""): while True: player_option = settings.base_options(rule_mess) if player_option == settings.translation(rule_ans_1): return True elif player_option == settings.translation(rule_ans_2): return False elif player_option != "skip": settings.translate_slow_print("input_error")
def figure_deploying(self): self.current_fig.tile = self.current_fig.start settings.translate_slow_print( "deploying_figure", (self.current_fig.number, self.current_fig.start.position), no_record=self.rules["no_record"]) if not self.current_player.has_deployed: self.current_player.has_deployed = True return self.figure_kicking()
def figure_repositioning(self): self.current_fig.tile = self.finding_figures_new_coordinates( self.current_fig.tile.position, self.current_fig.tile.finishing) settings.translate_slow_print( "figure_moved", (self.current_fig.number, self.current_fig.tile.position), no_record=self.rules["no_record"]) if self.current_fig.tile.finish: settings.translate_slow_print("figure_at_home", no_record=self.rules["no_record"]) return self.figure_kicking()
def game_presetting(self): if not self.repeating: self.getting_variables_from_preparation() self.setting_variables_from_preparation() settings.translate_slow_print("character_means_home", (self.finish_marking_character, ), no_record=self.rules["no_record"]) self.presetting_players_and_figures() return
def player_choosing_move(self): settings.translate_slow_print("rolled_st", (self.dice.dice_roll, )) player_option = settings.base_options( self.compiling_movement_message(), translate=False) for figure in self.current_player.figures: if player_option == str(figure.number) and figure.movable: self.current_fig = figure return self.choosing_how_should_figure_move() self.checking_if_player_changed_settings(player_option)
def choosing_human_or_ai(self): for player in self.players: while player.playing: player_option = settings.base_options("player_ai_or_real", (player.number, )) if player_option == settings.translation("choosing_pl_ai_1"): player.ai = False break elif player_option == settings.translation("choosing_pl_ai_2"): player.ai = True break elif player_option != "skip": settings.translate_slow_print("input_error")
def choosing_int_value(player_option, minimal_value, maximal_value=float("inf")): try: int(player_option) except ValueError: if player_option != "skip": settings.translate_slow_print("input_error") else: if minimal_value <= int(player_option) <= maximal_value: return int(player_option) else: settings.translate_slow_print("input_error") return None
def figure_kicking(self): for player in self.players: if player.playing and player.color.name != self.current_player.color.name: for figure in player.figures: if figure.tile.position == self.current_fig.tile.position and \ figure.tile.color.name == self.current_fig.tile.color.name and \ figure.color.name != self.current_fig.color.name: figure.tile = figure.home settings.translate_slow_print( "figure_kicked", (figure.number, player.number, figure.color.translation), no_record=self.rules["no_record"]) player.own_figures_kicked += 1 self.current_player.others_figures_kicked += 1
def ai_setting(self): while True: player_option = settings.base_options("what_kind_of_players") if player_option == settings.translation("ai_setting_1"): for player in self.players: player.ai = False break elif player_option == settings.translation("ai_setting_2"): for player in self.players: player.ai = True # asking if player wants to have full record of the game or just the result self.rules["no_record"] = self.choosing_rule( "no_record", "no_record_1", "no_record_2") break elif player_option == settings.translation("ai_setting_3"): return choosing_human_or_ai() elif player_option != "skip": settings.translate_slow_print("input_error")
def rules_setting(self): while True: self.rules = { "no_rpt_whl_six": False, "rnd_tcs": True, "no_mv_whl_dp": False, "thr_rls_onl_first": True, "no_record": False } player_option = settings.base_options("rules_setting") if player_option == settings.translation("rules_setting_1"): # no repositioning if deploying is possible self.rules["no_mv_whl_dp"] = self.choosing_rule( "rules_no_mv_whl_dp", "rules_no_mv_whl_dp_1", "rules_no_mv_whl_dp_2") # random ai tactics self.rules["rnd_tcs"] = self.choosing_rule( "rules_rnd_tcs", "rules_rnd_tcs_1", "rules_rnd_tcs_2") # no repeating when six self.rules["no_rpt_whl_six"] = self.choosing_rule( "rules_no_rpt_whl_six", "rules_no_rpt_whl_six_1", "rules_no_rpt_whl_six_2") # three rolls only before first deployment self.rules["thr_rls_onl_first"] = self.choosing_rule( "thr_rls_onl_first", "thr_rls_onl_first_1", "thr_rls_onl_first_2") return # basic settings elif player_option == settings.translation("rules_setting_2"): return elif player_option != "skip": settings.translate_slow_print("input_error")
def player_rolling_two_more_times(self): settings.translate_slow_print("rolled_st_more_chances", (self.dice.dice_roll, ), no_record=self.rules["no_record"]) for j in range(0, 2): self.dice.dice_rolling(self.current_player) if self.dice.dice_roll >= self.dice.min_deploy_roll: settings.translate_slow_print( "rolled_st", (self.dice.dice_roll, ), no_record=self.rules["no_record"]) return self.deploying_first_figure_in_three_rolls() else: settings.translate_slow_print( "rolled_st", (self.dice.dice_roll, ), no_record=self.rules["no_record"]) return
def all_player_figures_home(self): # player can deploy instantly if self.dice.dice_roll >= self.dice.min_deploy_roll: settings.translate_slow_print("rolled_st", (self.dice.dice_roll, ), no_record=self.rules["no_record"]) # player has no more rolls in this turn thanks to rules elif self.rules[ "thr_rls_onl_first"] and self.current_player.has_deployed: settings.translate_slow_print("rolled_st", (self.dice.dice_roll, ), no_record=self.rules["no_record"]) settings.translate_slow_print("no_moves", no_record=self.rules["no_record"]) # player has two more rolls else: self.player_rolling_two_more_times()
def outputting_choosing_playing_player_message(self): print("========================================") settings.translate_slow_print("player_is_playing", (self.current_player.number, self.current_player.color.translation))
def player_has_all_figures_at_home(self, player): player.undeployed = True if not self.rules["no_record"]: settings.translate_slow_print( "player_no_figure", (player.number, player.color.translation))
def player_color_deciding(self): for num in range(0, self.max_number_of_players): # no need for player to choose color of last player if there is only one to choose from if num == len(self.players) and len(self.figures) == 1: self.players[-1].playing = True for figure in self.figures[0]: figure.start.position = len(self.players) - 1 self.players[-1].self.figures = self.figures[0] self.players[-1].color = self.figures[0][0].color break # finding if player must be chosen playing_pl = 0 for player in self.players: if player.playing: playing_pl += 1 must_choose = False if (num == self.max_number_of_players - 2 and playing_pl == 0) or \ (num == self.max_number_of_players - 1 and playing_pl == 1): must_choose = True # player choosing while True: # forming message for player trait_num = 0 possible_colors = "" for figs in self.figures: trait_num += 1 if trait_num != len(self.players) - playing_pl: possible_colors += "[{}]{}, ".format( figs[0].color.prefix, figs[0].color.suffix) else: possible_colors += settings.translation("or_?").format( figs[0].color.prefix, figs[0].color.suffix) if not must_choose: possible_colors += settings.translation( "this_player_not_playing") next_pl = False player_option = settings.base_options( "which_color_is_player", (num + 1, num * self.distance_between_starts + 1, possible_colors)) for figs in self.figures: if player_option == figs[0].color.prefix: self.players[num].playing = True for figure in figs: figure.start.position = num self.players[num].figures = figs self.players[num].color = figs[0].color self.figures.remove(figs) next_pl = True break elif player_option == "N" and not must_choose: self.players[num].playing = False next_pl = True break else: if player_option != "skip": settings.translate_slow_print("input_error") if next_pl: break