def testRandomMaze(): import random import matplotlib.pyplot as plt import time start_time = time.time() maze = Maze() plt.plot(0, 0, 'go') for i in range(10): x = random.randrange(0, 100) y = random.randrange(0, 100) plt.plot(x, y, 'bo') if Node.find_node(x, y) < 0: n = Node(x, y) r = random.choice(list(n.registry.copy())) n.connect_to(r) plt.plot([n.x, r.x], [n.y, r.y], 'r-') r = random.choice(list(n.registry.copy())) n.connect_to(r) plt.plot([n.x, r.x], [n.y, r.y], 'r-') else: print("Node %s already exist at (%d,%d)" % (Node.registry[Node.find_node(x, y)], x, y)) e = random.choice(Node.registry) maze.mark_exit(e) plt.plot(e.x, e.y, 'rd') try: print(maze.find_way_out()) except NoSolution: print("No solution") print("Time spent: " + str(time.time() - start_time)) plt.show()
def testMaze(): maze = Maze() maze.create_origin() n0 = Node(10, 10) n1 = Node(10, 20) n2 = Node(20, 20) n3 = Node(20, 10) n4 = Node(25, 15) n5 = Node(30, 20) maze.origin.connect_to(n0) n0.connect_to(n1) n0.connect_to(n3) n3.connect_to(n4) n4.connect_to(n2) n1.connect_to(n2) n2.connect_to(n5) maze.mark_exit(n5) print(maze.find_way_out())