Beispiel #1
0
    def test_paths(self):
        """ Confirms each waypoint is reachable """

        for z in range(self.dim_z + 1):
            # Create the graph, impediments are walls(0) and locked doors(L)

            imp = []

            this_floor = [None for y in range(self.dim_y)]
            for y in range(self.dim_y):
                this_floor[y] = [None for x in range(self.dim_x)]
                for x in range(self.dim_x):
                    this_floor[y][x] = self.grid[x, y, z][0]

            graph = GraphGrid(this_floor)

            # Default impediments are wall(0) and locked doors(L)
            imp = [(a, b) for a, b, c in self.grid
                   if self.grid[a, b, z][0] in [0, '0', 'L']]

            # Set the list of impassable points
            graph.impassable = imp

            # Set the floor start and end points
            start, end = self.find_path_ends(z)

            self.logger.info('[*] Testing the path from {} to {}'.format(
                start, end))

            # Initialize the path tester, as a_star for best path
            path_tester = Pathfinder(Pathfinder.gb_first)
            path_tester.g = graph
            path_tester.start = start[:2]
            path_tester.dest = end[:2]
            path = path_tester.execute()

            if not path:
                self.logger.error("Invalid pathfinding algorithm")
            else:
                for (x, y) in path:
                    val = path[x, y]
                    if val is not None:
                        if self.grid[x, y, z][0] not in ['U', 'D', 'S', 'E']:
                            self.grid[val[0], val[1],
                                      z][1] = [color.WHITE_ON_BLUE]
    def test_paths(self):
        """ Confirms each waypoint is reachable """

        for z in range(self.dim_z+1):
            # Create the graph, impediments are walls(0) and locked doors(L)

            imp = []

            this_floor = [None for y in range(self.dim_y)]
            for y in range(self.dim_y):
                this_floor[y]=[None for x in range(self.dim_x)]
                for x in range(self.dim_x):
                    this_floor[y][x]=self.grid[x,y,z][0]

            graph = GraphGrid(this_floor)

            # Default impediments are wall(0) and locked doors(L)
            imp=[(a,b) for a,b,c in self.grid if self.grid[a,b,z][0] in [0,'0','L']]

            # Set the list of impassable points
            graph.impassable = imp

            # Set the floor start and end points
            start,end = self.find_path_ends(z)

            self.logger.info('[*] Testing the path from {} to {}'.format(start,
                                                                         end))

            # Initialize the path tester, as a_star for best path
            path_tester=Pathfinder(Pathfinder.gb_first)
            path_tester.g = graph
            path_tester.start = start[:2]
            path_tester.dest = end[:2]
            path = path_tester.execute()

            if not path:
                self.logger.error("Invalid pathfinding algorithm")
            else:
                for (x,y) in path:
                    val=path[x,y]
                    if val is not None:
                        if self.grid[x,y,z][0] not in ['U','D','S','E']:
                            self.grid[val[0],val[1],z][1]=[color.WHITE_ON_BLUE]