Example #1
0
    def get_path(self, state):

        fringe = util.Queue()
        seenPos = set()

        succs = state.generatePacmanSuccessors()
        self.nodes.append([None, (state, Directions.STOP)])

        seenPos.add((state.getPacmanPosition(), state.getFood))

        for succ in succs:
            self.nodes.append([state, succ])
        fringe.push(state)

        while not fringe.isEmpty():
            print("-------- new loop\n\n")
            state_curr = fringe.pop()
            seenPos.add((state_curr.getPacmanPosition(), state_curr.getFood()))
            if state_curr.isWin():
                print(state_curr.getPacmanPosition())
                return state_curr
            succs = state_curr.generatePacmanSuccessors()
            print("state_current:\n\n ", state_curr.getPacmanPosition(), "\n",
                  state_curr)
            numfoodcurr = state_curr.getNumFood()
            print("numFoodcurr: ", numfoodcurr)
            numfoodsucc = succs[0][0].getNumFood()
            print("numFoodsucc: ", numfoodsucc)

            for succ in succs:
                if not (succ[0].getPacmanPosition(),
                        succ[0].getFood()) in seenPos:
                    self.nodes.append([state_curr, succ])
                    fringe.push(succ[0])
                    print("fringePush: ", fringe)
Example #2
0
    def bfs(self, state):

        path = {}
        fringe = util.Queue()
        expanded = set()

        last = [None, None]
        expanded.add((state.getPacmanPosition(), state.getFood()))

        path[state] = [None, None]
        fringe.push(state)

        while not fringe.isEmpty():
            current = fringe.pop()
            expanded.add((current.getPacmanPosition(), current.getFood()))

            if current.isWin():
                last = current
                break

            for successor, direction in current.generatePacmanSuccessors():
                if not (successor.getPacmanPosition(), successor.getFood()) in expanded:
                    fringe.push(successor)
                    path[successor] = [current, direction]

        return path, last
 def __init__(self, gameState):
     self._fringe = util.Queue()
     self._maze = gameState.getWalls()
     self._M, self._N = self._maze.height, self._maze.width
     self._visited = [[False for y in range(
         self._N)] for x in range(self._M)]
     self._minDist = {}
     self._row, self._col = (-1, 0, 0, 1), (0, -1, 1, 0)
    def __init__(self, gameState):
        self._fringe = util.Queue()
        self._maze = gameState.getWalls()
        self._M = self._maze.height
        self._N = self._maze.width
        self._visited = np.zeros((self._M, self._N), dtype=bool)
        self._minDist = {}

        self._row = (-1, 0, 0, 1)
        self._col = (0, -1, 1, 0)
Example #5
0
    def _evalFct6(self, gameState):

        if gameState.isLose() or gameState.isWin():
            return gameState.getScore()

        minDistToFood = float("+inf")
        # for each new point to reach
        for food in gameState.getFood().asList():

            print("going through the food list")

            children = util.Queue()
            visited = []
            successors = gameState.generatePacmanSuccessors()

            # we push all successors in a queue, with 1 for the distance
            #  since they are one move apart from the initial position
            for successor in successors:
                print("added an original child")
                succState = successor[0]
                children.push((succState, 1))
                # we remember what positions have already been explored
                visited.append(succState.getPacmanPosition())

            while not children.isEmpty():
                (childState, distance) = children.pop()
                visited.append(childState.getPacmanPosition())
                print("new child ")
                # if this pacManPosition is the same as the food one
                # we see if the distance between them is the minimal one
                # to date, if yes, we update minDistToFood
                if food == childState.getPacmanPosition():
                    print("found a food !!!!!!!!!!!!!!")
                    minDistToFood = min(distance, minDistToFood)
                    break
                else:
                    for subChild in childState.generatePacmanSuccessors():
                        # the distance from the origin is one more than the one
                        # of the parent
                        nextState = subChild[0]
                        if nextState.getPacmanPosition() not in visited:
                            print("pushed an unvisited child")
                            children.push((nextState, distance+1))
            print("out of the queue")
        print("BEST DIST IS : {}".format(minDistToFood))

        return - minDistToFood + gameState.getScore()
 def _reset(self):
     self._visited = np.zeros((self._M, self._N), dtype=bool)
     self._fringe = util.Queue()
     # self._foodExplored.clear()
     self._minDist.clear()
Example #7
0
 def _reset(self):
     self._visited = [[False for x in range(self._N)]
                      for y in range(self._M)]
     self._fringe = util.Queue()
     # self._foodExplored.clear()
     self._minDist.clear()