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


Python search.breadthFirstSearch函数代码示例

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


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

示例1: betterEvaluationFunction

def betterEvaluationFunction(currentGameState):
  """
    Your extreme ghost-hunting, pellet-nabbing, food-gobbling, unstoppable
    evaluation function (question 5).
  """

  pacPos = currentGameState.getPacmanPosition()
  numCapsules = len(currentGameState.getCapsules())

  # Determine distance to nearest Ghost, don't care if farther than 7
  gDistance = 7
  for pos in currentGameState.getGhostPositions():
    problem = searchAgents.PositionSearchProblem(currentGameState, goal=pos, start=pacPos)
    gDistance = min(gDistance, len(search.breadthFirstSearch(problem)))

  # Determine distance to nearest food
  fDistance = 0
  
  foodGrid = currentGameState.getFood()
  foodList = foodGrid.asList()
  numFood = len(foodList)
  if len(foodList) > 0:
    fProblem = searchAgents.PositionSearchProblem(currentGameState, goal=foodList[0], start=pacPos)
    fDistance = len(search.breadthFirstSearch(problem))

  # Make shorter ghost distance attractive when ghosts are scared
  newGhostStates = currentGameState.getGhostStates()
  newScaredTime = 0
  newScaredTime = reduce(lambda x, y: x.scaredTimer + y.scaredTimer, newGhostStates)
  if newScaredTime > 6:
    gDistance = -gDistance

  px, py = pacPos
  fDensity = 0

  def minus1(l):
    l[:] = [x - 1 for x in l]
    return l

  width = len(foodGrid[:][0])
  height = len(foodGrid[0])

  # Compute density of food surrounding Pacman
  for i in minus1(range(5)):
    intx = px + i
    if intx < 0 or intx > width-1:
      continue

    for j in minus1(range(5)):
      inty = py + j
      if inty < 0 or inty > height-1:
        continue
      if foodGrid[intx][inty]:
        fDensity += 1

  # Return linear combination of factors
  return 3 * gDistance - 13*numCapsules + 1.0/(fDistance+1) + 1*fDensity - 2*numFood
开发者ID:Gabe3vino,项目名称:CS182ProjFall13,代码行数:57,代码来源:multiAgents.py

示例2: findPathToClosestDot

 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)
     totDist = 99999
     closestPellet = 1
     foodList = food.asList()
     for foodPellet in foodList:
         
         dist = self.distance(startPosition, foodPellet)
         
         if dist < totDist:
             print dist
             print totDist
             closestPellet = foodPellet
             totDist = dist
     
     
     problem.goal = closestPellet
     
     actions  = search.breadthFirstSearch(problem)
     
     return actions
     
     "*** YOUR CODE HERE ***"
     util.raiseNotDefined()
开发者ID:gunderjt,项目名称:artificial_intelligence,代码行数:29,代码来源:searchAgents.py

示例3: getPathToApproachPoint

 def getPathToApproachPoint(self, gameState, myState):
   """
   A path takes the form [(whereYouAre, whatYouDo), ...]
   """
   problem = OtherSideProblem(gameState, myState.getPosition(), self.west)
   states, actions, cost = search.breadthFirstSearch(problem)
   return zip(states, actions)  
开发者ID:njoubert,项目名称:UndergraduateProjects,代码行数:7,代码来源:staffAgents.py

示例4: getAction

 def getAction(self, state):
     """
     From game.py:
     The Agent will receive a GameState and must return an action from
     Directions.{North, South, East, West, Stop}
     """
     if not self.food or len(self.food) < 3:
         self.getNewFood(state)
     if not self.actions:
         problem = AnyFoodSearchProblem(state, self.food.pop(0))
         result = search.breadthFirstSearch(problem)
         if not result:
             self.getNewFood(state)
             problem = AnyFoodSearchProblem(state, self.food.pop(0))
         self.actions = search.breadthFirstSearch(problem)
     return self.actions.pop(0)
开发者ID:eabartlett,项目名称:cs188,代码行数:16,代码来源:searchAgents.py

示例5: getPathToNearestDot

 def getPathToNearestDot(self, gameState, myState):
   """
   A path takes the form [(whereYouAre, whatYouDo), ...]
   """
   food = self.getFood(gameState)
   problem = AnyDotWithGameStates( gameState, food, self.index)
   states, actions, cost = search.breadthFirstSearch(problem)
   return zip(states, actions)
开发者ID:njoubert,项目名称:UndergraduateProjects,代码行数:8,代码来源:staffAgents.py

