import numpy as np                                                                                                         
 
import time
import os
 
maze = np.full((10,12),'#')
maze[0] = ['#','#','#','#','#','#','#','#','#','#','#','#']
maze[1] = ['#',' ',' ',' ','#',' ','#',' ',' ','#',' ','#']
maze[2] = ['#',' ','#',' ','#',' ','#',' ','#','#',' ','#']
maze[3] = ['#',' ',' ',' ',' ',' ',' ',' ',' ','#',' ','#']
maze[4] = ['#',' ','#','#','#','#','#','#',' ','#',' ','#']
maze[5] = ['#',' ','#',' ',' ',' ',' ','#',' ','#',' ','#']
maze[6] = ['#',' ','#',' ','#',' ','#',' ',' ','#',' ','#']
maze[7] = ['#',' ','#',' ','#',' ','#',' ','#','#',' ','#']
maze[8] = ['#',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ']
maze[9] = ['#','#','#',' ','#','#','#','#','#','#','#','#']
 
def print_maze(arr):
    for y in range(arr.shape[0]):
        for x in range(arr.shape[1]):
            if arr[y][x] == '#':
                print('\033[92m' + arr[y][x] + '\033[0m', end ='')
            else:
                print(arr[y][x], end ='')
        print()
 
 
def explore(maze, origin_y, origin_x):
 
    maze[origin_y][origin_x] = '@' 
    print_maze(maze)
 
    if (origin_y == 8 and origin_x == 11): #The base case, we found the exit
        print("Found the exit!")
        time.sleep(3)
        exit()
 
    time.sleep(0.3)
    #os.system("cls||clear")
    print("\033[33A",end="\r")
 
    maze_up = maze.copy()
    maze_down = maze.copy()
    maze_left = maze.copy()
    maze_right = maze.copy()    
   
    #Check up direction and then move up
    if (maze[origin_y - 1][origin_x] == ' '):
        explore(maze_up, origin_y - 1, origin_x)
   
    #Check left direction and then move left
    if (maze[origin_y][origin_x - 1] == ' '):
        explore(maze_left, origin_y, origin_x - 1)
   
    #Check Right direction and then Move Right
    if (maze[origin_y][origin_x + 1] == ' '):
        explore(maze_right, origin_y, origin_x + 1)
   
    #Check Down direction and then Move Down
    if (maze[origin_y+1][origin_x] == ' '):
        explore(maze_down, origin_y + 1, origin_x)
   
    #If no direction to go next, start returning
    return  #Technically, once function ends runs out of
        #instructions, it automatically 'returns' so this line is
        #just to show a point that we are returning.
 
os.system("cls||clear")
explore(maze, 9, 3) #Character starts at coordinate 3,9

