def CreatePredatorLocations(self, spawnArea, agentCoord, goalCoord, occlusions=[]): agentSurroundCoordinates = [] for x in range(agentCoord.X - spawnArea, agentCoord.X + spawnArea + 1): for y in range(agentCoord.Y - spawnArea, agentCoord.Y + spawnArea + 1): if (ManhattanDistance(COORD(x, y), agentCoord) <= 2 * spawnArea): agentSurroundCoordinates.append(COORD(x, y)) agentSurroundCoordinates.append(goalCoord) agentSurroundCoordinates.extend(occlusions) predatorLocations = [] for y in range(self.YSize): for x in range(self.XSize): newLocation = COORD(x, y) if newLocation in agentSurroundCoordinates: continue predatorLocations.append(newLocation) return predatorLocations
def GetPredatorLocations(): #np.random.seed(1) tempGame = Game(XSize, YSize) agentSurroundCoordinates = [] for x in range(tempGame.AgentHome.X - ExperimentParams.SpawnArea, tempGame.AgentHome.X + ExperimentParams.SpawnArea + 1): for y in range(tempGame.AgentHome.Y - ExperimentParams.SpawnArea, tempGame.AgentHome.Y + ExperimentParams.SpawnArea + 1): if (ManhattanDistance(COORD(x, y), tempGame.AgentHome) <= 2 * ExperimentParams.SpawnArea): agentSurroundCoordinates.append(COORD(x, y)) agentSurroundCoordinates.append(tempGame.GoalPos) allPredatorLocations = [ COORD(x, y) for x in range(0, XSize) for y in range(0, YSize) ] validSpawnLocations = list( set(allPredatorLocations) - set(agentSurroundCoordinates)) predatorIndices = random.sample(range(0, len(validSpawnLocations)), ExperimentParams.NumRuns) predatorLocations = [validSpawnLocations[ind] for ind in predatorIndices] return predatorLocations
def VisualArea(self, coord, observationDirection, visualRange, pureVision=False): RadiusCoordinates = [] for x in range(coord.X - visualRange, coord.X + visualRange + 1): for y in range(coord.Y - visualRange, coord.Y + visualRange + 1): if (ManhattanDistance(COORD(x, y), coord) <= 2 * visualRange): RadiusCoordinates.append(COORD(x, y)) RangeCoordinates = [] RadiusCoordinates = np.flipud( np.reshape(np.array(RadiusCoordinates), (2 * visualRange + 1, 2 * visualRange + 1)).transpose()) if observationDirection == COMPASS.NORTH: RangeCoordinates = self.VisualCone(RadiusCoordinates, visualRange) elif observationDirection == COMPASS.EAST: RadiusCoordinates = np.flipud(RadiusCoordinates.transpose()) RangeCoordinates = self.VisualCone(RadiusCoordinates, visualRange) elif observationDirection == COMPASS.WEST: RadiusCoordinates = RadiusCoordinates.transpose() RangeCoordinates = self.VisualCone(RadiusCoordinates, visualRange) elif observationDirection == COMPASS.SOUTH: RadiusCoordinates = np.flipud(RadiusCoordinates) RangeCoordinates = self.VisualCone(RadiusCoordinates, visualRange) assert (RangeCoordinates) if pureVision: return RangeCoordinates for a in range(4): sidePos = coord + Compass[a] if sidePos not in RangeCoordinates: RangeCoordinates.append(sidePos) return RangeCoordinates