本文整理汇总了Python中terrain.Terrain.get_adj_info方法的典型用法代码示例。如果您正苦于以下问题:Python Terrain.get_adj_info方法的具体用法?Python Terrain.get_adj_info怎么用?Python Terrain.get_adj_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类terrain.Terrain
的用法示例。
在下文中一共展示了Terrain.get_adj_info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Robot
# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import get_adj_info [as 别名]
#.........这里部分代码省略.........
if rotation == 'Reset' and movement == 'Reset':
self.reset_values()
# If we are about to hit the goal in the second round
if self.robot_pos['location'] in self.center_locations \
and self.steps_final_round != 0:
self.report_results()
return rotation, movement
# --------------------------------------------
# LOCATION-RELATED
# --------------------------------------------
def reset_values(self):
self.robot_pos = {'location': [0, 0], 'heading': 'up'}
def get_current_position(self):
heading = self.robot_pos['heading']
location = self.robot_pos['location']
x = location[0]
y = location[1]
return x, y, heading
def is_at_starting_position(self, x, y):
return x == 0 and y == 0
def is_at_center_of_the_maze(self, x, y):
return [x, y] in self.center_locations
def is_at_a_dead_end(self, sensors):
x, y, heading = self.get_current_position()
adj_distances, adj_visited = \
self.terrain.get_adj_info(x, y, heading, sensors, False)
return sensors == [0, 0, 0] or adj_distances == list(MAX_DISTANCES)
def get_walls_for_current_location(self, x, y, heading, sensors):
if self.is_at_starting_position(x, y):
walls = [1, 0, 1, 1]
# If it had been visited before, just get those values
elif self.terrain.grid[x][y].visited != '':
walls = self.terrain.grid[x][y].get_total_walls()
# Else, get current walls. Note that it can only have real walls
# since the location has never been visited, and imaginary walls
# are the result of dead ends that force the robot to the prev location
else:
# Placeholder
walls = [0, 0, 0, 0]
# Change sensor info to wall info
walls_sensors = [1 if x == 0 else 0 for x in sensors]
# Map walls to correct x and y coordinates
for i in range(len(walls_sensors)):
dir_sensor = dir_sensors[heading][i]
index = wall_index[dir_sensor]
walls[index] = walls_sensors[i]
# Update missing wall index (the cell right behind the robot)
index = wall_index[dir_reverse[heading]]
walls[index] = 0
return walls