Question: I need function in python that develop a method to generate mazes of size n by m , where ,+n,mZ+. Follow the above example maze
I need function in python that develop a method to generate mazes of size n by m, where ,+n,mZ+.
Follow the above example maze and only have one opening on the edge of the maze that is the exit. Define a random starting point in the interior of the maze.
This is example
fig = plt.figure()
def move(maze, y, x): global fig if maze[y, x] == -1 : return False if maze[y, x] == 1 or maze[y, x] == 2 or maze[y, x] == 3: return False if x==0 or y == 0 or x >= maze.shape[1] or y >= maze.shape[0]: try: maze[y,x] = 3 except: print("YOU'RE OUTSIDE!") return True maze[y,x] = 1
found = move(maze, y, x+1) or \ move(maze, y-1, x) or \ move(maze, y, x-1) or \ move(maze, y+1, x) plt.pcolor(maze[-1::-1,:]) display(fig) clear_output(wait = True) plt.pause(1e-10) if found: maze[y,x] = 3 # This is the path we wanna follow else: maze[y,x] = 2 #dead end return found
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
