def do(): population = int(e1.get()) initial_infection_rate = float(e2.get()) closeness = int(e3.get()) dimensions = int(e4.get()) speed = int(e5.get()) frequency = int(e6.get()) turns = int(e7.get()) no_doctors = int(e8.get()) train_new_doctor_frequency = int(e9.get()) length_of_immunity = int(e10.get()) widget_list = all_children(master) for item in widget_list: item.pack_forget() myworld = World(population, initial_infection_rate, closeness, dimensions, speed, frequency, turns, no_doctors, length_of_immunity) myworld.populate_world(population, initial_infection_rate, closeness) w = Canvas(master, width=canvas_width, height=canvas_height) w.pack(expand=YES, fill=BOTH) for i in range(turns): update(i, w, myworld) if i % train_new_doctor_frequency == 0: myworld.train_doctor() time.sleep(0.05) mainloop()
def __init__(self, width, height): super().__init__(width, height) self.background = arcade.load_texture("images/bgni.jpg") self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.dot_sprite = ModelSprite('images/player.png', model=self.world.player) self.monster_sprite = MonsterSprite(model=self.world.monster) self.coin_sprite = [ CoinSprite(model=self.world.coin[0]), CoinSprite(model=self.world.coin[1]), CoinSprite(model=self.world.coin[2]), CoinSprite(model=self.world.coin[3]), CoinSprite(model=self.world.coin[4]) ] self.bomb_sprite = [ BombSprite(model=self.world.bomb[0]), BombSprite(model=self.world.bomb[1]), BombSprite(model=self.world.bomb[2]) ] self.hp = [ arcade.load_texture("images/pills.png"), arcade.load_texture("images/pills.png"), arcade.load_texture("images/pills.png") ] self.num_hp = 2 self.menus = { 'gameover': arcade.load_texture("images/gameover.png"), 'play': arcade.load_texture("images/play.png") } self.count = 0 self.temp_player = 1
def main(): # constants specific to statistic collection of simulations NUM_SIMULATIONS = 2 parser = argparse.ArgumentParser(description="Visualization controls") parser.add_argument("--visualize", action="store_true", help="whether to visualize on browser") args = parser.parse_args() if args.visualize: server.launch() else: coops = np.arange(0.0, 1.1, 0.1) ## TESTING ## # coops = [0.5] ############# e_prob = 0.5 for coop in coops: print("Simulating with cooperation level %.2f" % (coop)) f_name = "logs/log_%d" % (coop * 100) with open(f_name, 'w+') as f: for _ in range(NUM_SIMULATIONS): model = World(100, coop, e_prob) while model.schedule.time < 3000 and len( model.schedule.agents) != 0: # simulate till there are agents in the world model.step() # explorer mean age mean_explorer_age = np.mean( [model.ages[i] for i in model.ages if "explorer" in i]) # exploiter mean age mean_exploiter_age = np.mean([ model.ages[i] for i in model.ages if "exploiter" in i ]) # entire population mean age mean_age = np.mean([model.ages[i] for i in model.ages]) # mean expected age based on initial values expected_age = np.mean(model.expected_ages) ages = ', '.join([str(model.ages[i]) for i in model.ages]) memoryLens = ', '.join( [str(model.memoryLens[i]) for i in model.memoryLens]) total_energy = ', '.join( [str(i) for i in model.energy_tracker]) num_explorers = ', '.join( [str(i[0]) for i in model.member_tracker]) num_exploiters = ', '.join( [str(i[1]) for i in model.member_tracker]) f.write("ages, " + ages + "\n") f.write("memoryLens, " + memoryLens + "\n") f.write("total_energy, " + total_energy + "\n") f.write("num_explorers, " + num_explorers + "\n") f.write("num_exploiters, " + num_exploiters + "\n") f.write("%.5f, %.5f, %.5f, %.5f\n" % (mean_explorer_age, mean_exploiter_age, mean_age, expected_age))
def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(width, height) self.gold_sprite = ModelSprite('images/Gold.png', model=self.world.gold) self.ship_sprite = ModelSprite('images/ship.png', model=self.world.ship)
def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(SCREEN_WIDTH, SCREEN_HEIGHT) self.snake_sprite = ModelSprite('images/block.png', model=self.world.snake) self.snake_sprite = SnakeSprite(self.world.snake) self.heart_sprite = HeartSprite(self.world.heart)
def create_test_world(): world = add(World(name='Test World')) portal = add(Location(name='Portal', world=world)) plaza = add(Location(name='Plaza', world=world)) hotel = add(Location(name='Old Grand Hotel', world=world)) basement = add(Location(name='Hotel Basement', world=world)) add( Path( start=portal, destination=hotel, description= "YOU ARE IN THE HOTEL. THERE'S A DOOR TO THE BASEMENT IN FRONT OF YOU." )) add( Path( start=plaza, destination=hotel, description= "YOU ARE IN THE HOTEL. THERE'S A DOOR TO THE BASEMENT IN FRONT OF YOU." )) add( Path(start=hotel, destination=plaza, description="YOU ARE IN THE PLAZA, FACING THE HOTEL.")) add( Path( start=hotel, destination=basement, description= "YOU ARE IN THE BASEMENT. THERE ARE STAIRS UP TO THE HOTEL LOBBY BEHIND YOU." )) add( Path( start=basement, destination=hotel, description= "YOU ARE IN THE HOTEL LOBBY. THERE'S AN EXIT TO THE PLAZA IN FRONT OF YOU." )) add( Session(code='TestSession1', active=True, current_location=hotel, previous_location=portal)) db.session.commit()
def __init__(self, population, initial_infection_rate, closeness, dimensions, speed, frequency, turns, no_doctors, length_of_immunity, train_new_doctor_frequency): self.my_world = World(population, initial_infection_rate, closeness, dimensions, speed, frequency, turns, no_doctors, length_of_immunity) self.my_world.populate_world(population, initial_infection_rate, closeness) self.infectedCount = [] self.healthyCount = [] self.count = 0 self.frequency = frequency self.train_new_doctor_frequency = train_new_doctor_frequency
def __init__(self, width, height): super().__init__(width, height) self.current_state = INSTRUCTION_PAGE self.score = 0 self.background = arcade.load_texture('images/background.png') self.world = World(width, height) self.player_sprite = ModelSprite('images/soilder.png', model=self.world.player) self.zombie_sprite = ModelSprite('images/zombie.png', model=self.world.zombie) self.laser_sprite = ModelSprite('images/laser1.png', model=self.world.player.bullet)
def __init__(self, width, height): super().__init__(width, height) arcade.set_background_color(arcade.color.BLACK) self.world = World(width, height) self.endgame = arcade.Sprite('images/black.png', scale=2) self.hunter_sprite = ModelSprite('images/hunter.png', scale=0.4, model=self.world.hunter) self.bullet_sprite = [] self.pigs_sprites = [] for pig in self.world.pigs: self.pigs_sprites.append( ModelSprite('images/pig.png', scale=0.18, model=pig)) self.foxs_sprites = [] for fox in self.world.foxs: self.foxs_sprites.append( ModelSprite('images/fox.png', scale=0.36, model=fox))
############################## # set up data structure ############################## column_names = ['trial', 'noise', 'A_whether'] df = pd.DataFrame(0.0, index=np.arange(len(trials)), columns=column_names) df['trial'] = trials df['noise'] = noise ############################## # run simulations ############################## w = World() for idx, trial in enumerate(trials): df.loc[idx, 'A_whether'] = w.whether_cause(experiment=experiment, noise=noise, w=w, trial=trial, cause='A', df=df, n_simulations=n_simulations, animate=animate) df['trial'] = df['trial'] + 1 df = df * 1 #logical to integer if record_data: