EXPERIMENT 1
START
Gen: 0
Charts
Settings
Population
Speed
Range
Speed Distribution
Range Distribution
Speed vs Range Distribution
-
DAY 1
+
Sim Speed (1-5):
1
Daily Food Amount (20-200):
50
Speed Gene (1-20):
5
Sensor Range Gene (20-400):
50
Move energy multiplier (0-100):
20
Sense energy multiplier (0-100):
20
import js import pyodide import time import Constants import Globals from Simulation import Simulation from Canvas import CanvasDrawer from ChartDrawer import ChartDrawer from Scenario import Scenario from Scenario1 import Scenario1 from Scenario2 import Scenario2 from Scenario3 import Scenario3 def update_simspeed(value): js.console.log("SIMSPEED %d" % int(value)) Globals.SIMSPEED = int(value) def update_food_amount(value): scenario.food_amount= int(value) js.update_food_amount = update_food_amount js.update_simspeed = update_simspeed def get_url_param(param_name): return js.window.location.search.split(param_name + '=')[1].split('&')[0] experiment_display = js.document.getElementById('experiment_name_display') interval = None #Section: Setting scenarios based parameters experiment_param = get_url_param('experiment') scenario = None if experiment_param == "1": scenario = Scenario() experiment_display.innerText = f"Experiment 1" elif experiment_param == "2": scenario = Scenario1() experiment_display.innerText = f"Experiment 2" elif experiment_param == "3": scenario = Scenario2() experiment_display.innerText = f"Experiment 3" elif experiment_param == "4": scenario = Scenario3() experiment_display.innerText = f"Experiment 4" sim = Simulation(scenario) chart = ChartDrawer(sim) #Section: Day and Gen displays gen_display = js.document.getElementById('gen-display') day = -1 def update_counter(): time1 = time.time() sim.next_step() canvas.clear() time_calc = time.time() draw() time_draw = time.time() #Section: Update gen and day displays00 global gen_display global day if sim.day > day: day = sim.day gen_display.innerText = f"Generation: {day}" chart.update() time_chart = time.time() dt_calc = (time_calc - time1) * 1000 dt_draw = (time_draw - time_calc) * 1000 dt_chart = (time_chart - time_draw) * 1000 dt_total = dt_calc + dt_draw + dt_chart if dt_total > 50: js.console.log("BIGTIME: %d %d %d: " % (dt_calc, dt_draw, dt_chart)) update_counter_proxy = pyodide.create_proxy(update_counter) def toggle(event): global sim global interval #Section: Set up scenario if its not yet if not sim.is_setup: sim.setup() #Section: Update Run Button if interval is None: interval = js.setInterval(update_counter_proxy, 20) button.innerText = "PAUSE" else: js.clearInterval(interval) interval = None button.innerText = "CONTINUE" def draw(): # Initial draw for slime in Globals.creatures: if slime.is_active: if slime.food_got == 0: canvas.draw(slime, Constants.CREATURE_SIZE, Constants.SLIME_COLOR) elif slime.food_got == 1: canvas.draw(slime, Constants.CREATURE_SIZE, Constants.SLIME_ONE_FOOD) elif slime.food_got == 2: canvas.draw(slime, Constants.CREATURE_SIZE, Constants.SLIME_TWO_FOOD) else: canvas.draw(slime, Constants.CREATURE_SIZE, Constants.SLIME_COLOR_DEAD) for food in Globals.foods: canvas.draw(food, Constants.FOOD_SIZE, Constants.FOOD_COLOR) canvas = CanvasDrawer() button = js.document.getElementById('runButton') button.addEventListener('click', pyodide.create_proxy(toggle)) js.console.log("SIM IS READY")