From e2eb77b1efd8bd0695398ac9cfae1619233b9d3c Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sat, 2 Jan 2021 05:42:14 -0500 Subject: [PATCH] fully implemented heavy snow and slight tailwind weathers. removed supernova from the pool --- games.py | 67 ++++++++++++++++++++++++++-------------------- main_controller.py | 13 +++++++++ the_prestige.py | 3 +++ 3 files changed, 54 insertions(+), 29 deletions(-) diff --git a/games.py b/games.py index f2b0368..b8dafb0 100644 --- a/games.py +++ b/games.py @@ -24,22 +24,13 @@ def config(): return json.load(config_file) def all_weathers(): - if not os.path.exists("weather_config.json"): - #generate default config - super_weather_json = jsonpickle.encode(weather("Supernova", "🌟")) - mid_weather_json = jsonpickle.encode(weather("Midnight", "🕶")) - config_dic = { - "Supernova" : super_weather_json, - "Midnight": mid_weather_json - } - with open("weather_config.json", "w") as config_file: - json.dump(config_dic, config_file, indent=4) - with open("weather_config.json") as config_file: - weather_dic = {} - for weather_json in json.load(config_file).values(): - this_weather = jsonpickle.decode(weather_json, classes=weather) - weather_dic[this_weather.name] = this_weather - return weather_dic + weathers_dic = { + #"Supernova" : weather("Supernova", "🌟"), + "Midnight": weather("Midnight", "🕶"), + "Slight Tailwind": weather("Slight Tailwind", "🏌️‍♀️"), + "Heavy Snow": weather("Heavy Snow", "❄") + } + return weathers_dic class appearance_outcomes(Enum): @@ -222,8 +213,13 @@ class game(object): def get_batter(self): if self.top_of_inning: bat_team = self.teams["away"] + counter = self.weather.counter_away else: bat_team = self.teams["home"] + counter = self.weather.counter_home + + if self.weather.name == "Heavy Snow" and counter == bat_team.lineup_position: + return bat_team.pitcher return bat_team.lineup[bat_team.lineup_position % len(bat_team.lineup)] def get_pitcher(self): @@ -484,14 +480,26 @@ class game(object): def batterup(self): scores_to_add = 0 result = self.at_bat() - self.get_batter() if self.top_of_inning: offense_team = self.teams["away"] + weather_count = self.weather.counter_away defense_team = self.teams["home"] else: offense_team = self.teams["home"] + weather_count = self.weather.counter_home defense_team = self.teams["away"] + if self.weather.name == "Slight Tailwind" and "mulligan" not in self.last_update[0].keys() and not result["ishit"] and result["text"] != appearance_outcomes.walk: + mulligan_roll_target = -((((self.get_batter().stlats["batting_stars"])-7)/7)**2)+1 + if random.random() > mulligan_roll_target: + result["mulligan"] = True + return (result, 0) + + if self.weather.name == "Heavy Snow" and weather_count == offense_team.lineup_position and "snow_atbat" not in self.last_update[0].keys(): + result["snow_atbat"] = True + result["text"] = f"{offense_team.lineup[offense_team.lineup_position % len(offense_team.lineup)].name}'s hands are too cold! {self.get_batter().name} is forced to bat!" + return (result, 0) + defenders = defense_team.lineup.copy() defenders.append(defense_team.pitcher) defender = random.choice(defenders) #pitcher can field outs now :3 @@ -581,12 +589,21 @@ class game(object): for base in self.bases.keys(): self.bases[base] = None self.outs = 0 + if self.top_of_inning and self.weather.name == "Heavy Snow" and self.weather.counter_away < self.teams["away"].lineup_position: + self.weather.counter_away = self.pitcher_insert(self.teams["away"]) + if not self.top_of_inning: + if self.weather.name == "Heavy Snow" and self.weather.counter_home < self.teams["home"].lineup_position: + self.weather.counter_home = self.pitcher_insert(self.teams["home"]) self.inning += 1 if self.inning > self.max_innings and self.teams["home"].score != self.teams["away"].score: #game over self.over = True self.top_of_inning = not self.top_of_inning + def pitcher_insert(self, this_team): + rounds = math.ceil(this_team.lineup_position / len(this_team.lineup)) + position = random.randint(0, len(this_team.lineup)-1) + return rounds * len(this_team.lineup) + position def end_of_game_report(self): return { @@ -629,19 +646,9 @@ class game(object): else: inningtext = "bottom" - updatestring = f"{self.last_update[0]['batter']} {self.last_update[0]['text'].value} {self.last_update[0]['defender']}{punc}\n" + updatestring = "this isn't used but i don't want to break anything" - if self.last_update[1] > 0: - updatestring += f"{self.last_update[1]} runs scored!" - - return f"""Last update: {updatestring} - - Score: {self.teams['away'].score} - {self.teams['home'].score}. - Current inning: {inningtext} of {self.inning}. {self.outs} outs. - Pitcher: {self.get_pitcher().name} - Batter: {self.get_batter().name} - Bases: 3: {str(self.bases[3])} 2: {str(self.bases[2])} 1: {str(self.bases[1])} - """ + return "this isn't used but i don't want to break anything" else: return f"""Game over! Final score: **{self.teams['away'].score} - {self.teams['home'].score}** Last update: {self.last_update[0]['batter']} {self.last_update[0]['text'].value} {self.last_update[0]['defender']}{punc}""" @@ -779,6 +786,8 @@ class weather(object): def __init__(self, new_name, new_emoji): self.name = new_name self.emoji = new_emoji + self.counter_away = 0 + self.counter_home = 0 def __str__(self): return f"{self.emoji} {self.name}" \ No newline at end of file diff --git a/main_controller.py b/main_controller.py index 01d35a5..3bf30f3 100644 --- a/main_controller.py +++ b/main_controller.py @@ -88,6 +88,19 @@ def update_loop(): state["update_emoji"] = "💎" state["update_text"] = updatestring + elif "mulligan" in this_game.last_update[0].keys(): + updatestring = "" + punc = "" + if this_game.last_update[0]["defender"] != "": + punc = ", " + + state["update_emoji"] = "🏌️‍♀️" + state["update_text"] = f"{this_game.last_update[0]['batter']} would have gone out, but they took a mulligan!" + + elif "snow_atbat" in this_game.last_update[0].keys(): + state["update_emoji"] = "❄" + state["update_text"] = this_game.last_update[0]["text"] + else: updatestring = "" punc = "" diff --git a/the_prestige.py b/the_prestige.py index 988bb8d..df06614 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -720,6 +720,9 @@ async def watch_game(channel, newgame, user = None, league = None): "start_delay" : 5, "end_delay" : 10 } + if newgame.weather.name == "Heavy Snow": + newgame.weather.counter_away = random.randint(0,len(newgame.teams['away'].lineup)-1) + newgame.weather.counter_home = random.randint(0,len(newgame.teams['home'].lineup)-1) if league is not None: discrim_string = league