示例6: findPathToClosestDot

    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.breadthFirstSearch(problem)
开发者ID:alexkongg,项目名称:cs188project1,代码行数:9,代码来源:searchAgents.py

示例7: closestFoodDistance

def closestFoodDistance(gameState):
    """
    Returns the the distance to the closest food
    """
    from search import breadthFirstSearch
    startPosition = gameState.getPacmanPosition()
    food = gameState.getFood()
    walls = gameState.getWalls()
    problem = AnyFoodSearchProblem(gameState)
    path = breadthFirstSearch(problem)
    return len(path)
开发者ID:pierrat,项目名称:randomcode2,代码行数:11,代码来源:searchAgents.py

示例8: findPathToClosestDot

    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 ***"
        # use bfs. bfs will give you the shortest path, it spits out the solution, which is the path.
        # It is done. We return the path [a list of action]
        return search.breadthFirstSearch(problem)
开发者ID:jeffchiu605,项目名称:CS188.1x-Project-1,代码行数:12,代码来源:searchAgents.py

示例9: findPathToClosestDot

 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
     from search import breadthFirstSearch
     startPosition = gameState.getPacmanPosition()
     food = gameState.getFood()
     walls = gameState.getWalls()
     problem = AnyFoodSearchProblem(gameState)
     path = breadthFirstSearch(problem)       
     return path
     "*** YOUR CODE HERE ***"
     util.raiseNotDefined()
开发者ID:wustladela,项目名称:cse511hw1,代码行数:12,代码来源:searchAgents.py

示例10: findPathToClosestDot

    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 ***"
        #find the closest food to me and move towards it
        actions = search.breadthFirstSearch(problem)
        return actions
        util.raiseNotDefined()
开发者ID:adinutzyc21,项目名称:ArtificialIntelligence,代码行数:13,代码来源:searchAgents.py

示例11: findPathToClosestDot

  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()
    #print 'startPosition: ' + str(startPosition) #DEBUG
    food = gameState.getFood()
    walls = gameState.getWalls()
    problem = AnyFoodSearchProblem(gameState)

    "*** YOUR CODE HERE ***"
    actions = search.breadthFirstSearch(problem)
    #print 'actions: ' + str(actions) #DEBUG
    return actions
开发者ID:yoavkt,项目名称:AI_ex1,代码行数:13,代码来源:searchAgents.py

示例12: findPathToClosestDot

 def findPathToClosestDot(self, gameState):
     """
     Returns a path (a list of actions) to the closest dot, starting from
     gameState.f
     """
     # Here are some useful elements of the startState
     startPosition = gameState.getPacmanPosition()
     food = gameState.getFood()
     walls = gameState.getWalls()
     problem = AnyFoodSearchProblem(gameState)
     "*** YOUR CODE HERE ***"
     #Camino que sera aprovechado para alcanzar todos los goals
     #dijkstra y brfs funcionan
     return search.breadthFirstSearch(problem)
开发者ID:F6Velasquez,项目名称:Search-in-Pacman,代码行数:14,代码来源:searchAgents.py

示例13: findPathToClosestDot

    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()
        foodGrid = gameState.getFood()
        walls = gameState.getWalls()
        problem = AnyFoodSearchProblem(gameState)

        "*** YOUR CODE HERE ***"
        #We don't have to do much here once AnyFoodSearch is implemented.  We just basically pass the problem on to
        #a search function.  I chose BFS because it's more efficient than DFS and does not require a heuristic.
        return search.breadthFirstSearch(problem)
开发者ID:blanchardsw,项目名称:AI-Projects,代码行数:15,代码来源:searchAgents.py

示例14: findPathToClosestDot

    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
        "initialize some variables"
        startPosition = gameState.getPacmanPosition()
        food = gameState.getFood()
        walls = gameState.getWalls()
        problem = AnyFoodSearchProblem(gameState)

        "use breadthFirstSearch one AnyFoodSearchProblem to make it find the closest food dot"
        actionlist = search.breadthFirstSearch(problem)
        return actionlist
开发者ID:4128575,项目名称:INFOB2KI,代码行数:15,代码来源:searchAgents.py

示例15: findPathToClosestDot

    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 ***"
        # using bfs to find the actions to be taken to solve the problem
        return search.breadthFirstSearch(problem)
        util.raiseNotDefined()
开发者ID:Musket33rs,项目名称:SearchAgents,代码行数:15,代码来源:searchAgents.py


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