class Maze():
def __init__(self):
self.n = 4
def printSolution(self, sol):
i = 0
while i<self.n :
j = 0
while j<self.n :
print(sol[i][j],end='')
j += 1
print('')
i += 1
def isSafe(self,maze,x,y):
return x>=0 and x<self.n and y>=0 and y<self.n and maze[x][y]==1
def getPath(self,maze,x,y,sol):
if x == (self.n - 1) and y == (self.n - 1) :
sol[x][y] = 1
return True
if self.isSafe(maze,x,y):
sol[x][y] = 1
if self.getPath(maze, x+1, y, sol):
return True
if self.getPath(maze, x, y+1, sol):
return True
sol[x][y] = 0
return False
return False
if __name__ == '__main__' :
rat = M
Python:如何求解迷宫问题
最新推荐文章于 2024-04-22 23:57:03 发布