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
def getMyFood(self, gameState: GameState): if gameState.isOnRedTeam(self.index): return gameState.getRedFood() return gameState.getBlueFood()