本文整理汇总了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