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: """ Picks among legal actions randomly. """ ownIndex = self.index ownPosition = gameState.getAgentPosition(ownIndex) if (ownIndex in gameState.getBlueTeamIndices()): if (self.minFoodxy == gameState.getAgentPosition(self.index)): self.foodInMouth += 1 if self.foodInMouth < 8 and self.findNbFoodLeft( gameState.getRedFood(), gameState) > 0: direction = self.findClosestFoodDirection( gameState.getRedFood(), gameState) else: direction = getDirectionAndDistance(ownPosition, self.home, gameState)[1] if ownPosition == self.home: self.foodInMouth = 0 else: if (self.minFoodxy == gameState.getAgentPosition(self.index)): self.foodInMouth += 1 if self.foodInMouth < 8 and self.findNbFoodLeft( gameState.getRedFood(), gameState) > 0: direction = self.findClosestFoodDirection( gameState.getBlueFood(), gameState) else: direction = getDirectionAndDistance(ownPosition, self.home, gameState)[1] if ownPosition == self.home: self.foodInMouth = 0 return direction