当前位置: 首页>>代码示例>>Python>>正文


Python Terrain.get_adj_info方法代码示例

本文整理汇总了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
开发者ID:RodrigoVillatoro,项目名称:machine_learning_projects,代码行数:70,代码来源:robot.py


注:本文中的terrain.Terrain.get_adj_info方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。