def _generate(self, w, h, complex): ''' 产生一个特定的迷宫 :param w: int 迷宫宽度 :param h: int 迷宫高度 :param complex: float 算法复杂度,与搜索复杂度不同 :return: Maze 迷宫对象 ''' m = Maze() m.generator = CellularAutomaton(w, h, complex, default_density) m.generate() m.solver = BacktrackingSolver() #m.start = (1, 1) #m.end = (w, h) m.generate_entrances() m.solve() return m
def generate_maps(tag: str, dest: str, count: int, xsize: int, ysize: int): for i in range(count): # Initialise ith maze. m = Maze(i) # Set up generator and generate. # CellularAutomaton is used as it often gives multiple # possible solutions for larger map sizes. m.generator = CellularAutomaton(xsize, ysize) m.generate() m.generate_entrances(False, False) with open(path_join(dest, f"{tag}.{i}.unsolved.map"), "w") as f: f.write(str(m)) m.solver = ShortestPath() m.solve() with open(path_join(dest, f"{tag}.{i}.solved.map"), "w") as f: f.write(str(m))
from mazelib import Maze from mazelib.solve.BacktrackingSolver import BacktrackingSolver import numpy as np m = Maze() m.solver = BacktrackingSolver() miz = [[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ], [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1], [ 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1 ], [ 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 ], [ 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ], [ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ], [ 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1 ], [ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1