Algorithm for generating mazes