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


Python Terrain.update_distances方法代码示例

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


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