python类bfs()的实例源码

basicHighLevelModule.py 文件源码 项目:Pacbot 作者: HarvardURC 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def tick(self):
        if self.state and self.state.mode == LightState.RUNNING:
            p_loc = (self.state.pacman.x, self.state.pacman.y)

            # update game state
            if self.grid[p_loc[0]][p_loc[1]] in [o, O]:
                self.grid[p_loc[0]][p_loc[1]] = e

            path = bfs(self.grid, p_loc, self.state, [o, O])
            print(path)

            if path != None:
                next_loc = path[1]
                # Figure out position we need to move
                new_msg = PacmanCommand()
                new_msg.dir = self._get_direction(p_loc, next_loc)
                self.write(new_msg.SerializeToString(), MsgType.PACMAN_COMMAND)
                return

        new_msg = PacmanCommand()
        new_msg.dir = PacmanCommand.STOP
        self.write(new_msg.SerializeToString(), MsgType.PACMAN_COMMAND)
searchAgents.py 文件源码 项目:Berkeley-AI-PacMan-Lab-1 作者: jrios6 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def mazeDistance(point1, point2, gameState):
  """
  Returns the maze distance between any two points, using the search functions
  you have already built.  The gameState can be any game state -- Pacman's position
  in that state is ignored.

  Example usage: mazeDistance( (2,4), (5,6), gameState)

  This might be a useful helper function for your ApproximateSearchAgent.
  """
  x1, y1 = point1
  x2, y2 = point2
  walls = gameState.getWalls()
  assert not walls[x1][y1], 'point1 is a wall: ' + point1
  assert not walls[x2][y2], 'point2 is a wall: ' + str(point2)
  prob = PositionSearchProblem(gameState, start=point1, goal=point2, warn=False)
  return len(search.bfs(prob))
searchAgents.py 文件源码 项目:Pacman-AI 作者: ryanshrott 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def mazeDistance(point1, point2, gameState):
  """
  Returns the maze distance between any two points, using the search functions
  you have already built.  The gameState can be any game state -- Pacman's position
  in that state is ignored.

  Example usage: mazeDistance( (2,4), (5,6), gameState)

  This might be a useful helper function for your ApproximateSearchAgent.
  """
  x1, y1 = point1
  x2, y2 = point2
  walls = gameState.getWalls()
  assert not walls[x1][y1], 'point1 is a wall: ' + point1
  assert not walls[x2][y2], 'point2 is a wall: ' + str(point2)
  prob = PositionSearchProblem(gameState, start=point1, goal=point2, warn=False)
  return len(search.bfs(prob))
searchAgents.py 文件源码 项目:AI-PacMan-Projects 作者: deepeshmittal 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def mazeDistance(point1, point2, gameState):
    """
    Returns the maze distance between any two points, using the search functions
    you have already built. The gameState can be any game state -- Pacman's
    position in that state is ignored.

    Example usage: mazeDistance( (2,4), (5,6), gameState)

    This might be a useful helper function for your ApproximateSearchAgent.
    """
    x1, y1 = point1
    x2, y2 = point2
    walls = gameState.getWalls()
    assert not walls[x1][y1], 'point1 is a wall: ' + str(point1)
    assert not walls[x2][y2], 'point2 is a wall: ' + str(point2)
    prob = PositionSearchProblem(gameState, start=point1, goal=point2, warn=False, visualize=False)
    return len(search.bfs(prob))
searchAgents.py 文件源码 项目:cs188_tbf 作者: loren-jiang 项目源码 文件源码 阅读 48 收藏 0 点赞 0 评论 0
def mazeDistance(point1, point2, gameState):
    """
    Returns the maze distance between any two points, using the search functions
    you have already built. The gameState can be any game state -- Pacman's
    position in that state is ignored.

    Example usage: mazeDistance( (2,4), (5,6), gameState)

    This might be a useful helper function for your ApproximateSearchAgent.
    """
    x1, y1 = point1
    x2, y2 = point2
    walls = gameState.getWalls()
    assert not walls[x1][y1], 'point1 is a wall: ' + str(point1)
    assert not walls[x2][y2], 'point2 is a wall: ' + str(point2)
    prob = PositionSearchProblem(gameState, start=point1, goal=point2, warn=False, visualize=False)
    return len(search.bfs(prob))
searchAgents.py 文件源码 项目:AIclass 作者: mttk 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def mazeDistance(point1, point2, gameState):
    """
    Returns the maze distance between any two points, using the search functions
    you have already built. The gameState can be any game state -- Pacman's
    position in that state is ignored.

    Example usage: mazeDistance( (2,4), (5,6), gameState)

    This might be a useful helper function for your ApproximateSearchAgent.
    """
    x1, y1 = point1
    x2, y2 = point2
    walls = gameState.getWalls()
    assert not walls[x1][y1], 'point1 is a wall: ' + str(point1)
    assert not walls[x2][y2], 'point2 is a wall: ' + str(point2)
    prob = PositionSearchProblem(gameState, start=point1, goal=point2, warn=False, visualize=False)
    return len(search.bfs(prob))
