Пример #1
0
    def registerInitialState(self, gameState):
        self.red = gameState.isOnRedTeam(self.index)
        self.distancer = distanceCalculator.Distancer(
            gameState.getInitialLayout())
        self.distancer.getMazeDistances()

        abc = gameState.getInitialLayout()
        width = abc.getWidth()
        height = abc.getHeight()
        midpoint = int(width / 2)
        global midpointTiles
        midpointTiles = []
        midpointTiles.append((0, 0))
        redPenalty = 1
        redPenalty2 = 0
        if self.red:
            redPenalty = -1
            redPenalty2 = -1

        for i in range(1, height - 1):
            counter = 0
            while abc.isWall(
                (midpoint + redPenalty2 + ((2 + counter) * redPenalty), i)):
                counter += 1
            midpointTiles.append(
                ((midpoint + redPenalty2 + ((2 + counter) * redPenalty)), i))
Пример #2
0
    def registerInitialState(self, gameState):
        """
        This method handles the initial setup of the agent and populates useful fields,
        such as the team the agent is on and the `pacai.core.distanceCalculator.Distancer`.
        """

        self.red = gameState.isOnRedTeam(self.index)
        self.distancer = distanceCalculator.Distancer(
            gameState.getInitialLayout())

        self.distancer.getMazeDistances()
Пример #3
0
    def registerInitialState(self, gameState):
        self.red = gameState.isOnRedTeam(self.index)
        self.distancer = distanceCalculator.Distancer(
            gameState.getInitialLayout())
        self.distancer.getMazeDistances()

        abc = gameState.getInitialLayout()
        width = abc.getWidth()
        height = abc.getHeight()
        midpoint = int(width / 2)
        global midpointTiles2
        global targetTile
        global maxDistance
        global totalCapsules
        global totalFood
        totalFood = len(self.getFood(gameState).asList())
        totalCapsules = len(self.getCapsules(gameState))
        midpointTiles2 = []
        redPenalty = 1
        redPenalty2 = 0
        if self.red:
            redPenalty = -1
            redPenalty2 = -1
        longestPath = 0
        shortestPath = float("inf")
        for i in range(1, height - 1):
            if not abc.isWall((midpoint + redPenalty2, i)) and not abc.isWall(
                (midpoint + redPenalty2 + (redPenalty * -1), i)):
                midpointTiles2.append(((midpoint + redPenalty2), i))
                temp = self.getMazeDistance(
                    (midpoint + redPenalty2, i),
                    gameState.getAgentState(self.index).getPosition())
                if shortestPath > temp:
                    shortestPath = temp
                    targetTile = len(midpointTiles2) - 1
                if longestPath < temp:
                    maxDistance = temp

        # print("Initial Target Tile",targetTile)
        targetTile = 0
        print(targetTile)

        print(midpointTiles2)
Пример #4
0
    def registerInitialState(self, gameState):
        self.red = gameState.isOnRedTeam(self.index)
        self.distancer = distanceCalculator.Distancer(
            gameState.getInitialLayout())
        self.distancer.getMazeDistances()
        global invader
        invader = 0
        global assumedAttacker
        enemies = self.getOpponents(gameState)
        assumedAttacker = enemies[0]

        abc = gameState.getInitialLayout()
        width = abc.getWidth()
        height = abc.getHeight()
        midpoint = int(width / 2)
        global midpointTiles
        midpointTiles = []
        midpointTiles.append((0, 0))
        redPenalty = 1
        redPenalty2 = 0
        if self.red:
            redPenalty = -1
            redPenalty2 = -1

        for i in range(1, height - 1):
            counter = 0
            while abc.isWall(
                (midpoint + redPenalty2 + ((2 + counter) * redPenalty), i)):
                counter += 1
            midpointTiles.append(
                ((midpoint + redPenalty2 + ((2 + counter) * redPenalty)), i))
        global deadends
        deadends = {}
        for n in range(1, height - 1):
            for i in range(1, width - 1):
                if not abc.isWall((i, n)):
                    counter = 0
                    opening = (0, 0)
                    if not abc.isWall((i - 1, n)):
                        opening = (i - 1, n)
                        counter += 1
                    if not abc.isWall((i + 1, n)):
                        opening = (i + 1, n)
                        counter += 1
                    if not abc.isWall((i, n + 1)):
                        opening = (i, n + 1)
                        counter += 1
                    if not abc.isWall((i, n - 1)):
                        opening = (i, n - 1)
                        counter += 1
                    if counter == 1:
                        counter = 0
                        opening2 = (0, 0)
                        if not abc.isWall((opening[0] - 1, opening[1])):
                            if ((opening[0] - 1, opening[1]) != (i, n)):
                                opening2 = (opening[0] - 1, opening[1])
                            counter += 1
                        if not abc.isWall((opening[0] + 1, opening[1])):
                            if ((opening[0] + 1, opening[1]) != (i, n)):
                                opening2 = (opening[0] + 1, opening[1])
                            counter += 1
                        if not abc.isWall((opening[0], opening[1] - 1)):
                            if ((opening[0], opening[1] - 1) != (i, n)):
                                opening2 = (opening[0], opening[1] - 1)
                            counter += 1
                        if not abc.isWall((opening[0], opening[1] + 1)):
                            if ((opening[0], opening[1] + 1) != (i, n)):
                                opening2 = (opening[0], opening[1] + 1)
                            counter += 1
                        if counter == 2:
                            deadends[opening2] = [opening, (i, n)]
                        else:
                            deadends[opening] = [(i, n)]