def reset_world(self, world, epoch): world.origin = np.array([world.size / 2, world.size / 2]) # agent colors for i, agent in enumerate(world.agents): if agent.adversary: # agent.color = world.predator_colors[i] agent.color = np.array([0.85, 0.35, 0.35]) else: agent.color = np.array([0.35, 0.85, 0.35]) # properties for landmarks for i, landmark in enumerate(world.landmarks): landmark.color = np.array([0.25, 0.25, 0.25]) # generate predators in random circle of random radius with random angles redraw = True while redraw: # draw location for prey prey_pt = world.origin + np.random.normal(0.0, 0.0001, size=2) # prey_pt = np.array([0., 0.]) # draw predator locations if world.init_pos_curriculum: world.pred_init_distance = world.pred_init_distance_end - ( world.pred_init_distance_end - world.pred_init_distance_start) * max( (world.decay - epoch) / world.decay, 0.0) init_pts = [ world.origin + np.random.normal(0.0, world.pred_init_distance, size=2) for _ in range(self.n_preds) ] else: init_pts = [ np.random.uniform(0.0, world.size, size=2) for _ in range(self.n_preds) ] # init_pts = [np.array([5., 3.]), np.array([2., 4.73205081]), np.array([1.99999999, 1.2679492 ])] # init_pts = [np.array([7., 5.]), np.array([4., 6.73205081]), np.array([3.99999999, 3.2679492 ])] # init_pts = [np.array([1., 3.]), np.array([3., 5.]), np.array([5., 3])] # ensure predators not initialized on top of prey redraw = overlaps(prey_pt, init_pts, world.size, threshold=0.5) # set initial states init_pts.append(prey_pt) for i, agent in enumerate(world.agents): agent.active = True agent.captured = False # agents can move beyond confines of camera image --> need to adjust coords accordingly agent.state.coords = init_pts[i] agent.state.p_pos = agent.state.coords % world.size agent.state.p_vel = np.zeros(world.dim_p) agent.state.theta = 0.0 agent.state.c = np.zeros(world.dim_c)
def reset_world(self, world): world.origin = np.array([world.size/2, world.size/2]) print('world size = {}'.format(world.size)) print('pred vel = {}'.format(world.agents[0].max_speed)) print('prey vel = {}'.format(world.agents[-1].max_speed)) print('tax = {}'.format(world.tax)) print('action penalty = {}'.format(world.action_penalty)) print('capture reward = {}'.format(world.cap_reward)) # agent color for i, agent in enumerate(world.agents): if agent.adversary: agent.color = world.predator_colors[i] else: agent.color = np.array([0.35, 0.85, 0.35]) # properties for landmarks for i, landmark in enumerate(world.landmarks): landmark.color = np.array([0.25, 0.25, 0.25]) # generate predators in random circle of random radius with random angles redraw = True while redraw: # draw location for prey prey_pt = world.origin + np.random.normal(0.0, 0.0001, size=2) # draw predator locations init_pts = [np.random.uniform(0.0, world.size, size=2) for _ in range(self.n_preds)] # init_pts = [np.array([1.5, 1.5]) + np.random.normal(0.0, 0.01, size=2), np.array([1.5, 1.5])+np.random.normal(0.0, 0.01, size=2), np.array([1.5, 1.5])] # ensure predators not initialized on top of prey redraw = overlaps(prey_pt, init_pts, world.size, threshold=0.5) # set initial states init_pts.append(prey_pt) for i, agent in enumerate(world.agents): agent.active = True agent.captured = False # agents can move beyond confines of camera image --> need to adjust coords accordingly agent.state.coords = init_pts[i] agent.state.p_pos = agent.state.coords % world.size agent.state.p_vel = np.zeros(world.dim_p) agent.state.theta = 0.0 agent.state.c = np.zeros(world.dim_c)