Browse Source

looking okay

main
Charles Reid 4 years ago
parent
commit
bba2853ada
  1. 7
      v3/game.py
  2. 8
      v3/gators.py
  3. 3
      v3/inninggenerator.py
  4. 8
      v3/players.py
  5. 55
      v3/roll.py

7
v3/game.py

@ -45,20 +45,23 @@ class Game(object): @@ -45,20 +45,23 @@ class Game(object):
Simulate a single game
"""
logger.warning('\n\n')
logger.warning('====================================')
logger.warning('============ TOP INNING ============')
logger.warning('====================================')
t1_w, t1_r = InningGenerator.generate_half(self.config, self.state, True)
logger.warning('\n\n')
logger.warning('====================================')
logger.warning('============ BOT INNING ============')
logger.warning('====================================')
t2_w, t2_r = InningGenerator.generate_half(self.config, self.state, False)
logger.warning('\n\n')
logger.warning('====================================')
logger.warning('=========== GAME SUMMARY ===========')
logger.warning('====================================')
state = self.state
logger.info(f"{state.team1.name}: {state.state1.wickets} / {state.state1.runs} - {len(t1_r)}.{len(t1_r[-1])}")
logger.info(f"{state.team2.name}: {state.state2.wickets} / {state.state2.runs} - {len(t2_r)}.{len(t2_r[-2])}")
logger.info(f"{state.team1.name:>35}: {state.state1.wickets} / {state.state1.runs} - {len(t1_r)}.{len(t1_r[-1])}")
logger.info(f"{state.team2.name:>35}: {state.state2.wickets} / {state.state2.runs} - {len(t2_r)}.{len(t2_r[-1])}")

8
v3/gators.py

@ -18,7 +18,7 @@ class Gator(object): @@ -18,7 +18,7 @@ class Gator(object):
def __init__(self):
self.id = str(uuid.uuid4())
self.attr = {}
self.attr['agg'] = 3 # random.randint(1,5)
self.attr['rea'] = 3 # random.randint(1,5)
self.attr['rxn'] = 3 # random.randint(1,5)
self.attr['con'] = 3 # random.randint(1,5)
self.attr['agg'] = random.randint(1,5)
self.attr['rea'] = random.randint(1,5)
self.attr['rxn'] = random.randint(1,5)
self.attr['con'] = random.randint(1,5)

3
v3/inninggenerator.py

@ -48,7 +48,8 @@ class InningGenerator(object): @@ -48,7 +48,8 @@ class InningGenerator(object):
this_wickets = []
for iplay in range(ppo):
outcome = Roll.roll(batting_state.pokers[0], gator)
context = f"{iover+1}.{iplay+1}"
outcome = Roll.roll(batting_state.pokers[0], gator, context)
# Increment runs/wickets and update pokers
if outcome > 0:

8
v3/players.py

@ -40,7 +40,7 @@ class Player(object): @@ -40,7 +40,7 @@ class Player(object):
def __init__(self):
self.id = str(uuid.uuid4())
self.attr = {}
self.attr['agg'] = 3 # random.randint(1,5)
self.attr['rea'] = 3 # random.randint(1,5)
self.attr['rxn'] = 3 # random.randint(1,5)
self.attr['con'] = 3 # random.randint(1,5)
self.attr['agg'] = random.randint(1,5)
self.attr['rea'] = random.randint(1,5)
self.attr['rxn'] = random.randint(1,5)
self.attr['con'] = random.randint(1,5)

55
v3/roll.py

@ -37,18 +37,18 @@ class Roll(object): @@ -37,18 +37,18 @@ class Roll(object):
# Map star ratings to new spaces
# Expected outcome
player_attr_min = 0.25
player_attr_max = 0.75
player_attr_min = 0.4
player_attr_max = 0.8
player_attr_space = np.linspace(player_attr_min, player_attr_max, nstars)
# Consistency (alpha param of beta distribution)
player_con_space = np.logspace(-0.5, 0.5, nstars)
player_con_space = np.logspace(-0.4, 0.4, nstars)
# Expected outcome
gator_attr_min = 0.25
gator_attr_max = 0.75
gator_attr_min = 0.3
gator_attr_max = 0.6
gator_attr_space = np.linspace(gator_attr_min, gator_attr_max, nstars)
# Consistency
gator_con_space = np.logspace(-0.5, 0.5, nstars)
gator_con_space = np.logspace(-0.4, 0.4, nstars)
# Get attribute
pa = player.attr[attr_lab]
@ -70,7 +70,7 @@ class Roll(object): @@ -70,7 +70,7 @@ class Roll(object):
return (p_outcome, g_outcome)
@classmethod
def roll(cls, player, gator):
def roll(cls, player, gator, context=None):
"""
Given a player and a gator, run the various rolls and find an outcome.
"""
@ -83,45 +83,52 @@ class Roll(object): @@ -83,45 +83,52 @@ class Roll(object):
rea_diff = rea[0] - rea[1]
rxn_diff = rxn[0] - rxn[1]
if context:
prefix = f"{context}: "
else:
prefix = ""
if agg_diff > 0 and rea_diff > 0:
# Player won
if rxn_diff < 0:
# Player won but gator got reversal
logger.debug(f"Player flinched!")
logger.debug(prefix + f"Player was about to poke but flinched!")
return 0
else:
# Outcome: runs
diff = rxn[0] - rxn[1]
if diff > 0.8:
logger.debug(f"Gator got slapped!")
if rxn_diff > 0.66:
logger.debug(prefix + f"Gator got slapped!")
return 6
elif diff > 0.5:
logger.debug(f"Gator got booped in the snoot!")
elif rxn_diff > 0.33:
logger.debug(prefix + f"Gator got booped in the snoot!")
return 4
else:
logger.debug(f"Gator got poked!")
elif rxn_diff > 0.05:
logger.debug(prefix + f"Gator got poked!")
return 1
else:
logger.debug(prefix + f"Player poked wildly, missing the gator!")
return 0
elif agg_diff < 0 and rea_diff < 0:
# Gator won
if rxn_diff > 0:
# Gator won but player got reversal
logger.debug(f"Gator flinched!")
logger.debug(prefix + f"Gator was about to chomp but flinched!")
return 0
else:
# Outcome: wickets
if abs(rxn_diff) > 0.8:
logger.debug(f"Player was eaten by gator!")
if abs(rxn_diff) > 0.66:
logger.debug(prefix + f"Player was eaten by gator! **************************")
return -3
elif abs(rxn_diff) > 0.5:
logger.debug(f"Player's arm got chomped by the gator!")
elif abs(rxn_diff) > 0.33:
logger.debug(prefix + f"Player's arm chomped by gator!")
return -2
elif abs(rxn_diff) > 0.2:
logger.debug(f"Player's finger got chomped by the gator!")
elif abs(rxn_diff) > 0.05:
logger.debug(prefix + f"Player's finger chomped by gator!")
return -1
else:
logger.debug(f"Player escaped!")
logger.debug(prefix + f"Gator chomped but narrowly missed!")
return 0
else:
logger.debug(f"Nothing happened!")
logger.debug(prefix + f"The gator retreated...")
return 0

Loading…
Cancel
Save