Skip to content

Instantly share code, notes, and snippets.

@JaciBrunning
Created January 6, 2025 07:39
Show Gist options
  • Save JaciBrunning/de56557e02dff98f3c6fb3b1c8bdcfe2 to your computer and use it in GitHub Desktop.
Save JaciBrunning/de56557e02dff98f3c6fb3b1c8bdcfe2 to your computer and use it in GitHub Desktop.
# %%
from numpy import random
import matplotlib.pyplot as plt
ALGAE_PROCESSOR_CYCLE_TIME = (5, 0.5) # Mean, Stddev
CYCLE_TRAVEL_TIME = (4, 0.5) # Mean, Stddev
CYCLE_COLLECTION_TIME = (4, 0.25) # Mean, Stddev
CORAL_PLACE_TIME = (6, 0.75) # Mean, Stddev
def estimate_cycle_coral_eject(level: int):
return random.normal(*CYCLE_COLLECTION_TIME) + random.normal(*CYCLE_TRAVEL_TIME) + level*random.normal(*CORAL_PLACE_TIME) + random.normal(*CYCLE_TRAVEL_TIME)
def score_sim(strategy_coral, strategy_algae, opp_proc_chance=0.5, **kw):
points = 0
state = None
state_time = 0
state_timeout = 0
level_states = [0, 0, 0]
t = 0
while t < 2*60+30:
if state == None:
state = "cycle"
state_time = t
target_level = 0
if strategy_coral == "high-first":
if level_states[2] < 12:
target_level = 1
elif level_states[1] < 12:
target_level = 2
elif strategy_coral == "low-first":
if level_states[1] < 12:
target_level = 1
elif level_states[2] < 12:
target_level = 2
state_timeout = estimate_cycle_coral_eject(target_level)
points += 2 + target_level
if strategy_algae != "dump-algae":
points += 6 - (4 if random.rand() < opp_proc_chance else 0)
state_timeout += random.normal(*ALGAE_PROCESSOR_CYCLE_TIME)
if state_time + state_timeout <= t:
state = None
t += 0.1
return points
plt.figure(figsize=(8, 30), dpi=150)
INDEX = 0
def estimate(f, *a, **kw):
global INDEX
POINT_POTENTIALS = []
for i in range(0, 1000):
POINT_POTENTIALS.append(f(*a, **kw))
ax = plt.subplot(5, 2, INDEX + 1)
ax.set_title(", ".join([str(arg) for arg in a]) + "\n" + ", ".join([f"{str(k)}: {str(v)}" for k, v in kw.items()]))
ax.hist(POINT_POTENTIALS)
ax.axis([0, 140, 0, 500])
# plt.show()
INDEX += 1
estimate(score_sim, "high-first", "dump-algae")
estimate(score_sim, "low-first", "dump-algae")
estimate(score_sim, "high-first", "processor-algae", opp_proc_chance=0.25)
estimate(score_sim, "low-first", "processor-algae", opp_proc_chance=0.25)
estimate(score_sim, "high-first", "processor-algae", opp_proc_chance=0.5)
estimate(score_sim, "low-first", "processor-algae", opp_proc_chance=0.5)
estimate(score_sim, "high-first", "processor-algae", opp_proc_chance=0.75)
estimate(score_sim, "low-first", "processor-algae", opp_proc_chance=0.75)
estimate(score_sim, "high-first", "processor-algae", opp_proc_chance=1)
estimate(score_sim, "low-first", "processor-algae", opp_proc_chance=1)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment