本文整理汇总了Python中terrain.Terrain.update_imaginary_walls方法的典型用法代码示例。如果您正苦于以下问题:Python Terrain.update_imaginary_walls方法的具体用法?Python Terrain.update_imaginary_walls怎么用?Python Terrain.update_imaginary_walls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类terrain.Terrain
的用法示例。
在下文中一共展示了Terrain.update_imaginary_walls方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Robot
# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import update_imaginary_walls [as 别名]
#.........这里部分代码省略.........
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
movement = 0
return rotation, movement
def deal_with_dead_end(self, x, y, heading):
# 1) Move back one step
rotation = 0
movement = -1
# 2) Get reference to cell
cell = self.terrain.grid[x][y]
# 3) Place imaginary wall behind the robot before exiting location
reverse_direction = dir_reverse[heading]
index = self.terrain.get_index_of_wall(reverse_direction)
cell.imaginary_walls[index] = 1
# 4) Change the value of visited to signify dead end
cell.visited = 'x'
cell.distance = WALL_VALUE
# 5) Update imaginary walls and distances
self.terrain.update_imaginary_walls(x, y, cell.imaginary_walls)
return rotation, movement
def should_end_exploring(self, x, y):
"""
The robot should end exploring in all these cases:
- It has already explored more than 90% of the cells
- It has already taken 30 steps (in the exploration phase)
- It has reached the center of the maze (again)
- It has reached the starting location (again)
"""
# Check for % of cells covered
if self.terrain.get_percentage_of_maze_explored() > 80:
return True
if self.consecutive_explored_cells >= 3:
return True
# Check for number of steps
if self.steps_exploring > 15:
return True
# Check for center of the maze:
if self.is_at_center_of_the_maze(x, y):
return True
if self.is_at_starting_position(x, y):
return True
return False