Exemplo n.º 1
0
    def compute_route(self, node_source, source_ori, node_target, target_ori):

        self._previous_node = node_source

        a_star = AStar()
        a_star.init_grid(
            self._map.get_graph_resolution()[0],
            self._map.get_graph_resolution()[1],
            self._map.get_walls_directed(node_source, source_ori, node_target,
                                         target_ori), node_source, node_target)

        route = a_star.solve()

        # JuSt a Corner Case
        # Clean this to avoid having to use this function
        if route is None:
            a_star = AStar()
            a_star.init_grid(
                self._map.get_graph_resolution()[0],
                self._map.get_graph_resolution()[1],
                self._map.get_walls_directed(node_source,
                                             source_ori,
                                             node_target,
                                             target_ori,
                                             both_walls=False), node_source,
                node_target)

            route = a_star.solve()

        self._route = route

        return route
Exemplo n.º 2
0
 def AStar_robot(self):
     """
     Perform a AStar search to find the optimal route based on the
     known maze 
     
     Note: Changing the weight of g (weight based on steps from start)
         in AStar caused the algorithm to get out of a stuck corner case.
         Should do something to modify cell.g if the same move is seen 
         multiple times in a short period. (3 in 5?)
     """
     search = AStar(self.maze_dim, self.current_maze, 
                    self.location, self.goal)
     # Build the internal AStar grid
     search.init_grid()
     # Find the optimal route
     search.process()
     # Return the list of moves necessary to reach the goal
     self.move_list = search.display_path(show=False)
     print(self.move_list)
     #print(self.move_list)
     # Return the move
     rotation, movement = self.move_direction(self.move_list.pop(0))
     return rotation, movement