def season_retire(self): # Decides if a player retired and if so, sets retired = True # Returns True if retired, False if not # & Run once per season age_norm = HelperMethods.normalize(self.age, PLAYER_GLOBALS["MIN_AGE"], PLAYER_GLOBALS["MAX_AGE"]) skill_norm = HelperMethods.normalize(self.skill, PLAYER_GLOBALS["MIN_SKILL"], PLAYER_GLOBALS["MAX_SKILL"]) if age_norm >= 1: self.retired = True return True elif age_norm >= 0.9: if random.random() >= 0.5: self.retired = True return True elif age_norm >= 0.8: if skill_norm <= 0.15: self.retired = True return True else: if random.random() >= 0.25: self.retired = True return True elif age_norm >= 0.7 and skill_norm <= 0.1: self.retired = True return True return False
def season_training_increase_per_turn(self): # Sets increase_per_turn -> how much a player trains per turn # Returns True if worked, False if not # & Run once per season if self.age >= PLAYER_GLOBALS["MIN_AGE"]: age_int = PLAYER_GLOBALS["AGE_TRAINING_INF"] inc_int = PLAYER_GLOBALS["TRAINING_PER_AGE"] age_norm = HelperMethods.normalize(self.age, PLAYER_GLOBALS["MIN_AGE"], PLAYER_GLOBALS["MAX_AGE"]) skill_norm = HelperMethods.normalize(self.skill, PLAYER_GLOBALS["MIN_SKILL"], PLAYER_GLOBALS["MAX_SKILL"]) skill_inf = 1 if skill_norm >= 0.85: skill_inf = 0.5 for index, age_range in enumerate(age_int): if age_norm < age_range: x1 = age_int[index] x2 = age_int[index - 1] y1 = inc_int[index] y2 = inc_int[index - 1] increase = HelperMethods.ysolver(point1=(x1, y1), point2=(x2, y2), x=age_norm) break self.increase_per_turn = (increase * skill_inf) / float( GAME_GLOBALS["TOTAL_TURNS"]) return True return False
def training(self): # Trains all players in team # & Run once per turn ground_norm = HelperMethods.normalize(5, TEAM_GLOBALS["MIN_TRAINING_GROUND"], TEAM_GLOBALS["MAX_TRAINING_GROUND"]) for player in self.players: skill_norm = HelperMethods.normalize(player.skill, PLAYER_GLOBALS["MIN_SKILL"], PLAYER_GLOBALS["MAX_SKILL"]) if ground_norm >= skill_norm: ground_inf = 1 else: ground_inf = min(max(1 - 3 * (skill_norm - ground_norm), 0), 1) player.turn_training(ground_inf)
def calc_price(self): apparent_skill = self.skill starting_values = PLAYER_GLOBALS["PRICE_AGE"] factors = PLAYER_GLOBALS["PRICE_SKILL"] power = [0, 0, 0, 0, 0, 0] age_norm = HelperMethods.normalize(self.age, PLAYER_GLOBALS["MIN_AGE"], PLAYER_GLOBALS["MAX_AGE"]) age_inf_price = int(age_norm * (len(starting_values) - 2)) point1 = (age_inf_price, starting_values[age_inf_price]) point2 = (age_inf_price + 1, starting_values[age_inf_price + 1]) start_value = Line.Line((point1, point2)).solve_for_y(age_norm * (len(starting_values) - 2)) get_lastpower = (apparent_skill - PLAYER_GLOBALS["MIN_SKILL"]) / 10 get_howmuchpower = (apparent_skill - PLAYER_GLOBALS["MIN_SKILL"]) % 10 for i in range(get_lastpower + 1): power[i] = 3 if i == get_lastpower: power[i] = get_howmuchpower / 3.0 price = start_value * pow(factors[0],power[0]) * pow(factors[1],power[1]) * pow(factors[2],power[2]) * pow(factors[3],power[3]) * pow(factors[4],power[4]) * 1000 if price / 100 >= 1: return int(price) - int(price) % 10 else: return int(price)
def calc_price(self): apparent_skill = self.skill starting_values = PLAYER_GLOBALS["PRICE_AGE"] factors = PLAYER_GLOBALS["PRICE_SKILL"] power = [0, 0, 0, 0, 0, 0] age_norm = HelperMethods.normalize(self.age, PLAYER_GLOBALS["MIN_AGE"], PLAYER_GLOBALS["MAX_AGE"]) age_inf_price = int(age_norm * (len(starting_values) - 2)) point1 = (age_inf_price, starting_values[age_inf_price]) point2 = (age_inf_price + 1, starting_values[age_inf_price + 1]) start_value = Line.Line( (point1, point2)).solve_for_y(age_norm * (len(starting_values) - 2)) get_lastpower = (apparent_skill - PLAYER_GLOBALS["MIN_SKILL"]) / 10 get_howmuchpower = (apparent_skill - PLAYER_GLOBALS["MIN_SKILL"]) % 10 for i in range(get_lastpower + 1): power[i] = 3 if i == get_lastpower: power[i] = get_howmuchpower / 3.0 price = start_value * pow(factors[0], power[0]) * pow( factors[1], power[1]) * pow(factors[2], power[2]) * pow( factors[3], power[3]) * pow(factors[4], power[4]) * 1000 if price / 100 >= 1: return int(price) - int(price) % 10 else: return int(price)
def minute(self): if self.minutes < MATCH_GLOBALS["TOTAL_TURNS"]: self.home.update_skill_tactic() self.away.update_skill_tactic() self.minutes += 1 self.events = {"Home Possession": False, "Goal": False} home_tactic_inf = [(self.home.tactic[0] - self.away.tactic[2]) * MATCH_GLOBALS["TACTIC_INFLUENCE"], (self.home.tactic[1] - self.away.tactic[1]) * MATCH_GLOBALS["TACTIC_INFLUENCE"], (self.home.tactic[2] - self.away.tactic[0]) * MATCH_GLOBALS["TACTIC_INFLUENCE"]] home_concedes_rat = (self.home.skill[0] - self.away.skill[2]) / float(PLAYER_GLOBALS["MAX_SKILL"]) + home_tactic_inf[0] home_possession_rat = (self.home.skill[1] - self.away.skill[1]) / float(PLAYER_GLOBALS["MAX_SKILL"]) + home_tactic_inf[1] home_scores_rat = (self.home.skill[2] - self.away.skill[0]) / float(PLAYER_GLOBALS["MAX_SKILL"]) + home_tactic_inf[2] home_scores_prob = Line.Line(((-1, MATCH_GLOBALS["MIN_GOAL_PER_POSS"]), (1, MATCH_GLOBALS["MAX_GOAL_PER_POSS"]))).solve_for_y(home_scores_rat) home_possession_prob = Line.Line(((-1, 1 - MATCH_GLOBALS["MAX_POSSESSION"]),(1, MATCH_GLOBALS["MAX_POSSESSION"]))).solve_for_y(home_possession_rat) home_concedes_prob = Line.Line(((-1, MATCH_GLOBALS["MAX_GOAL_PER_POSS"]), (1, MATCH_GLOBALS["MIN_GOAL_PER_POSS"]))).solve_for_y(home_concedes_rat) poss_rand = random.uniform(0, 1) goal_rand = random.uniform(0, 1) #ANTI GOLEADAS: if self.result[0] >= 3 + self.result[1]: home_scores_prob = home_scores_prob * MATCH_GLOBALS["ANTI_GOLEADAS"] elif self.result[1] >= 3 + self.result[0]: home_concedes_prob = home_concedes_prob * MATCH_GLOBALS["ANTI_GOLEADAS"] #PROBABILIDADE HUMANA DE MARCAR NO FINAL min_norm = HelperMethods.normalize(self.minutes, 0, MATCH_GLOBALS["TOTAL_TURNS"]) if min_norm <= 0.2: if self.away.manager.human: home_scores_prob = home_scores_prob * MATCH_GLOBALS["GOAL_BEGINNING_END_MULTI"] if self.home.manager.human: home_concedes_prob = home_concedes_prob * MATCH_GLOBALS["GOAL_BEGINNING_END_MULTI"] if min_norm >= 0.8: if self.home.manager.human: home_scores_prob = home_scores_prob * MATCH_GLOBALS["GOAL_BEGINNING_END_MULTI"] if self.away.manager.human: home_concedes_prob = home_concedes_prob * MATCH_GLOBALS["GOAL_BEGINNING_END_MULTI"] if poss_rand <= home_possession_prob: self.events["Home Possession"] = True self.possession[0] += 1 if goal_rand <= home_scores_prob: self.result[0] += 1 self.events["Goal"] = True self.set_goalscorer(True) else: self.events["Home Possession"] = False self.possession[1] += 1 if goal_rand <= home_concedes_prob: self.result[1] += 1 self.events["Goal"] = True self.set_goalscorer(False) return True else: return False
def season_training_increase_per_turn(self): # Sets increase_per_turn -> how much a player trains per turn # Returns True if worked, False if not # & Run once per season if self.age >= PLAYER_GLOBALS["MIN_AGE"]: age_int = PLAYER_GLOBALS["AGE_TRAINING_INF"] inc_int = PLAYER_GLOBALS["TRAINING_PER_AGE"] age_norm = HelperMethods.normalize(self.age, PLAYER_GLOBALS["MIN_AGE"], PLAYER_GLOBALS["MAX_AGE"]) skill_norm = HelperMethods.normalize(self.skill, PLAYER_GLOBALS["MIN_SKILL"], PLAYER_GLOBALS["MAX_SKILL"]) skill_inf = 1 if skill_norm >= 0.85: skill_inf = 0.5 for index, age_range in enumerate(age_int): if age_norm < age_range: x1 = age_int[index] x2 = age_int[index - 1] y1 = inc_int[index] y2 = inc_int[index - 1] increase = HelperMethods.ysolver(point1=(x1, y1), point2=(x2, y2), x = age_norm) break self.increase_per_turn = (increase * skill_inf) / float(GAME_GLOBALS["TOTAL_TURNS"]) return True return False
def create_skill(skill, avg_skill): # Returns int with player starting skill # TODO: Add age influence! # if avg_skill: # skill_variation = int(round(PLAYER_GLOBALS["MAX_SKILL"] * 0.02, 0)) # random_var = random.randint(-skill_variation, skill_variation) # skill += random_var skill_age_inf = PLAYER_GLOBALS["MAX_SKILL"] * 0.05 + skill * 0.2 age_inf = 1 - 2 * HelperMethods.normalize(age, PLAYER_GLOBALS["MIN_AGE"], PLAYER_GLOBALS["MAX_AGE"]) if age_inf > 0: skill -= skill_age_inf * age_inf skill = min(max(int(round(skill, 0)), PLAYER_GLOBALS["MIN_SKILL"]), PLAYER_GLOBALS["MAX_SKILL"]) return skill
def create_skill(skill, avg_skill): # Returns int with player starting skill # TODO: Add age influence! # if avg_skill: # skill_variation = int(round(PLAYER_GLOBALS["MAX_SKILL"] * 0.02, 0)) # random_var = random.randint(-skill_variation, skill_variation) # skill += random_var skill_age_inf = PLAYER_GLOBALS["MAX_SKILL"] * 0.05 + skill * 0.2 age_inf = 1 - 2 * HelperMethods.normalize( age, PLAYER_GLOBALS["MIN_AGE"], PLAYER_GLOBALS["MAX_AGE"]) if age_inf > 0: skill -= skill_age_inf * age_inf skill = min(max(int(round(skill, 0)), PLAYER_GLOBALS["MIN_SKILL"]), PLAYER_GLOBALS["MAX_SKILL"]) return skill
def minute(self): if self.minutes < MATCH_GLOBALS["TOTAL_TURNS"]: self.home.update_skill_tactic() self.away.update_skill_tactic() self.minutes += 1 self.events = {"Home Possession": False, "Goal": False} home_tactic_inf = [ (self.home.tactic[0] - self.away.tactic[2]) * MATCH_GLOBALS["TACTIC_INFLUENCE"], (self.home.tactic[1] - self.away.tactic[1]) * MATCH_GLOBALS["TACTIC_INFLUENCE"], (self.home.tactic[2] - self.away.tactic[0]) * MATCH_GLOBALS["TACTIC_INFLUENCE"], ] home_concedes_rat = (self.home.skill[0] - self.away.skill[2]) / float( PLAYER_GLOBALS["MAX_SKILL"] ) + home_tactic_inf[0] home_possession_rat = (self.home.skill[1] - self.away.skill[1]) / float( PLAYER_GLOBALS["MAX_SKILL"] ) + home_tactic_inf[1] home_scores_rat = (self.home.skill[2] - self.away.skill[0]) / float( PLAYER_GLOBALS["MAX_SKILL"] ) + home_tactic_inf[2] home_scores_prob = Line.Line( ((-1, MATCH_GLOBALS["MIN_GOAL_PER_POSS"]), (1, MATCH_GLOBALS["MAX_GOAL_PER_POSS"])) ).solve_for_y(home_scores_rat) home_possession_prob = Line.Line( ((-1, 1 - MATCH_GLOBALS["MAX_POSSESSION"]), (1, MATCH_GLOBALS["MAX_POSSESSION"])) ).solve_for_y(home_possession_rat) home_concedes_prob = Line.Line( ((-1, MATCH_GLOBALS["MAX_GOAL_PER_POSS"]), (1, MATCH_GLOBALS["MIN_GOAL_PER_POSS"])) ).solve_for_y(home_concedes_rat) poss_rand = random.uniform(0, 1) goal_rand = random.uniform(0, 1) # ANTI GOLEADAS: if self.result[0] >= 3 + self.result[1]: home_scores_prob = home_scores_prob * MATCH_GLOBALS["ANTI_GOLEADAS"] elif self.result[1] >= 3 + self.result[0]: home_concedes_prob = home_concedes_prob * MATCH_GLOBALS["ANTI_GOLEADAS"] # PROBABILIDADE HUMANA DE MARCAR NO FINAL min_norm = HelperMethods.normalize(self.minutes, 0, MATCH_GLOBALS["TOTAL_TURNS"]) if min_norm <= 0.2: if self.away.manager.human: home_scores_prob = home_scores_prob * MATCH_GLOBALS["GOAL_BEGINNING_END_MULTI"] if self.home.manager.human: home_concedes_prob = home_concedes_prob * MATCH_GLOBALS["GOAL_BEGINNING_END_MULTI"] if min_norm >= 0.8: if self.home.manager.human: home_scores_prob = home_scores_prob * MATCH_GLOBALS["GOAL_BEGINNING_END_MULTI"] if self.away.manager.human: home_concedes_prob = home_concedes_prob * MATCH_GLOBALS["GOAL_BEGINNING_END_MULTI"] if poss_rand <= home_possession_prob: self.events["Home Possession"] = True self.possession[0] += 1 if goal_rand <= home_scores_prob: self.result[0] += 1 self.events["Goal"] = True self.set_goalscorer(True) else: self.events["Home Possession"] = False self.possession[1] += 1 if goal_rand <= home_concedes_prob: self.result[1] += 1 self.events["Goal"] = True self.set_goalscorer(False) return True else: return False