Esempio n. 1
0
 def handle(self, *args, **options):
     m = Maze()
     m.generator = Prims(10, 10)
     m.generate()
     m.generate_entrances()
     print()
     self.stdout.write(self.style.SUCCESS('Successfully generated'))
Esempio n. 2
0
 def generate_data(self):
     results = []
     for i in range(self.count):
         m = Maze()
         m.generator = Prims(20, 20)
         m.generate()
         m.generate_entrances()
         results.append(toHTML(m.grid, m.start, m.end, 25))
     self.data = results
     return self.data
Esempio n. 3
0
 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))
Esempio n. 5
0
import pygame as py

screen_height = 880
screen_width = int(screen_height * 1.0)

mx = 11
my = 11  # width and height of the maze
size = screen_height / mx

colors = [(0, 0, 0), (0, 200, 0), (255, 0, 0),
          (255, 255, 0)]  # RGB colors of the maze

m = Maze()
m.generator = Prims(5, 5)
m.generate()
m.generate_entrances(True, True)
print(m.tostring(True))
m.grid[m.start[0]][m.start[1]] = 2
m.grid[m.end[0]][m.end[1]] = 3

py.init()

screen = py.display
screen_surf = screen.set_mode((screen_width, screen_height))


class Player(object):
    def __init__(self, pos):
        self.rect = py.Rect(pos[1] * size, pos[0] * size, size - 1, size - 1)

    def move(self, dx, dy):