Python实现递归生成迷宫算法
写一个类来储存代表迷宫的列表,包含若干方法
import random
import copy
class Maze:
'''
scale is the size of the maze
'''
def __init__(self,scale=10):
self.scale = scale
'''
maze: *maze_map: a 2D list that store the map of the maze
fin; *finish_state: a 2D list that store the state of each block in de maze
'''
self.maze = [['▇']*(self.scale*2+1) for i in range(self.scale*2+1)]
self.fin = [[False]*(self.scale) for i in range(self.scale)]
'''
some vars related to the anwser path
'''
self.vis = [[False]*(self.scale*2+1) for i in range(self.scale*2+1)]
self.ans = []
def __gen_maze(self,cur_x=1