def registerInitialState(self, gameState: GameState): walls = gameState.getWalls() maxX, maxY = walls.asList()[-1] limitRegion = math.ceil(maxX/2) + 1 if gameState.isOnRedTeam(self.index): limitRegion -= 3 for y in range(0, maxY): if not gameState.hasWall(limitRegion, y): self.openBorder.append(Position(limitRegion, y)) self.enemiesIndices = gameState.getRedTeamIndices() if gameState.isOnRedTeam(self.index): self.enemiesIndices = gameState.getBlueTeamIndices() # for pos in self.openBorder: # print(pos) # print("\n") CaptureAgent.registerInitialState(self, gameState)
def chooseAction(self, gameState: GameState) -> str: ownIndex = self.index ownPosition = gameState.getAgentPosition(ownIndex) if self.firstPatrolDone: possibleChokePoints = [] grid = gameState.getWalls() for i in range(len(grid[0]) - 1): if not gameState.hasWall(self.mapMiddlePoint[0], i): possibleChokePoints.append((self.mapMiddlePoint[0], i)) self.topChokePoint = possibleChokePoints[0] self.bottomChokePoint = possibleChokePoints[ len(possibleChokePoints) - 1] direction = getDirectionAndDistance(ownPosition, self.topChokePoint, gameState)[1] self.firstPatrolDone = False else: if self.goingUp: direction = getDirectionAndDistance(ownPosition, self.topChokePoint, gameState)[1] distance = getDirectionAndDistance(ownPosition, self.topChokePoint, gameState)[0] if distance == 0: self.goingUp = False else: direction = getDirectionAndDistance(ownPosition, self.bottomChokePoint, gameState)[1] distance = getDirectionAndDistance(ownPosition, self.bottomChokePoint, gameState)[0] if distance == 0: self.goingUp = True return direction