Example #1
0
 def run(self) -> None:
     """Run the program."""
     if self.gui:
         self.run_gui()
     else:
         maze = Maze(self.width, self.height, generator=self.generator)
         if self.solve:
             solver = MazeSolver()
             maze.path = solver.solve(maze)
         print(maze)
Example #2
0
    def __init__(
        self, generator: Optional[MazeGenerator] = DepthFirstSearchGenerator()
    ) -> None:
        super().__init__()
        self.walls = []

        self.vertices = {}
        self.edges = {}

        self.maze = Maze(width=self.NUM_COLUMNS,
                         height=self.NUM_ROWS,
                         generator=generator)
        self.create_graph()
Example #3
0
    def generate_new_maze(self,
                          event: Optional[tk.Event] = None,
                          generate: bool = True) -> None:
        """Create a new blank maze, and optionally generate paths through it."""
        if self.generating_maze or self.solving_maze:
            return

        self.clear_path()
        self.frontier_cells.clear()
        self.generation_start_cell = None
        self.maze = Maze(self.width, self.height, generator=None)
        self.maze_generated = False
        self.start_time = None
        self.display_maze()

        if generate:
            self.generate_current_maze()
Example #4
0
 def __init__(self):
     self.lab = Maze()
     self.lab.create_lab_elements()
Example #5
0
        self.junction_graph = self.construct_junction_graph()
        self.junction_graph.depth_first_search(self.maze.start_cell,
                                               self.junction_visitor)

        end_cell = self.maze.end_cell
        path = [end_cell]
        prev_cell = end_cell
        cell = self.prev_cells.get(end_cell)

        while path[-1] != self.maze.start_cell:
            if Direction.between(prev_cell, cell) is None:
                # fill in corridors
                direction = self.junction_direction(prev_cell, cell)
                neighbor = self.maze.neighbor(prev_cell, direction)
                while neighbor != cell:
                    path.append(neighbor)
                    neighbor = self.maze.neighbor(neighbor, direction)
            path.append(cell)
            prev_cell = cell
            cell = self.prev_cells.get(cell)

        return list(reversed(path))


if __name__ == '__main__':
    maze = Maze()
    solver = MazeSolver()
    path = solver.solve(maze)
    print(maze)
    print(f'Solution: {[cell.coordinates for cell in path]}')