def setTeam(self, gameState): if self.red: return CaptureAgent.registerTeam(self, gameState.getRedTeamIndices()) else: return CaptureAgent.registerTeam(self, gameState.getBlueTeamIndices())
def registerInitialState(self, gameState): CaptureAgent.registerInitialState(self, gameState) if self.red: CaptureAgent.registerTeam(self, gameState.getRedTeamIndices()) else: CaptureAgent.registerTeam(self, gameState.getBlueTeamIndices()) self.goToCenter(gameState)
def registerInitialState(self, gameState): """ This method handles the initial setup of the agent to populate useful fields (such as what team we're on). A distanceCalculator instance caches the maze distances between each pair of positions, so your agents can use: self.distancer.getDistance(p1, p2) IMPORTANT: This method may run for at most 15 seconds. """ ''' Make sure you do not delete the following line. If you would like to use Manhattan distances instead of maze distances in order to save on initialization time, please take a look at CaptureAgent.registerInitialState in captureAgents.py. ''' CaptureAgent.registerInitialState(self, gameState) ''' Your initialization code goes here, if you need any. ''' if self.red: CaptureAgent.registerTeam(self, gameState.getRedTeamIndices()) else: CaptureAgent.registerTeam(self, gameState.getBlueTeamIndices()) #Agents try to go to center with top or bottom bias self.goToCenter(gameState)
def registerInitialState(self, gameState): CaptureAgent.registerInitialState(self, gameState) # Sets if agent is on red team or not if self.red: CaptureAgent.registerTeam(self, gameState.getRedTeamIndices()) else: CaptureAgent.registerTeam(self, gameState.getBlueTeamIndices()) # Get how large the game space is # Legal positions are positions without walls height = gameState.data.layout.height width = gameState.data.layout.width self.legalPositions = [] for y in range(1, height): for x in range(1, width): if not gameState.hasWall(x, y): self.legalPositions.append((x, y)) global beliefs beliefs = [util.Counter()] * gameState.getNumAgents() # All beliefs begin with the agent at its inital position for i, val in enumerate(beliefs): if i in self.getOpponents(gameState): beliefs[i][gameState.getInitialAgentPosition(i)] = 1.0 # Agents inital move towards the centre with a bias for either the top or the bottom self.goToCenter(gameState)
def registerInitialState(self, gameState): """ This method handles the initial setup of the agent to populate useful fields (such as what team we're on). A distanceCalculator instance caches the maze distances between each pair of positions, so your agents can use: self.distancer.getDistance(p1, p2) IMPORTANT: This method may run for at most 15 seconds. """ ''' Make sure you do not delete the following line. If you would like to use Manhattan distances instead of maze distances in order to save on initialization time, please take a look at CaptureAgent.registerInitialState in captureAgents.py. ''' CaptureAgent.registerInitialState(self, gameState) ''' Your initialization code goes here, if you need any. ''' if self.red: CaptureAgent.registerTeam(self, gameState.getRedTeamIndices()) else: CaptureAgent.registerTeam(self, gameState.getBlueTeamIndices()) #Agents try to go to center with top or bottom bias self.goToCenter(gameState)
def registerIndices(self, gameState): self.redIndices = gameState.getRedTeamIndices() self.blueIndices = gameState.getBlueTeamIndices() if not self.red: CaptureAgent.registerTeam(self, self.blueIndices) else: CaptureAgent.registerTeam(self, self.redIndices)
def registerInitialState(self, gameState): if self.red: CaptureAgent.registerTeam(self, gameState.getRedTeamIndices()) else: CaptureAgent.registerTeam(self, gameState.getBlueTeamIndices()) self.start = gameState.getAgentPosition(self.index) CaptureAgent.registerInitialState(self, gameState) self.legalPositions = gameState.data.layout.walls.asList(False) self.positionBeliefs = {} for opponent in self.getOpponents(gameState): self.initialBeliefsDistributions(opponent)
def registerInitialState(self, gameState): CaptureAgent.registerInitialState(self, gameState) # Judge team color if self.red: CaptureAgent.registerTeam(self, gameState.getRedTeamIndices()) else: CaptureAgent.registerTeam(self, gameState.getBlueTeamIndices()) # Get the board space self.x = gameState.data.layout.width self.y = gameState.data.layout.height # Get possible positions when there are no walls self.legalPositions = [] for p in gameState.getWalls().asList(False): if p[1] > 1: self.legalPositions.append(p) self.walls = list(gameState.getWalls()) self.chokes = [] if self.red: coolDistance = -3 else: coolDistance = 4 for i in range(self.y): if not self.walls[self.x / 2 + coolDistance][i]: self.chokes.append(((self.x / 2 + coolDistance), i)) # Index of each Agent if self.index == max( gameState.getRedTeamIndices()) or self.index == max( gameState.getBlueTeamIndices()): x, y = self.chokes[3 * len(self.chokes) / 4] else: x, y = self.chokes[1 * len(self.chokes) / 4] self.goalSetting = (x, y) # Get enemies/opponents self.enemies = self.getOpponents(gameState) # get probabilities of enemies global beliefs beliefs = [util.Counter()] * gameState.getNumAgents() for i, val in enumerate(beliefs): if i in self.enemies: beliefs[i][gameState.getInitialAgentPosition(i)] = 1 self.runAgent(gameState)
def registerInitialState(self, gameState): """ This method handles the initial setup of the agent to populate useful fields (such as what team we're on). A distanceCalculator instance caches the maze distances between each pair of positions, so your agents can use: self.distancer.getDistance(p1, p2) IMPORTANT: This method may run for at most 15 seconds. """ ''' Make sure you do not delete the following line. If you would like to use Manhattan distances instead of maze distances in order to save on initialization time, please take a look at CaptureAgent.registerInitialState in captureAgents.py. ''' CaptureAgent.registerInitialState(self, gameState) ''' Your initialization code goes here, if you need any. ''' # Get the Size of the Map width, height = gameState.data.layout.width, gameState.data.layout.height # Get the color of the team if self.red: CaptureAgent.registerTeam(self, gameState.getRedTeamIndices()) else: CaptureAgent.registerTeam(self, gameState.getBlueTeamIndices()) # Get all the move position in the map self.legalMovePositions = [p for p in gameState.getWalls().asList(False)] self.walls = list(gameState.getWalls()) # possible is used to guess the position of the enemy global possible possible = [util.Counter() for i in range(gameState.getNumAgents())] # possible start from the initial position for i, value in enumerate(possible): if i in self.getOpponents(gameState): # Get the initial position of the agent,set the possibility to 1 possible[i][gameState.getInitialAgentPosition(i)] = 1.0 # Get the boundary position for i in range(height): if not self.walls[width // 2][i]: self.boundary.append((width//2, i)) # At the start of the game, two agent go direct to the center self.goToCenter(gameState)
def registerInitialState(self, gameState): CaptureAgent.registerInitialState(self, gameState) if self.red: CaptureAgent.registerTeam(self, gameState.getRedTeamIndices()) else: CaptureAgent.registerTeam(self, gameState.getBlueTeamIndices()) self.width, self.height = gameState.getWalls().asList()[-1] self.legalPositions = [p for p in gameState.getWalls().asList(False) if p[1] > 1] self.walls = list(gameState.getWalls()) if self.red: offset = -3 else: offset = 4 self.chokes = [] for a in range(self.height): if not self.walls[self.width/2+offset][a]: self.chokes.append(((self.width/2+offset), a)) if self.index == max(gameState.getRedTeamIndices()) or self.index == max(gameState.getBlueTeamIndices()): h, v = self.chokes[3*len(self.chokes)/4] else: h, v = self.chokes[1*len(self.chokes)/4] self.goal = (h, v) global beliefs beliefs = [util.Counter()] * gameState.getNumAgents() for i, val in enumerate(beliefs): if i in self.getOpponents(gameState): beliefs[i][gameState.getInitialAgentPosition(i)] = 1.0 self.goMid(gameState)
def registerInitialState(self, gameState): """ This method handles the initial setup of the agent to populate useful fields (such as what team we're on). A distanceCalculator instance caches the maze distances between each pair of positions, so your agents can use: self.distancer.getDistance(p1, p2) IMPORTANT: This method may run for at most 15 seconds. """ ''' Make sure you do not delete the following line. If you would like to use Manhattan distances instead of maze distances in order to save on initialization time, please take a look at CaptureAgent.registerInitialState in captureAgents.py. ''' CaptureAgent.registerInitialState(self, gameState) ''' Your initialization code goes here, if you need any. ''' # Sets if agent is on red team or not if self.red: CaptureAgent.registerTeam(self, gameState.getRedTeamIndices()) else: CaptureAgent.registerTeam(self, gameState.getBlueTeamIndices()) # Get how large the game space is self.x, self.y = gameState.getWalls().asList()[-1] # Legal positions are positions without walls self.legalPositions = [p for p in gameState.getWalls().asList(False) if p[1] > 1] self.walls = list(gameState.getWalls()) # Chokes contains choke points on our side of game space self.chokes = [] # Offsets for how far away from middle our ghosts should sit if an invader is detected # but cannot be seen for some reason if self.red: xAdd = -3 else: xAdd = 4 # Find all choke points of interest for i in range(self.y): if not self.walls[self.x/2+xAdd][i]: self.chokes.append(((self.x/2+xAdd), i)) if self.index == max(gameState.getRedTeamIndices()) or self.index == max(gameState.getBlueTeamIndices()): x, y = self.chokes[3*len(self.chokes)/4] else: x, y = self.chokes[1*len(self.chokes)/4] self.goalTile = (x, y) # beliefs is used to infere the position of enemy agents using noisey data global beliefs beliefs = [util.Counter()] * gameState.getNumAgents() # All beliefs begin with the agent at its inital position for i, val in enumerate(beliefs): if i in self.getOpponents(gameState): beliefs[i][gameState.getInitialAgentPosition(i)] = 1.0 #Agents inital move towards the centre with a bias for either the top or the bottom self.goToCenter(gameState)
def registerInitialState(self, gameState): """ This method handles the initial setup of the agent to populate useful fields (such as what team we're on). A distanceCalculator instance caches the maze distances between each pair of positions, so your agents can use: self.distancer.getDistance(p1, p2) IMPORTANT: This method may run for at most 15 seconds. """ ''' Make sure you do not delete the following line. If you would like to use Manhattan distances instead of maze distances in order to save on initialization time, please take a look at CaptureAgent.registerInitialState in captureAgents.py. ''' CaptureAgent.registerInitialState(self, gameState) ''' Your initialization code goes here, if you need any. ''' if self.red: CaptureAgent.registerTeam(self, gameState.getRedTeamIndices()) else: CaptureAgent.registerTeam(self, gameState.getBlueTeamIndices()) self.legalPositions = [] for p in gameState.getWalls().asList(False): if p[1] > 1: self.legalPositions.append(p) self.x, self.y = gameState.getWalls().asList()[-1] self.walls = list(gameState.getWalls()) # self.chokes = [] # if self.red: # xAdd = -3 # else: # xAdd = 4 # for i in range(self.y): # if not self.walls[self.x/2 + xAdd][i]: # self.chokes.append(((self.x/2 + xAdd), i)) # if self.index == max(gameState.getRedTeamIndices()) or self.index == max(gameState.getBlueTeamIndices()): # x, y = self.chokes[3*len(self.chokes)/4] # else: # x, y = self.chokes[1*len(self.chokes)/4] # self.goalTile = (x, y) global beliefs beliefs = [util.Counter()] * gameState.getNumAgents() # All beliefs begin with the agent at its inital position for i, val in enumerate(beliefs): if i in self.getOpponents(gameState): beliefs[i][gameState.getInitialAgentPosition(i)] = 1.0 self.goToCenter(gameState)