本文整理汇总了Python中agent.Agent.turn方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.turn方法的具体用法?Python Agent.turn怎么用?Python Agent.turn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类agent.Agent
的用法示例。
在下文中一共展示了Agent.turn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import turn [as 别名]
def start(self):
''' Start the A star algorithm '''
expansion_count = 0
while not self.open_set.empty():
current = self.open_set.get()
# print "Expanding node {0}".format(current)
expansion_count += 1
# If we reached the goal, stop
if current == self.world.goal:
break
evaluator = Agent(current, self.facing[current], self.heuristic_num, self.world)
for next in self.world.get_adjacent_cells(current):
# Tally total cost
g_score = self.cost_so_far[current] \
+ evaluator.forward(next) + evaluator.turn(next)
# Consider the adjacent node, 'next'...
if next not in self.cost_so_far or g_score < self.cost_so_far[next]:
self.cost_so_far[next] = g_score
h_score = evaluator.estimate(next, self.world.goal)
f_score = g_score + h_score
#Add the node to the priority queue
self.open_set.put(next, f_score)
#Save the direction the node is facing
new_dir = Direction().set_dir(Direction.vector(current, next))
self.facing[next] = new_dir
turn_string = "turn," * evaluator.dir.count_turns_needed(current, next)
self.actions_taken[next] = turn_string + "forward"
#Add the node to the path of traversed nodes
self.came_from[next] = current
for bash_cell in self.world.get_bashable_cells(current):
g_score = self.cost_so_far[current] \
+ evaluator.bash(bash_cell) + evaluator.turn(bash_cell)
#Consider the bash node, next
if bash_cell not in self.cost_so_far or g_score < self.cost_so_far[bash_cell]:
self.cost_so_far[bash_cell] = g_score
h_score = evaluator.estimate(bash_cell, self.world.goal)
f_score = g_score + h_score
self.open_set.put(bash_cell, f_score)
new_dir = Direction().set_dir(Direction.vector(current, bash_cell))
self.facing[bash_cell] = new_dir
turn_string = "turn," * evaluator.dir.count_turns_needed(current, bash_cell)
self.actions_taken[bash_cell] = turn_string + "bash,forward,"
self.came_from[bash_cell] = current
score = 100 - self.cost_so_far[self.world.goal]
self.trace_path()
self.output(score, expansion_count)