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


Python CaptureAgent.getMazeDistance方法代码示例

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


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

示例1: chooseAction

# 需要导入模块: from captureAgents import CaptureAgent [as 别名]
# 或者: from captureAgents.CaptureAgent import getMazeDistance [as 别名]
  def chooseAction(self, gameState):
    """
  Picks among actions randomly.
  """
    actions = gameState.getLegalActions(self.index)

    '''
  You should change this in your own agent.
  '''
    optimalAction = "Stop"
    danger = False
    threshold = 8
    for enemy in self.enemyTeam:
      if CaptureAgent.getMazeDistance(self, getAgentDistances(enemy), gameState.getAgentPosition(self.index)) < threshold:
        danger = True

    if danger == True:
      optimalAction = random.choice(actions)
    else:
      optimal = 999
      for action in actions:
        successor = self.getSuccessor(gameState, action)
        foodList = self.getFood(successor).asList()
        myPos = successor.getAgentState(self.index).getPosition()
        minDistance = min([(self.getMazeDistance(myPos, food), food) for food in foodList])
        food = minDistance[1]

        distance = CaptureAgent.getMazeDistance(self, successor.getAgentPosition(self.index), food)
        if distance < optimal:
          optimal = distance
          optimalAction = action

    return optimalAction
开发者ID:IanDrynan,项目名称:PacMan-Ai-Project,代码行数:35,代码来源:myTeam.py


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