Skip to content

Instantly share code, notes, and snippets.

@supphawit
Last active February 12, 2019 09:34
Show Gist options
  • Save supphawit/a35184b0c9d631d5d6f3b76cafecc59d to your computer and use it in GitHub Desktop.
Save supphawit/a35184b0c9d631d5d6f3b76cafecc59d to your computer and use it in GitHub Desktop.
import copy
maze = [[4, 0, 0, 0, 0, 1],
[1, 1, 0, 0, 0, 1],
[0, 0, 0, 1, 0, 0],
[0, 1, 1, 0, 0, 1],
[0, 1, 0, 0, 1, 0],
[0, 1, 0, 0, 0, 3]]
result = []
def _theMaze(maze,x,y,d):
global result
for i, tmp in enumerate(maze):
if 4 in tmp:
pos = (i,tmp.index(4))
x = pos[0]
y = pos[1]
break
if (x >= 0) and (y >= 0) and (y < len(maze[0])) and (x < len(maze)) :
if ((maze[x][y] == 1) or (maze[x][y] == 2)):
return
if (maze[x][y] == 3):
result.append(copy.deepcopy(maze))
if (maze[x][y] == 0):
maze[x][y] = 2
for _d in d:
dx = _d[0]
dy = _d[1]
_theMaze(maze, x+dx, y+dy, d)
maze[x][y] = 0
else:
return
direction = [(-1,0),(0,1),(1,0),(0,-1)]
# Up = (-1,0)
# Right = (0,1)
# Down = (1,0)
# Left (0,-1)
_theMaze(maze,0,0,direction)
for i in result:
for j in i:
print (j)
print ("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment