-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmazegenerator.py
65 lines (54 loc) · 2.22 KB
/
mazegenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# default class for generating a maze
from maze import Maze
import time
import random
from abc import ABC, abstractmethod
class MazeGenerator:
def __init__(self, size):
self.maze = Maze(size)
self.maze.setup_grid()
self.name = "DEFAULT"
self.size = size
self.directory = self.directory = "mazes/" + self.name + "-" + str(self.size) + "x" + str(self.size) + "-" + hex(random.randint(0, 500))
self.matrix = self.maze.matrix
self.duration = 0
def analyze(self, count):
"""
run and print multiple iterations of the maze generation, without saving the PNG
@param count: the number of iterations to execute
"""
durations = []
for _ in range(count):
self.__init__(self.size)
self.generate(save_png=False)
durations.append(self.duration)
print(self.name + ":", str(durations))
def generate(self, history_log=None, save_png=True):
"""
Generate the maze based off the parameters specified in the object parameters
@param history_log: an array of command tuples in the form (<command_string>, <param1>, <param2>, ...)
@param save_png: boolean value indicating if the PNG result should be saved
"""
pass
def save_png(self):
"""
Helper function to save the maze as a PNG
"""
self.maze.image.save("mazes/" + self.name + "-" + str(self.maze.size) + "x" + str(self.maze.size) + "-" +
str(float("%.5f" % self.duration)) + "s.png", "PNG")
def print_results(self):
"""
Prints the results of the maze generation to the console
"""
print("%s: %s x %s" % (self.name, self.maze.size, self.maze.size))
print("--- %s seconds ---" % self.duration)
print("History saved to", self.directory)
def save_history(self, history_log):
"""
Processes the history_log array to generate a folder of PNGs in order to animate the algorithm
@param history_log: an array of command tuples in the form (<command_string>, <param1>, <param2>, ...)
"""
pass
@abstractmethod
def maze_generator_factory(self, size: int):
pass