import numpy as np
import random
from matplotlib import pyplot as plt
import matplotlib.cm as cm
num_rows = 10
num_cols = 10
# M = [L,U,R,D,VIS]
M = []
r = 0
c = 0
M = np.zeros((num_rows,num_cols,5),dtype=np.uint8)
image = np.zeros((num_rows * 10,num_cols * 10),dtype = np.uint8)
st = []
st.append([r,c])
while st:
M[r,c,4] = 1
dirc = []
if c > 0 and M[r,c-1,4] == 0:
dirc.append('L')
if r > 0 and M[r-1,c,4] == 0:
dirc.append('U')
if c < num_cols - 1 and M[r,c+1,4] == 0:
dirc.append('R')
if r < num_rows - 1 and M[r+1,c,4] == 0:
dirc.append('D')
if len(dirc):
move_dir = random.choice(dirc)
if move_dir == 'L':
M[r,c,0] = 1
c -= 1
M[r,c,2] =1
if move_dir == 'U':
M[r,c,1] = 1
r -= 1
M[r,c,3] = 1
if move_dir == 'R':
M[r,c,2] = 1
c += 1
M[r,c,0] = 1
if move_dir == 'D':
M[r,c,3] = 1
r += 1
M[r,c,1] = 1
st.append([r,c])
else:
r,c = st.pop()
M[0,0,0] =1