Generating Maze using Python
August 2, 2007
Do you like mazes?
eriol@mornie:~$ python maze.py +--+--+--+--+--+--+--+--+--+--+ | | | | | + + + +--+ + +--+ + + + | | | | | | | | + + + +--+--+--+ +--+--+ + | | | | | | | + + +--+ + +--+--+ + + + | | | | | | | + + + +--+--+--+--+--+--+ + | | | | | + +--+--+ + + +--+--+--+ + | | | | +--+--+--+--+--+--+--+--+--+--+
After reading this good article, I decided to wrote some code to generate a perfect maze :D
The result is here: maze.py
As you can see, Depth-First Search is not a complex algorithm:
def create(self): cell_stack = [] while self.visited_cells < self.total_cells: neighbors = self.find_neighbors_with_walls(self.current_cell) if neighbors: new_cell = random.choice(neighbors) self.current_cell.destroy_wall(cell=new_cell) cell_stack.append(self.current_cell) self.current_cell = new_cell self.visited_cells += 1 else: self.current_cell = cell_stack.pop()


05 May 11, Thursday @ 02:50
Hi,
this interesting article inspired me to write a maze generator and solver written in Perl.
http://www.lucaamore.com/?p=583