当前位置: 首页>>代码示例>>Python>>正文


Python search.bfs方法代码示例

本文整理汇总了Python中search.bfs方法的典型用法代码示例。如果您正苦于以下问题:Python search.bfs方法的具体用法?Python search.bfs怎么用?Python search.bfs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在search的用法示例。


在下文中一共展示了search.bfs方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mazeDistance

# 需要导入模块: import search [as 别名]
# 或者: from search import bfs [as 别名]
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)) 
开发者ID:jrios6,项目名称:Berkeley-AI-PacMan-Lab-1,代码行数:19,代码来源:searchAgents.py

示例2: tick

# 需要导入模块: import search [as 别名]
# 或者: from search import bfs [as 别名]
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) 
开发者ID:HarvardURC,项目名称:Pacbot,代码行数:24,代码来源:basicHighLevelModule.py

示例3: mazeDistance

# 需要导入模块: import search [as 别名]
# 或者: from search import bfs [as 别名]
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)) 
开发者ID:ryanshrott,项目名称:Pacman-AI,代码行数:19,代码来源:searchAgents.py

示例4: mazeDistance

# 需要导入模块: import search [as 别名]
# 或者: from search import bfs [as 别名]
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)) 
开发者ID:deepeshmittal,项目名称:AI-PacMan-Projects,代码行数:19,代码来源:searchAgents.py

示例5: _find_paths_to_closest_ghosts

# 需要导入模块: import search [as 别名]
# 或者: from search import bfs [as 别名]
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] 
开发者ID:HarvardURC,项目名称:Pacbot,代码行数:6,代码来源:heuristicHighLevelModule.py

示例6: _find_distance_of_closest_pellet

# 需要导入模块: import search [as 别名]
# 或者: from search import bfs [as 别名]
def _find_distance_of_closest_pellet(self, target_loc):
        return len(bfs(self.grid, target_loc, [o])) - 1 
开发者ID:HarvardURC,项目名称:Pacbot,代码行数:4,代码来源:heuristicHighLevelModule.py

示例7: findPathToClosestDot

# 需要导入模块: import search [as 别名]
# 或者: from search import bfs [as 别名]
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) 
开发者ID:jrios6,项目名称:Berkeley-AI-PacMan-Lab-1,代码行数:11,代码来源:searchAgents.py

示例8: findPathToClosestDot

# 需要导入模块: import search [as 别名]
# 或者: from search import bfs [as 别名]
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) 
开发者ID:ryanshrott,项目名称:Pacman-AI,代码行数:13,代码来源:searchAgents.py

示例9: findPathToClosestDot

# 需要导入模块: import search [as 别名]
# 或者: from search import bfs [as 别名]
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 ***" 
开发者ID:loren-jiang,项目名称:cs188_tbf,代码行数:14,代码来源:searchAgents.py


注:本文中的search.bfs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。