def main(): agents = [ISMCTSAgent(), Agent(), Agent()] wins = 0 first_wins = 0 second_wins = 0 losses = 0 first_losses = 0 second_losses = 0 total_games = 1000 prev_start = 1 for i in range(0, total_games): game = UnoState(len(agents)) #game.card_encoding = encode_cards(game) #game.playerToMove = 0 if prev_start == 1 else 1 prev_start = game.playerToMove print(f"{game.playerToMove} starts") if PlayGame(agents, game) == 0: wins += 1 else: losses += 1 print(f"Current Record: {wins}-{losses} ({wins+losses} games)") print(f"\nFinal Record: {wins}-{losses} ({wins+losses} games)") return
def testFollowStationary(self): from spatialRelationClassifier import SpatialRelationClassifier sr_class = SpatialRelationClassifier() result = sr_class.classify("to", [(0, 0), (10, 10)], [(9, 9), (9, 10), (10, 10), (10, 9)]) map_fn = "%s/data/directions/direction_floor_3/direction_floor_3_small_filled.cmf" % TKLIB_HOME cluster_fn = "%s/data/directions/direction_floor_3/skels/direction_floor_3_skel.pck" % TKLIB_HOME gtruth_tag_fn = "%s/data/directions/direction_floor_3/tags/df3_small_tags.tag" % TKLIB_HOME tagFile = tag_util.tag_file(gtruth_tag_fn, map_fn) tagFile.get_map() tagFile.get_tag_names() skeleton = carmen_map_skeletonizer.load(cluster_fn, map_fn) situation = Situation([Agent("figure", [(0, (25.400000378489494, 9.0000001341104507, 0.0))]), Agent("landmark", [(0, (25.200000375509262, 11.800000175833702, 0.0)), (1, (25.400000378489494, 12.000000178813934, -2.3561944901923448)), (2, (25.400000378489494, 12.200000181794167, -1.5707963267948966)), (3, (25.400000378489494, 12.400000184774399, -1.5707963267948966)), (4, (25.200000375509262, 12.600000187754631, -0.78539816339744828)), (5, (25.200000375509262, 12.800000190734863, -1.5707963267948966)), (6, (25.200000375509262, 13.000000193715096, -1.5707963267948966)), (7, (25.200000375509262, 13.200000196695328, -1.5707963267948966)), (8, (25.00000037252903, 13.40000019967556, -0.78539816339744828)), (9, (24.800000369548798, 13.600000202655792, -0.78539816339744828)), (10,(24.600000366568565, 13.800000205636024, -0.78539816339744828)), (11,(24.600000366568565, 13.800000205636024, 0.0))])], tagFile, skeleton) classifiers = trainer_pacman.versionOne() for name, c in classifiers.iteritems(): print "domain", name, c.classifier.domain.classVar.values self.assertEqual(len(c.classifier.domain.classVar.values), 2) sr_class = SpatialRelationClassifier() result = sr_class.classify("to", [(0, 0), (10, 10)], [(9, 9), (9, 10), (10, 10), (10, 9)]) followClassifier = classifiers["follow"] followClassifier.classify(situation) sr_class = SpatialRelationClassifier() result = sr_class.classify("to", [(0, 0), (10, 10)], [(9, 9), (9, 10), (10, 10), (10, 9)]) followClassifier.classify(situation) self.assertTrue(followClassifier.pTrue > 0.5)
def __init__(self, a_params, p_params, f_params, vel, handlers=None, view=True, frict=0.05): ''' Environment class that contains all necessary components to configure and run scenarios. a_params -- parameters for the Blue Agent p_params -- parameters for the Green Agent f_params -- parameters for the Fireball vel -- velcoties associated with each agent in the scenario handlers -- optional collision handlers view -- flag for whether you want to view the scenario or not frict -- friction value for pymunk physics ''' self.view = view # Objects in environent self.agent = Agent(a_params['loc'][0], a_params['loc'][1], a_params['color'], a_params['coll'], a_params['moves']) self.patient = Agent(p_params['loc'][0], p_params['loc'][1], p_params['color'], p_params['coll'], p_params['moves']) self.fireball = Agent(f_params['loc'][0], f_params['loc'][1], f_params['color'], f_params['coll'], f_params['moves']) # Initial location of objects in environment self.p_loc = p_params['loc'] self.a_loc = a_params['loc'] self.f_loc = f_params['loc'] # Pymunk space friction self.friction = frict # Agent velocities self.vel = vel # Engine parameters self.space = None self.screen = None self.options = None self.clock = None # Collision handlers self.coll_handlers = [x for x in handlers] if handlers else handlers # Values needed for rendering the scenario in Blender self.tick = 0 self.agent_collision = None self.patient_fireball_collision = 0 self.position_dict = {'agent': [], 'patient': [], 'fireball': []} self.screen_size = (1000, 600) # Configure and run environment self.configure()
def testVerbClassifierTrue(self): map_fn = "%s/data/directions/direction_floor_3/direction_floor_3_small_filled.cmf" % TKLIB_HOME cluster_fn = "%s/data/directions/direction_floor_3/skels/direction_floor_3_skel.pck" % TKLIB_HOME gtruth_tag_fn = "%s/data/directions/direction_floor_3/tags/df3_small_tags.tag" % TKLIB_HOME tagFile = tag_util.tag_file(gtruth_tag_fn, map_fn) tagFile.get_map() tagFile.get_tag_names() skeleton = carmen_map_skeletonizer.load(cluster_fn, map_fn) situation = Situation([Agent("figure", # a list of tuples # [(time1, (x1, y1, theta1)), # (time2, (x2, y2, theta2))] [(0, (0, 0, 0)), (1, (0, 1, 1)), (2, (0, 2, 2))]), Agent("landmark", [(0, (0, -1, -1)), (1, (0, 0, 0)), (2, (0, 1, 1))])], tagFile, skeleton ) classifiers = trainer_pacman.versionOne() followClassifier = classifiers["follow"] self.assertEqual(followClassifier.classify(situation), False) print "true", followClassifier.pTrue print "false", followClassifier.pFalse self.assertTrue(0 <= followClassifier.pTrue <= 1) self.assertTrue(0 <= followClassifier.pFalse <= 1) situation = Situation([Agent("figure", [(0, (0, 0, 0)), (1, (0, 1, 1)), (2, (0, 2, 2))]), Agent("landmark", [(0, (0, 100, 100)), (1, (0, 101, 101)), (2, (0, 102, 102))])], tagFile, skeleton) self.assertEqual(followClassifier.classify(situation), False)
def MyMain(H, W): random.seed(time.time()) environment = Environment(H, W, C.COL_DEFAULT) for AgName in list(C.AGENT_CARACT.keys()): AgCar = C.AGENT_CARACT[AgName] A = AgentGlobal(AgName, Agent(0, 0, AgName, *AgCar[0]), *AgCar[1:]) A.initEnv(environment, C.AGENT_INIT[AgName]) for PlName in list(C.PLANT_CARACT.keys()): PlCar = C.PLANT_CARACT[PlName] P = PlantGlobal(PlName, Plant(0, 0, PlName, PlCar[0]), *PlCar[1:]) P.initEnv(environment, C.PLANT_INIT[PlName]) pygame.init() screen = pygame.display.set_mode((C.PX_SIZE * W, C.PX_SIZE * H), pygame.DOUBLEBUF) screen.fill((0, 0, 0)) disp.DrawMatrix(environment.getColorMatrix(), screen, C.PX_SIZE) # wait till the window is closed clock = pygame.time.Clock() done = False ticker = 0 #used to express time passing in the environment while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True environment.tick(ticker) ticker += 1 disp.DrawMatrix(environment.getColorMatrix(), screen, C.PX_SIZE) # display the backbuffer pygame.display.flip() clock.tick(C.TICK)
def simulate(n_city, max_sims, N=5000): env = TornadoEnv(n_city, max_sims) os.makedirs('data/weather/sims/', exist_ok=True) fn = f'data/weather/opt_results/{n_city}_{max_sims}.pkl' res = joblib.load(f'data/weather/opt_results/20_50.pkl') agents = { 'LC': LiederPolicy([0, 1, res.x, 0, 1]), 'uniform': NoMetareasonPolicy() } # if n_city == 3 or max_sims < 25: # with Timer() as t: # Q, V, pi, info = solve(env) # V(env.init) # print(f'exact solution computed in {t.elapsed} seconds') # agents['optimal'] = FunctionPolicy(pi) for name, pol in agents.items(): np.random.seed(45) df = pd.DataFrame(Agent(env, pol).run_many(5000, pbar=False)) df['name'] = name df['n_city'] = n_city df['max_sims'] = max_sims df = df.set_index(['n_city', 'max_sims', 'name']) df.to_csv(f'data/weather/sims/{n_city}_{max_sims}_{name}.pkl') print(f'wrote {fn}')
def create_agents(self, region): agents = {} pops = self.sim.pops pop_cols = list(list(pops.values())[0].columns) if not self.sim.PARAMS['SIMPLIFY_POP_EVOLUTION']: list_of_possible_ages = pop_cols[1:] else: list_of_possible_ages = [0] + pop_cols[1:] loop_age_control = list(list_of_possible_ages) loop_age_control.pop(0) for age in loop_age_control: for gender in ['male', 'female']: code = region.id pop = pop_age_data(pops[gender], code, age, self.sim.PARAMS['PERCENTAGE_ACTUAL_POP']) for individual in range(pop): # Qualification # To see a histogram check test: qualification = self.qual(code) r_age = self.seed.randint( list_of_possible_ages[ (list_of_possible_ages.index(age, ) - 1)] + 1, age) money = self.seed.randrange(1, 34) month = self.seed.randrange(1, 13, 1) agent_id = self.gen_id() a = Agent(agent_id, gender, r_age, qualification, money, month) agents[agent_id] = a return agents
def test_SimpleReflexAgentProgram(): class Rule: def __init__(self, state, action): self.__state = state self.action = action def matches(self, state): return self.__state == state loc_A = (0, 0) loc_B = (1, 0) # create rules for a two state Vacuum Environment rules = [ Rule((loc_A, "Dirty"), "Suck"), Rule((loc_A, "Clean"), "Right"), Rule((loc_B, "Dirty"), "Suck"), Rule((loc_B, "Clean"), "Left") ] def interpret_input(state): return state # create a program and then an object of the SimpleReflexAgentProgram program = SimpleReflexAgentProgram(rules, interpret_input) agent = Agent(program) # create an object of TrivialVacuumEnvironment environment = TrivialVacuumEnvironment() # add agent to the environment environment.add_thing(agent) # run the environment environment.run() # check final status of the environment assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
def init_agents(self): """ Initialise the n_agents_arrival agents The simulation starts with two agents (with a total population of 40 individuals) settling in proximity to Anakena Beach in the North part of the island in the year t_0 = 800 A.D., following [Bahn2017]. We assume, they erect a settlement nearby within radius moving_radius_arrival """ for i in range(self.n_agents_arrival): # Arrival point is at Anakena Beach x, y = self.map.midpoints_map[self.map.anakena_ind_map] # Create an agent, x,y are at Anakena Beach, population p is the initial population over the initial agents ag = Agent(self, x, y, int(self.p_arrival / self.n_agents_arrival)) ag.cell = self.map.anakena_ind_map ag.cell_all = self.map.anakena_ind # For storage purposes: # Increase agent number in the cell of Anakena Beach by 1 # self.map.agNr_c[ag.cell] += 1 # Increase population size in the cell of Anakena Beach by the agent's population p self.map.pop_cell[ag.cell] += ag.p # increase the running agent indices (including dead agents) self.max_agent_index += 1 # Move the agent to a new location, within the radius specified by moving_radius_arrival around anakena ag.move(self.map.circ_inds_anakena) # Update tree preference and consequently resource requirements ag.update_t_pref() ag.calc_resource_req() # Add agent to schedule (list of agents) self.schedule.append(ag) return
def __init__(self, model_name, model): super().__init__(train=False) self.model_name = model_name self.model = model.model self.agent = Agent(self.projects, model) self.result = []
def reset(self, number_of_agents_in_list_local, size_of_environment_local): global number_of_agents_in_list, list_of_agents, list_of_agents_shuffled, size_of_environment, observation_space_calculated, initial_number_of_agents number_of_agents_in_list = number_of_agents_in_list_local size_of_environment = size_of_environment_local initial_number_of_agents = number_of_agents_in_list_local observation_space_calculated = size_of_environment_local number_of_agents = 0 # Reset the state of the environment to an initial state self.growth_rate = 1 self.environment = numpy.empty((size_of_environment,size_of_environment), dtype=numpy.object) self.environment_duplicate = numpy.empty((size_of_environment, size_of_environment), dtype=numpy.object) # Creating 250 agent objects and putting them into the list_of_agents array. for i in range(number_of_agents_in_list): #CHANGE TO 250 list_of_agents.append(Agent(i)) # Looping though the environment and adding random values between 0 and 4 # This will be sugar levels. for i in range(size_of_environment): for j in range(size_of_environment): self.environment[i, j] = random.randrange(0, 4) # Looping 250 times over the environment and randomly placing agents on 0 sugar cells. while(number_of_agents != number_of_agents_in_list): #CHANGE TO 250 x = random.randrange(size_of_environment) y = random.randrange(size_of_environment) if(self.environment[x, y] == 0): self.environment[x, y] = list_of_agents[number_of_agents].get_visual() self.environment_duplicate[x, y] = list_of_agents[number_of_agents] # Added the agent objects have been placed down randomly onto the environment from first to last. list_of_agents_shuffled[number_of_agents] = list_of_agents[number_of_agents] number_of_agents = number_of_agents + 1
def test_ModelBasedReflexAgentProgram(): class Rule: def __init__(self, state, action): self.__state = state self.action = action def matches(self, state): return self.__state == state loc_A = (0, 0) loc_B = (1, 0) # create rules for a two-state vacuum environment rules = [ Rule((loc_A, "Dirty"), "Suck"), Rule((loc_A, "Clean"), "Right"), Rule((loc_B, "Dirty"), "Suck"), Rule((loc_B, "Clean"), "Left") ] def update_state(state, action, percept, model): return percept # create a program and then an object of the ModelBasedReflexAgentProgram class program = ModelBasedReflexAgentProgram(rules, update_state, None) agent = Agent(program) # create an object of TrivialVacuumEnvironment environment = TrivialVacuumEnvironment() # add agent to the environment environment.add_thing(agent) # run the environment environment.run() # check final status of the environment assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
def __init__(self,location,shape,plot): self.location = location self.shape = shape self.plot = plot self.env = Environment(self.shape) self.agent = Agent() self.child = Child(self.env.state)
def test_Agent(): def constant_prog(percept): return percept agent = Agent(constant_prog) result = agent.program(5) assert result == 5
def build_agent(envs, activation=nn.ReLU(), **agent_args): return Agent( envs.observation_space.shape, envs.action_space, activation=activation, **agent_args, )
def test_TableDrivenAgent() : #create a table that would consist of all the possible states of the agent loc_A, loc_B = (0, 0), (1, 0) table = {((loc_A, 'Clean'),): 'Right', ((loc_A, 'Dirty'),): 'Suck', ((loc_B, 'Clean'),): 'Left', ((loc_B, 'Dirty'),): 'Suck', ((loc_A, 'Dirty'), (loc_A, 'Clean')): 'Right', ((loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck', ((loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck', ((loc_B, 'Dirty'), (loc_B, 'Clean')): 'Left', ((loc_A, 'Dirty'), (loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck', ((loc_B, 'Dirty'), (loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck' } # create an program and then an object of the TableDrivenAgent program = TableDrivenAgentProgram(table) agent = Agent(program) # create an object of the TrivialVacuumEnvironment environment = TrivialVacuumEnvironment() # add agent to the environment environment.add_thing(agent) # run the environment environment.run() # check final status of the environment assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
def test_TableDrivenAgent(): loc_A, loc_B = (0, 0), (1, 0) # table defining all the possible states of the agent table = { ((loc_A, 'Clean'), ): 'Right', ((loc_A, 'Dirty'), ): 'Suck', ((loc_B, 'Clean'), ): 'Left', ((loc_B, 'Dirty'), ): 'Suck', ((loc_A, 'Dirty'), (loc_A, 'Clean')): 'Right', ((loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck', ((loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck', ((loc_B, 'Dirty'), (loc_B, 'Clean')): 'Left', ((loc_A, 'Dirty'), (loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck', ((loc_B, 'Dirty'), (loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck' } # create an program and then an object of the TableDrivenAgent program = TableDrivenAgentProgram(table) agent = Agent(program) # create an object of TrivialVacuumEnvironment environment = TrivialVacuumEnvironment() # initializing some environment status environment.status = {loc_A: 'Dirty', loc_B: 'Dirty'} # add agent to the environment environment.add_thing(agent) # run the environment by single step everytime to check how environment evolves using TableDrivenAgentProgram environment.run(steps=1) assert environment.status == {(1, 0): 'Clean', (0, 0): 'Dirty'} environment.run(steps=1) assert environment.status == {(1, 0): 'Clean', (0, 0): 'Dirty'} environment.run(steps=1) assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
def testFollow(self): map_fn = "%s/data/directions/direction_floor_3/direction_floor_3_small_filled.cmf" % TKLIB_HOME cluster_fn = "%s/data/directions/direction_floor_3/skels/direction_floor_3_skel.pck" % TKLIB_HOME gtruth_tag_fn = "%s/data/directions/direction_floor_3/tags/df3_small_tags.tag" % TKLIB_HOME tagFile = tag_util.tag_file(gtruth_tag_fn, map_fn) tagFile.get_map() tagFile.get_tag_names() skeleton = carmen_map_skeletonizer.load(cluster_fn, map_fn) situation = Situation([Agent("figure", [(0, (25.400000378489494, 9.0000001341104507, 0.0)), (1, (25.400000378489494, 9.200000137090683, -1.5707963267948966)), (2, (25.400000378489494, 9.4000001400709152, -1.5707963267948966)), (3, (25.400000378489494, 9.6000001430511475, -1.5707963267948966)), (4, (25.400000378489494, 9.8000001460313797, -1.5707963267948966)), (5, (25.200000375509262, 10.000000149011612, -0.78539816339744828)), (6, (25.200000375509262, 10.200000151991844, -1.5707963267948966)), (7, (25.400000378489494, 10.400000154972076, -2.3561944901923448)), (8, (25.400000378489494, 10.600000157952309, -1.5707963267948966)), (9, (25.400000378489494, 10.800000160932541, -1.5707963267948966)), (10,(25.600000381469727, 11.000000163912773, -2.3561944901923448)), (11,(25.600000381469727, 11.000000163912773, 0.0))]), Agent("landmark", [(0, (25.200000375509262, 11.800000175833702, 0.0)), (1, (25.400000378489494, 12.000000178813934, -2.3561944901923448)), (2, (25.400000378489494, 12.200000181794167, -1.5707963267948966)), (3, (25.400000378489494, 12.400000184774399, -1.5707963267948966)), (4, (25.200000375509262, 12.600000187754631, -0.78539816339744828)), (5, (25.200000375509262, 12.800000190734863, -1.5707963267948966)), (6, (25.200000375509262, 13.000000193715096, -1.5707963267948966)), (7, (25.200000375509262, 13.200000196695328, -1.5707963267948966)), (8, (25.00000037252903, 13.40000019967556, -0.78539816339744828)), (9, (24.800000369548798, 13.600000202655792, -0.78539816339744828)), (10,(24.600000366568565, 13.800000205636024, -0.78539816339744828)), (11,(24.600000366568565, 13.800000205636024, 0.0))])], tagFile, skeleton) classifiers = trainer_pacman.versionOne() followClassifier = classifiers["follow"] followClassifier.classify(situation) self.assertTrue(followClassifier.pTrue > 0.5)
def run(wss=None, steps=None, seed=None): l.debug('Running random_mom_and_calf in', str(steps), 'steps with seed', seed) steps = int(steps) if steps else 10 random.seed(seed) options = OPTIONS options.wss = wss sea = Sea(options) mom = Agent(mom_program, 'mom') calf = Agent(calf_program, 'calf') sea.add_thing(mom, mom_start_pos) sea.add_thing(calf, calf_start_pos) sea.run(steps)
def __init__(self, env, eval_node, expansion_cost=0.01): super().__init__() self.env = env self.expansion_cost = -abs(expansion_cost) # This guy interacts with the external environment, what a chump! self.surface_agent = Agent() self.surface_agent.register(self.env) self.eval_node = eval_node
def __init__(self, agents, update_when_receiving=False): self.agents = agents self.last_market_price = 0.5 self.market_price = 0.5 self.best_belief = 0.5 self.idx_agent_receiving_evidence = -1 #This is always set to the last agent to receive evidence self.god = Agent() self.exchange = Exchange() self.update_when_receiving = update_when_receiving #Whlie receiving evidence, does the agent update belief based on change in market price?
def create_agents(self): agents = [] for _ in range(self.config.num_threads): memory = ReplayMemory(self.config) agent = Agent(self.policy_network(), memory, self.summary, self.config) agents.append(agent) return agents
def evaluate(policy, envs): agent = Agent() def run_env(policy, env): agent.register(env) agent.register(policy) tr = agent.run_episode() return {'util': tr['return'], 'observations': len(tr['actions']) - 1} return pd.DataFrame(run_env(policy, env) for env in envs)
def __init__(self, board_size): self.p = np.zeros([board_size, board_size]) self.p_size = board_size * board_size self.visit = np.zeros([board_size, board_size]) self.visit_size = board_size * board_size self.moves = [] self.values = [] self.agent = Agent(board_size)
def test(self): import ipdb ipdb.set_trace() obs = self.env.reset() F = CausalEntropicForce() agent = Agent('test') obs = Observation(obs, agent) X_0 = Macrostate(env=self.env, x_0=obs) MaximizeCausalForce.solve(F, X_0)
def create_agent(params, agent_id, env): # initialize networks and load weights net = DQN(env.observation_space.shape, env.action_space.n, params["DEVICE"]).to(device) net.load_state_dict(torch.load(params["WEIGHTS"])) # initialize agent agent = Agent(agent_id, env, net, params) return agent
def main(): G = makegraphs.starGraph(5) agentlist = {} #id num, utility, endowment, prices, subplans, r agent1 = Agent(1, np.array((10, 1)), np.array((0, 1)), np.array((10, 10)), np.array([[0, 0], [3, 0]]), np.array([0, 1])) agentlist[1] = agent1 agent2 = Agent(2, np.array((10, 10)), np.array((0, 0)), np.array((10, 10)), np.array([[0, 3], [0, 0]]), np.array([1, 1])) agentlist[2] = agent2 agent3 = Agent(3, np.array((1, 10)), np.array((1, 0)), np.array((10, 10)), np.array([[0, 0], [3, 0]]), np.array([1, 0])) agentlist[3] = agent3 agent4 = Agent(4, np.array((10, 10)), np.array((0, 0)), np.array((10, 10)), np.array([[0, 3], [0, 0]]), np.array([1, 1])) agentlist[4] = agent4 agent5 = Agent(5, np.array((1, 10)), np.array((1, 0)), np.array((10, 10)), np.array([[0, 0], [3, 0]]), np.array([1, 0])) agentlist[5] = agent5 nx.set_node_attributes(G, 'agentprop', agentlist) check_eq = False num_rounds = 0 while (check_eq == False): print("Num rounds ", num_rounds) agents_old = copy.deepcopy(nx.get_node_attributes(G, 'agentprop')) agents_new = dynamics.changePlans(G) check_eq = dynamics.checkEquilibrium(agents_old, agents_new) nx.set_node_attributes(G, 'agentprop', agents_new) filename = 'samplefile' + str(num_rounds) + '.png' #dynamics.drawNetwork(G, 'agentprop', filename) num_rounds += 1 print(num_rounds - 1) nx.set_node_attributes(G, 'agentprop', agentlist)
def birth(sim): """Similar to create agent, but just one individual""" age = 0 qualification = int(sim.seed.gammavariate(3, 3)) qualification = [qualification if qualification < 21 else 20][0] money = sim.seed.randrange(20, 40) month = sim.seed.randrange(1, 13, 1) gender = sim.seed.choice(['Male', 'Female']) sim.total_pop += 1 a = Agent((sim.total_pop - 1), gender, age, qualification, money, month) return a
def add_agent(self, agent_dir, name, train=False): assert len(self.agents) < s.MAX_AGENTS # if self.args.single_process: backend = SequentialAgentBackend(train, name, agent_dir) # else: # backend = ProcessAgentBackend(train, name, agent_dir) backend.start() agent = Agent(self.colors.pop(), name, agent_dir, train, backend) self.agents.append(agent)
def __init__(self, make_video=False, replay=False, live_preview=False): self._actions = self.ACTIONS self.ROWS, self.COLS = s.ROWS, s.COLS self._live_preview = False args = namedtuple("args", [ "no_gui", "fps", "log_dir", "turn_based", "update_interval", "save_replay", "replay", "make_video", "continue_without_training" ]) args.continue_without_training = False args.save_replay = False args.log_dir = "agent_code/koetherminator" if make_video: # not working yet! args.no_gui = False args.make_video = True # obviously gotta change to True if ffmpeg issue is fixed args.fps = 15 args.update_interval = 0.1 args.turn_based = False elif live_preview: self._live_preview = True args.no_gui = False args.make_video = False args.fps = 15 args.update_interval = 1 args.turn_based = False else: args.no_gui = True args.make_video = False if replay: args.save_replay = True # agents = [("user_agent", True)] + [("rule_based_agent", False)] * (s.MAX_AGENTS-1) agents = [("user_agent", True) ] + [("peaceful_agent", False)] * (s.MAX_AGENTS - 1) if not args.no_gui: pygame.init() self._world = BombeRLeWorld(args, agents) self._agent = self._world.agents[0] rb_agent_cfg = {"color": "blue", "name": "rule_based_agent"} rb_agent_backend = SequentialAgentBackend(False, rb_agent_cfg['name'], rb_agent_cfg['name']) rb_agent_backend.start() self._rb_agent = Agent(rb_agent_cfg['color'], rb_agent_cfg['name'], rb_agent_cfg['name'], train=False, backend=rb_agent_backend)