def step_move(self): # set line of sight of movers agent = self.agent for guard in self.guards: if (self.libvis.can_see(agent.get_coord(),guard.get_coord()) and coord_math.distc(agent.get_coord(),guard.get_coord()) < self.env_values.agent_linesight): agent.on_guard_sight(guard.get_coord()) if self.agent.NEEDS_EXPLORING_DATA: agent_coord = self.agent.get_coord() for ray in coord_math.get_rays(agent_coord,57,self.env_values.agent_linesight): if not self.libvis.can_see(agent_coord,ray): self.agent.on_object_sight(find_block_intersect(self.libvis,agent_coord,ray),True) else: self.agent.on_object_sight(ray,False) # move movers for mover in self.movers: move_dir = mover.move() while True: move_dist = coord_math.distc((0,0),move_dir) if move_dist > 1.0: move_dir = coord_math.scalar_mul(move_dir,1.0/move_dist) #print(move_dir) src_coord = mover.get_coord() dest_coord = coord_math.add(src_coord,move_dir) if not self.libvis.can_see(src_coord,dest_coord): print("mover at {} tried to move though wall!".format(src_coord)) #move_dir = (random.random()*2,random.random()*2) #exit(0) break else: break mover.moved(move_dir) # check if agent is found by guard agent_loc = self.agent.get_coord() for guard in self.guards: guard_loc = guard.get_coord() if (coord_math.distc(agent_loc,guard_loc) < self.env_values.guard_linesight and self.libvis.can_see(agent_loc,guard_loc)): self.agent_found = True #print(agent_loc) #print(guard_loc) #print(coord_math.distc(agent_loc,guard_loc)) # check if agent has collected reward, and execute collection new_reward_list = [] for rew_point in self.rewards: if self.libvis.can_see(agent_loc,rew_point): if coord_math.distc(agent_loc,rew_point) < self.env_values.agent_linesight: self.agent.on_reward_sight(rew_point) if coord_math.distc(agent_loc,rew_point) < self.env_values.reward_collect_radius: self.reward_collected += 1 self.agent.on_reward_collected(rew_point) else: new_reward_list.append(rew_point) else: new_reward_list.append(rew_point) self.rewards = new_reward_list
def negative_circle(cen,map_info,radius): poly = [] poly.append((map_info.width-1,0)) for point in coord_math.get_rays(cen,29,radius): poly.append(point) poly.append(coord_math.add((radius,0),cen)) poly.append((map_info.width-1,0)) poly.append((map_info.width-1,map_info.height-1)) poly.append((0,map_info.height-1)) poly.append((0,0)) return poly
def get_sight_locs(rad, cen, static_map): num_rays = int(rad * 3) ax, ay = cen sight_locs = set() for rx, ry in coord_math.get_rays(cen, num_rays, rad): sight_coords = coord_math.raytrace2dgrid(ax, ay, rx, ry) for sx, sy in sight_coords: if static_map[(sx, sy)] != STATIC_OPEN: break sight_locs.add((sx, sy)) return (sight_locs)
def communicate_line_sight(self,agent): NUM_RAYS = self.agent_linesight*8 NUM_CHECK_ON_RAY = self.agent_linesight*2 ray_results = [] for tx,ty in coord_math.get_rays(self.agent.pos(),NUM_RAYS,self.agent_linesight): obj,coord = self.find_first_el_blocked(agent.x,agent.y,tx,ty,NUM_CHECK_ON_RAY) #print(obj) ray_results.append((obj,(coord))) ray_results += self.agent_sees_objects() recentered = [(obj,self.agent.recenter_coord(coord)) for obj,coord in ray_results] return recentered