tidied up stealing implementation
This commit is contained in:
parent
5f88bfaee1
commit
aac1d905e2
4
games.py
4
games.py
|
@ -222,7 +222,7 @@ class game(object):
|
|||
self.max_innings = config()["default_length"]
|
||||
self.bases = {1 : None, 2 : None, 3 : None}
|
||||
self.weather = weather.Weather(self)
|
||||
self.voice = game_strings_base()
|
||||
self.voice = None
|
||||
self.current_batter = None
|
||||
|
||||
def occupied_bases(self):
|
||||
|
@ -383,7 +383,7 @@ class game(object):
|
|||
self.bases[start_base+1] = baserunner
|
||||
self.bases[start_base] = None
|
||||
|
||||
self.voice.stealing(baserunner.name, base_string(start_base+1), defender.name, successful)
|
||||
self.voice.stealing(outcome, baserunner.name, base_string(start_base+1), defender.name, successful)
|
||||
|
||||
if self.outs >= 3:
|
||||
self.flip_inning()
|
||||
|
|
30
gametext.py
30
gametext.py
|
@ -40,14 +40,14 @@ class game_strings_base(object):
|
|||
homerun = ["hits a dinger!"]
|
||||
grandslam = ["hits a grand slam!"]
|
||||
|
||||
steal_success = ["{} was caught stealing {} base by {}!"]
|
||||
steal_caught = ["{runner} steals {base_string} base!"]
|
||||
steal_caught = ["{} was caught stealing {} base by {}!"]
|
||||
steal_success = ["{} steals {} base!"]
|
||||
|
||||
twoparts = []
|
||||
|
||||
diff_formats = {fielderschoice[0]: ("defender", "base_string"),
|
||||
steal_success[0]: ("runner", "base_string", "defender"),
|
||||
steal_caught[0]: ("runner", "base_string")}
|
||||
steal_success[0]: ("runner", "base_string"),
|
||||
steal_caught[0]: ("runner", "base_string", "defender")}
|
||||
no_formats = strikeoutlooking + strikeoutswinging + doubleplay + walk + single + double + triple + homerun + grandslam
|
||||
|
||||
def activate(self, lastupdate, currentupdate, game):
|
||||
|
@ -99,22 +99,22 @@ class game_strings_base(object):
|
|||
def activate_weather(self, lastupdate, currentupdate, game):
|
||||
pass
|
||||
|
||||
def stealing(self, runner, base_string, defender, is_successful):
|
||||
if not is_successful:
|
||||
index = randrange(0, len(steal_success))
|
||||
text = steal_success[index]
|
||||
def stealing(self, currentupdate, runner, base_string, defender, is_successful):
|
||||
if is_successful:
|
||||
index = randrange(0, len(self.steal_success))
|
||||
text = self.steal_success[index]
|
||||
else:
|
||||
index = randrange(0, len(steal_caught))
|
||||
text = steal_caught[index]
|
||||
index = randrange(0, len(self.steal_caught))
|
||||
text = self.steal_caught[index]
|
||||
|
||||
format_list = []
|
||||
for format in diff_formats[text]:
|
||||
for format in self.diff_formats[text]:
|
||||
if format == "runner":
|
||||
format_list.append(runner.name)
|
||||
format_list.append(runner)
|
||||
elif format == "base_string":
|
||||
format_list.append(base_string)
|
||||
elif format == "defender":
|
||||
format_list.append(defender.name)
|
||||
format_list.append(defender)
|
||||
|
||||
currentupdate["steals"] = [text.format(*format_list)]
|
||||
|
||||
|
@ -214,8 +214,8 @@ class TheGoddesses(game_strings_base):
|
|||
|
||||
|
||||
def all_voices():
|
||||
return [game_strings_base,
|
||||
TheGoddesses]
|
||||
return {"default": game_strings_base,
|
||||
"the goddesses": TheGoddesses}
|
||||
|
||||
|
||||
def base_string(base):
|
||||
|
|
|
@ -1632,7 +1632,7 @@ def prepare_game(newgame, league = None, weather_name = None):
|
|||
newgame.weather = weathers[random.choice(list(weathers.keys()))](newgame)
|
||||
|
||||
if newgame.voice is None:
|
||||
newgame.voice = gametext.TheGoddesses()
|
||||
newgame.voice = random.choice(list(gametext.all_voices().values()))()
|
||||
|
||||
state_init = {
|
||||
"away_name" : newgame.teams['away'].name,
|
||||
|
|
Loading…
Reference in a new issue