began implementing archetypes
This commit is contained in:
parent
f7164f207e
commit
51c30b326e
27
archetypes.py
Normal file
27
archetypes.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import random
|
||||||
|
from gametext import appearance_outcomes
|
||||||
|
|
||||||
|
class Archetype:
|
||||||
|
name = "basic"
|
||||||
|
display_name = "Jack of All Trades"
|
||||||
|
display_symbol = "🃏"
|
||||||
|
|
||||||
|
def modify_bat_rolls(self, outcome, rolls):
|
||||||
|
""""modify the rolls used in batting before using the rolled values"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def modify_out_type(self, outcome):
|
||||||
|
"""if the batter would go out, do something"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def modify_hit_type(self, outcome):
|
||||||
|
"""if the batter would get a hit, do something"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def hold_runner(self, outcome, stats):
|
||||||
|
"""affect the pitcher's ability to prevent steal attempts"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def steal_check(self, outcome, steal_roll):
|
||||||
|
"""make a runner more or less likely to steal"""
|
||||||
|
pass
|
51
games.py
51
games.py
|
@ -1,4 +1,4 @@
|
||||||
import json, random, os, math, jsonpickle, weather
|
import json, random, os, math, jsonpickle, weather, archetypes
|
||||||
import database as db
|
import database as db
|
||||||
from league_storage import get_mods, get_team_mods
|
from league_storage import get_mods, get_team_mods
|
||||||
from gametext import base_string, appearance_outcomes, game_strings_base
|
from gametext import base_string, appearance_outcomes, game_strings_base
|
||||||
|
@ -91,6 +91,7 @@ class team(object):
|
||||||
self.lineup = []
|
self.lineup = []
|
||||||
self.lineup_position = 0
|
self.lineup_position = 0
|
||||||
self.rotation = []
|
self.rotation = []
|
||||||
|
self.archetypes = {}
|
||||||
self.pitcher = None
|
self.pitcher = None
|
||||||
self.score = 0
|
self.score = 0
|
||||||
self.slogan = None
|
self.slogan = None
|
||||||
|
@ -234,6 +235,9 @@ class game(object):
|
||||||
self.over = False
|
self.over = False
|
||||||
self.random_weather_flag = False
|
self.random_weather_flag = False
|
||||||
self.teams = {"away" : team1, "home" : team2}
|
self.teams = {"away" : team1, "home" : team2}
|
||||||
|
self.archetypes = {team1.name : team1.archetypes, team2.name : team2.archetypes}
|
||||||
|
self.offense_archetypes = {}
|
||||||
|
self.defense_archetypes = {}
|
||||||
self.inning = 1
|
self.inning = 1
|
||||||
self.outs = 0
|
self.outs = 0
|
||||||
self.top_of_inning = True
|
self.top_of_inning = True
|
||||||
|
@ -294,6 +298,21 @@ class game(object):
|
||||||
outcome["pitcher"] = pitcher
|
outcome["pitcher"] = pitcher
|
||||||
outcome["defender"] = ""
|
outcome["defender"] = ""
|
||||||
|
|
||||||
|
if pitcher.name in self.defense_archetypes.keys():
|
||||||
|
outcome["pitcher_archetype"] = self.defense_archetypes[pitcher.name]
|
||||||
|
else:
|
||||||
|
outcome["pitcher_archetype"] = archetypes.Archetype
|
||||||
|
|
||||||
|
if batter.name in self.offense_archetypes.keys():
|
||||||
|
outcome["batter_archetype"] = self.offense_archetypes[batter.name]
|
||||||
|
else:
|
||||||
|
outcome["batter_archetype"] = archetypes.Archetype
|
||||||
|
|
||||||
|
if defender.name in self.defense_archetypes.keys():
|
||||||
|
outcome["defender_archetype"] = self.defense_archetypes[defender.name]
|
||||||
|
else:
|
||||||
|
outcome["defender_archetype"] = archetypes.Archetype
|
||||||
|
|
||||||
player_rolls = {}
|
player_rolls = {}
|
||||||
player_rolls["bat_stat"] = random_star_gen("batting_stars", batter)
|
player_rolls["bat_stat"] = random_star_gen("batting_stars", batter)
|
||||||
player_rolls["pitch_stat"] = random_star_gen("pitching_stars", pitcher)
|
player_rolls["pitch_stat"] = random_star_gen("pitching_stars", pitcher)
|
||||||
|
@ -306,6 +325,9 @@ class game(object):
|
||||||
|
|
||||||
self.weather.modify_atbat_roll(outcome, roll, defender)
|
self.weather.modify_atbat_roll(outcome, roll, defender)
|
||||||
|
|
||||||
|
outcome["batter_archetype"].modify_bat_rolls(outcome, roll)
|
||||||
|
outcome["pitcher_archetype"].modify_bat_rolls(outcome, roll)
|
||||||
|
|
||||||
|
|
||||||
if roll["pb_system_stat"] <= 0:
|
if roll["pb_system_stat"] <= 0:
|
||||||
outcome["ishit"] = False
|
outcome["ishit"] = False
|
||||||
|
@ -321,6 +343,9 @@ class game(object):
|
||||||
else:
|
else:
|
||||||
outcome["outcome"] = appearance_outcomes.walk
|
outcome["outcome"] = appearance_outcomes.walk
|
||||||
|
|
||||||
|
outcome["batter_archetype"].modify_out_type(outcome)
|
||||||
|
outcome["pitcher_archetype"].modify_out_type(outcome)
|
||||||
|
|
||||||
if self.bases[1] is not None and roll["hitnum"] < -2 and self.outs != 2:
|
if self.bases[1] is not None and roll["hitnum"] < -2 and self.outs != 2:
|
||||||
outcome["outcome"] = appearance_outcomes.doubleplay
|
outcome["outcome"] = appearance_outcomes.doubleplay
|
||||||
outcome["defender"] = ""
|
outcome["defender"] = ""
|
||||||
|
@ -358,6 +383,10 @@ class game(object):
|
||||||
outcome["outcome"] = appearance_outcomes.grandslam
|
outcome["outcome"] = appearance_outcomes.grandslam
|
||||||
else:
|
else:
|
||||||
outcome["outcome"] = appearance_outcomes.homerun
|
outcome["outcome"] = appearance_outcomes.homerun
|
||||||
|
|
||||||
|
outcome["batter_archetype"].modify_hit_type(outcome)
|
||||||
|
outcome["pitcher_archetype"].modify_hit_type(outcome)
|
||||||
|
|
||||||
return outcome
|
return outcome
|
||||||
|
|
||||||
def thievery_attempts(self): #returns either false or "at-bat" outcome
|
def thievery_attempts(self): #returns either false or "at-bat" outcome
|
||||||
|
@ -375,8 +404,21 @@ class game(object):
|
||||||
|
|
||||||
self.weather.modify_steal_stats(stats)
|
self.weather.modify_steal_stats(stats)
|
||||||
|
|
||||||
|
if pitcher.name in self.defense_archetypes.keys():
|
||||||
|
outcome["pitcher_archetype"] = self.defense_archetypes[pitcher.name]
|
||||||
|
else:
|
||||||
|
outcome["pitcher_archetype"] = archetypes.Archetype
|
||||||
|
|
||||||
|
if baserunner.name in self.offense_archetypes.keys():
|
||||||
|
outcome["baserunner_archetype"] = self.offense_archetypes[baserunner.name]
|
||||||
|
else:
|
||||||
|
outcome["baserunner_archetype"] = archetypes.Archetype
|
||||||
|
|
||||||
|
outcome["pitcher_archetype"].hold_runner(outcome, stats)
|
||||||
|
|
||||||
if stats["run_stars"] >= (stats["def_stars"] - 1.5): #if baserunner isn't worse than pitcher
|
if stats["run_stars"] >= (stats["def_stars"] - 1.5): #if baserunner isn't worse than pitcher
|
||||||
roll = random.random()
|
roll = random.random()
|
||||||
|
outcome["baserunner_archetype"].steal_check(outcome, roll)
|
||||||
if roll >= (-(((stats["run_stars"]+1)/14)**2)+1): #plug it into desmos or something, you'll see
|
if roll >= (-(((stats["run_stars"]+1)/14)**2)+1): #plug it into desmos or something, you'll see
|
||||||
attempts.append((baserunner, start_base))
|
attempts.append((baserunner, start_base))
|
||||||
|
|
||||||
|
@ -398,6 +440,10 @@ class game(object):
|
||||||
run_stat = random_star_gen("baserunning_stars", baserunner)
|
run_stat = random_star_gen("baserunning_stars", baserunner)
|
||||||
def_stat = random_star_gen("defense_stars", defender)
|
def_stat = random_star_gen("defense_stars", defender)
|
||||||
run_roll = random.gauss(2*math.erf((run_stat-def_stat)/4)-1,3)*config()["stolen_base_success_mod"]
|
run_roll = random.gauss(2*math.erf((run_stat-def_stat)/4)-1,3)*config()["stolen_base_success_mod"]
|
||||||
|
|
||||||
|
outcome["baserunner_archetype"].modify_steal_attempt(outcome, run_roll)
|
||||||
|
outcome["pitcher_archetype"].modify_steal_attempt(outcome, run_roll)
|
||||||
|
|
||||||
if start_base == 2:
|
if start_base == 2:
|
||||||
run_roll = run_roll * .9 #stealing third is harder
|
run_roll = run_roll * .9 #stealing third is harder
|
||||||
if run_roll < 1:
|
if run_roll < 1:
|
||||||
|
@ -557,6 +603,9 @@ class game(object):
|
||||||
offense_team = self.teams["home"]
|
offense_team = self.teams["home"]
|
||||||
defense_team = self.teams["away"]
|
defense_team = self.teams["away"]
|
||||||
|
|
||||||
|
self.offense_archetypes = self.archetypes[offense_team.name]
|
||||||
|
self.defense_archetypes = self.archetypes[defense_team.name]
|
||||||
|
|
||||||
|
|
||||||
defenders = defense_team.lineup.copy()
|
defenders = defense_team.lineup.copy()
|
||||||
defenders.append(defense_team.pitcher)
|
defenders.append(defense_team.pitcher)
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="archetypes.py">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="database.py">
|
<Compile Include="database.py">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
Loading…
Reference in a new issue