searchAgents.py 文件源码 项目:AIclass 作者: mttk 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def mazeDistance(point1, point2, gameState):
    """
    Returns the maze distance between any two points, using the search functions
    you have already built. The gameState can be any game state -- Pacman's
    position in that state is ignored.

    Example usage: mazeDistance( (2,4), (5,6), gameState)

    This might be a useful helper function for your ApproximateSearchAgent.
    """
    x1, y1 = point1
    x2, y2 = point2
    walls = gameState.getWalls()
    assert not walls[x1][y1], 'point1 is a wall: ' + str(point1)
    assert not walls[x2][y2], 'point2 is a wall: ' + str(point2)
    prob = PositionSearchProblem(gameState, start=point1, goal=point2, warn=False, visualize=False)
    return len(search.bfs(prob))
searchAgents.py 文件源码 项目:Pac-Man-Search 作者: xuefengDevelop 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def mazeDistance(point1, point2, gameState):
    """
    Returns the maze distance between any two points, using the search functions
    you have already built. The gameState can be any game state -- Pacman's
    position in that state is ignored.

    Example usage: mazeDistance( (2,4), (5,6), gameState)

    This might be a useful helper function for your ApproximateSearchAgent.
    """
    x1, y1 = point1
    x2, y2 = point2
    walls = gameState.getWalls()
    assert not walls[x1][y1], 'point1 is a wall: ' + str(point1)
    assert not walls[x2][y2], 'point2 is a wall: ' + str(point2)
    prob = PositionSearchProblem(gameState, start=point1, goal=point2, warn=False, visualize=False)
    return len(search.bfs(prob))
searchAgents.py 文件源码 项目:Pacman-AI 作者: adamtache 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def mazeDistance(point1, point2, gameState):
  """
  Returns the maze distance between any two points, using the search functions
  you have already built.  The gameState can be any game state -- Pacman's position
  in that state is ignored.

  Example usage: mazeDistance( (2,4), (5,6), gameState)

  This might be a useful helper function for your ApproximateSearchAgent.
  """
  x1, y1 = point1
  x2, y2 = point2
  walls = gameState.getWalls()
  assert not walls[x1][y1], 'point1 is a wall: ' + point1
  assert not walls[x2][y2], 'point2 is a wall: ' + str(point2)
  prob = PositionSearchProblem(gameState, start=point1, goal=point2, warn=False)
  return len(search.bfs(prob))
heuristicHighLevelModule.py 文件源码 项目:Pacbot 作者: HarvardURC 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _find_paths_to_closest_ghosts(self, pac_loc):
        ghosts = [self.state.red_ghost, self.state.pink_ghost, self.state.orange_ghost, self.state.blue_ghost]
        state_paths = [(ghost.state, bfs(self.grid, pac_loc, (ghost.x, ghost.y), GHOST_CUTOFF)) for ghost in ghosts]
        return [sp for sp in state_paths if sp[1] is not None]
heuristicHighLevelModule.py 文件源码 项目:Pacbot 作者: HarvardURC 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _find_distance_of_closest_pellet(self, target_loc):
        return len(bfs(self.grid, target_loc, [o])) - 1
searchAgents.py 文件源码 项目:Berkeley-AI-PacMan-Lab-1 作者: jrios6 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def findPathToClosestDot(self, gameState):
    "Returns a path (a list of actions) to the closest dot, starting from gameState"
    # Here are some useful elements of the startState
    startPosition = gameState.getPacmanPosition()
    food = gameState.getFood()
    walls = gameState.getWalls()
    problem = AnyFoodSearchProblem(gameState)

    return search.bfs(problem)
searchAgents.py 文件源码 项目:Pacman-AI 作者: ryanshrott 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def findPathToClosestDot(self, gameState):
    "Returns a path (a list of actions) to the closest dot, starting from gameState"
    # Here are some useful elements of the startState
    startPosition = gameState.getPacmanPosition()
    food = gameState.getFood()
    walls = gameState.getWalls()
    problem = AnyFoodSearchProblem(gameState)

    "*** YOUR CODE HERE ***"
    problem = AnyFoodSearchProblem(gameState)
    return search.bfs(problem)
searchAgents.py 文件源码 项目:cs188_tbf 作者: loren-jiang 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def findPathToClosestDot(self, gameState):
        """
        Returns a path (a list of actions) to the closest dot, starting from
        gameState.
        """
        # Here are some useful elements of the startState
        startPosition = gameState.getPacmanPosition()
        food = gameState.getFood()
        walls = gameState.getWalls()
        problem = AnyFoodSearchProblem(gameState)
        return(search.bfs(problem))
        "*** YOUR CODE HERE ***"


问题


面经


文章

微信
公众号

扫码关注公众号