• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python search.breadthFirstSearch函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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)

        closest = None
        for pellet in food.asList():
            if closest == None:
                closest = pellet
                continue
            distance1 = abs(closest[0]-startPosition[0]) + abs(closest[1]-startPosition[1])
            distance2 = abs(pellet[0]-startPosition[0]) + abs(pellet[0]-startPosition[0])
            if distance1 < distance2:
                closest = pellet

        self.searchType = AnyFoodSearchProblem
        self.searchFunction = lambda prob: search.breadthFirstSearch(problem)
        return search.breadthFirstSearch(problem)
开发者ID:DvanLaar,项目名称:AI,代码行数:24,代码来源:searchAgents.py


示例17: 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 ***"
        # do BFS with AnyFoodSearchProlem (which has as goal state 'any food')
        # since BFS searches breadth first, you will always get the closest food
        from search import breadthFirstSearch
        return breadthFirstSearch(problem)
开发者ID:Pava1n3,项目名称:Git-Gud-Hub,代码行数:16,代码来源:searchAgents.py


示例18: 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 defined in search.py to find the goal""" 
        from search import breadthFirstSearch
        return breadthFirstSearch(problem)
开发者ID:adityaghosh,项目名称:PacmanAI,代码行数:16,代码来源:searchAgents.py


示例19: evalFn

 def evalFn(self, successor, action):
   if self.getFood(successor).count() == 0: return 1000
   myState = successor.getAgentState(self.index)
   pos = myState.getPosition() 
   if pos != nearestPoint(pos): return self.evalFn(successor.generateSuccessor(self.index, action), action)
   
   food = self.getFood(successor)
   problem = AnyDotOnSideWillDo(nearestPoint(pos), food, successor.getWalls())
   distanceToFood = search.breadthFirstSearch(problem)[2]
   
   distanceToOpponent = 100
   for enemyIndex in self.getOpponents(successor):
     opp = successor.getAgentState(enemyIndex)
     if not opp.isPacman:
       distanceToOpponent = min(distanceToOpponent, manhattanDistance(myState.getPosition(), opp.getPosition()))
     
   return -0.3 * distanceToFood + self.getScore(successor) + 2 * math.log(distanceToOpponent)
开发者ID:njoubert,项目名称:UndergraduateProjects,代码行数:17,代码来源:staffAgents.py


示例20: primsMinSpanningTreeHeuristic

def primsMinSpanningTreeHeuristic(state, gameState, edges):
    vNew = []
    totalDist = 0
    
    currentFoodGrid = state[1]
    vertices = foodGridToFoodList(currentFoodGrid)
           
    if (len(vertices) == 0):
        return 0
    
    start = state[0] #Pacman's position
    
    delStart = False
    if (start not in edges.keys()): #This is only to keep the edge hash from becoming really big.
        delStart = True
        edges[start] = {}
        for pellet in vertices:
          problem = CustomPositionSearchProblem(gameState, lambda x: 1, pellet, start)
          actions = search.breadthFirstSearch(problem)
          distance = len(actions) #we can do this because the cost function is 1
          edges[start][pellet] = distance 
          #DO WE NEED TO ADD THE START AS A DESTINATION TO ALL THE OTHER PELLETS TOO? I DONT THINK SO...
    
    vNew.append(start)
    
    nearestV = None
    nearestD = 999999
    while len(vertices) > 0:
        nearestV = None
        nearestD = 999999 
        for sVertex in vNew:
            for eVertex in vertices:
                if (edges[sVertex][eVertex] < nearestD):
                    nearestD = edges[sVertex][eVertex]
                    nearestV = eVertex
        assert nearestV != None
        vNew.append(eVertex)
        vertices.remove(eVertex)
        totalDist += nearestD
        
    if (delStart):
        del edges[start]
    
    #print "h = ",totalDist,", ",foodCount," food, ", len(edges.keys()), "nodes in edge hash: ", edges.keys()
    #print "Prim distance=", totalDist, ", pellet count=", len(vertices), " and pacman position=", start    
    return totalDist
开发者ID:njoubert,项目名称:UndergraduateProjects,代码行数:46,代码来源:searchAgents.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python search.search函数代码示例发布时间:2022-05-27
下一篇:
Python search.bfs函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap