def generate(self, width, height): graph = Graph(width, height) visited_nodes = set() nodes = list(flatten(graph.nodes)) node = choice(nodes) nodes.remove(node) visited_nodes.add(node) while nodes: path = {} node = n = choice(nodes) while node not in visited_nodes: next = choice(list(graph.get_neighbours_for_node(node))) path[node] = next node = next node = n while node not in visited_nodes: next = path[node] node.connect(next) visited_nodes.add(node) nodes.remove(node) node = next return graph
def generate(self, width, height): graph = Graph(width, height) total_nodes = width * height visited_nodes = set() node = choice(choice(graph.nodes)) visited_nodes.add(node) while len(visited_nodes) < total_nodes: next = choice(list(graph.get_neighbours_for_node(node))) if next not in visited_nodes: node.connect(next) visited_nodes.add(next) node = next return graph