本文整理汇总了Python中terrain.Terrain.update_distances方法的典型用法代码示例。如果您正苦于以下问题:Python Terrain.update_distances方法的具体用法?Python Terrain.update_distances怎么用?Python Terrain.update_distances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类terrain.Terrain
的用法示例。
在下文中一共展示了Terrain.update_distances方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Robot
# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import update_distances [as 别名]
#.........这里部分代码省略.........
if possible_candidate is None:
possible_candidate = i
else:
a = adj_distances[possible_candidate]
b = adj_distances[i]
if b > a:
possible_candidate = i
valid_index = possible_candidate
if valid_index is None:
possible_candidate = None
for i, dist in enumerate(adj_distances):
if dist != -1 and adj_visited[i] is 'e':
if possible_candidate is None:
possible_candidate = i
else:
a = adj_distances[possible_candidate]
b = adj_distances[i]
if b > a:
possible_candidate = i
valid_index = possible_candidate
return valid_index
def explore(self, x, y, heading, sensors):
if self.should_end_exploring(x, y) or not self.explore_after_center:
rotation = 'Reset'
movement = 'Reset'
self.exploring = False
self.terrain.set_imaginary_walls_for_unvisited_cells()
self.terrain.update_distances(last_update=True)
else:
# If we reach a dead end:
if self.is_at_a_dead_end(sensors):
rotation, movement = self.deal_with_dead_end(x, y, heading)
else:
valid_index = self.get_valid_index(x, y, heading, sensors, True)
if valid_index is not None:
rotation, movement = self.convert_from_index(valid_index)
else:
rotation, movement = 'Reset', 'Reset'
return rotation, movement
def convert_from_index(self, index):
# Move Left
if index == 0:
rotation = -90
movement = 1
# Move Up
elif index == 1:
rotation = 0
movement = 1
# Move Right
elif index == 2:
rotation = 90
movement = 1
# Minimum distance is behind, so just rotate clockwise
else:
rotation = 90