Esempio n. 1
0
    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)
Esempio n. 2
0
    def registerInitialState(self, gameState: 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 5 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.
        '''
        self.minFoodxy = (0, 0)

        self.gridWall = gameState.getWalls()
        self.home = findHome(self.gridWall,
                             gameState.getAgentPosition(self.index))

        if (self.index in gameState.getRedTeamIndices()):
            # left side
            self.mapMiddlePoint = (self.gridWall.width // 2 - 2,
                                   self.gridWall.height // 2)
            self.foodInMouth = 0
        else:
            # right side
            self.mapMiddlePoint = (self.gridWall.width // 2 + 2,
                                   self.gridWall.height // 2)
            self.foodInMouth = 0