Created
June 6, 2015 04:40
-
-
Save coderanger/b36b70550e2521538e1f to your computer and use it in GitHub Desktop.
Monte carlo simulation for Glim Farming in with Lyme.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import random | |
import statistics | |
def run_Take_on_a_Clay_Pupil(state): | |
state['cp'] = 1 | |
def run_Reading_and_writing(state): | |
"""Requires Pygmalion 1.""" | |
state['glim'] += 105 | |
state['cp'] += 3 | |
def run_Leisure(state): | |
"""Requires Pygmalion 3.""" | |
state['glim'] += 108 | |
state['cp'] += 3 | |
def run_Independent_thought(state): | |
"""Requires Pygmalion 5.""" | |
state['glim'] += 111 | |
state['cp'] += 3 | |
def get_level(cp): | |
return math.floor((math.sqrt((8*cp) + 1) - 1) * 0.5) | |
def get_narrow_chance(level, target): | |
chance = 0.5 + ((level - target) * 0.1) | |
if chance > 1: | |
chance = 1.0 | |
elif chance < 0.1: | |
chance = 0.1 | |
return chance | |
def run_Ask_him_to_write_a_story(state): | |
level = get_level(state['cp']) | |
chance = get_narrow_chance(level, 12) | |
if random.random() <= chance: | |
state['glim'] += 700 | |
state['cp'] = 0 | |
else: | |
state['cp'] -= 10 | |
state['suspicion'] += 3 | |
def run(state, threshold): | |
level = get_level(state['cp']) | |
if level == 0: | |
run_Take_on_a_Clay_Pupil(state) | |
elif level < 3: | |
run_Reading_and_writing(state) | |
elif level < 5: | |
run_Leisure(state) | |
elif level >= threshold: | |
run_Ask_him_to_write_a_story(state) | |
else: | |
run_Independent_thought(state) | |
def value_of_suspicion(state): | |
solutions = state['suspicion'] / 5.5 | |
return solutions * -250 | |
def run_actions(actions, threshold): | |
state = {'glim': 0, 'cp': 0, 'suspicion': 0} | |
for i in range(actions): | |
run(state, threshold) | |
total_value = state['glim'] + value_of_suspicion(state) | |
return total_value / actions | |
def run_trials(runs, actions, threshold): | |
values = [] | |
for i in range(runs): | |
values.append(run_actions(actions, threshold)) | |
return { | |
'runs': runs, | |
'actions': actions, | |
'threshold': threshold, | |
'mean': statistics.mean(values), | |
'stdev': statistics.stdev(values), | |
} | |
def display_trial(ret): | |
print('Ran {actions}x{runs} with {threshold}: {mean}({stdev})'.format(**ret)) | |
def run_all_trials(runs, actions): | |
for threshold in range(12, 18): | |
display_trial(run_trials(runs, actions, threshold)) | |
run_all_trials(1000, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment