def test_left_wall_follow_with_one_possible_path_down_bottom_follows_that_path(self): maze = numpy.array([[1, 0, 1, 1, 1], [1, 0, 1, 1, 1], [1, 0, 1, 1, 1]]) path = solve_maze.wall_follow(maze) self.assertEqual((0, 1), path[0]) self.assertEqual((1, 1), path[1]) self.assertEqual((2, 1), path[2])
def test_left_wall_follow_with_dead_ends_and_spiralling_path_finds_possible_path(self): maze = numpy.array([[1, 0, 1, 0, 0, 0], [1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0], [1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 1, 1]]) path = solve_maze.wall_follow(maze) self.assertEqual((0, 1), path[0]) self.assertEqual((4, 3), path[-1])
def test_left_wall_follow_with_dead_end_to_left_finds_possible_path(self): maze = numpy.array([[1, 1, 0, 1, 1], [1, 0, 0, 0, 1], [1, 1, 1, 0, 1]]) path = solve_maze.wall_follow(maze) self.assertEqual((0, 2), path[0]) self.assertEqual((1, 2), path[1]) self.assertEqual((1, 3), path[2]) self.assertEqual((2, 3), path[3])
def test_left_wall_follow_with_one_possible_path_through_middle_follows_that_path(self): maze = numpy.array([[1, 0, 1, 1, 1], [1, 0, 0, 0, 1], [1, 1, 1, 0, 1]]) path = solve_maze.wall_follow(maze) self.assertEqual((0, 1), path[0]) self.assertEqual((1, 1), path[1]) self.assertEqual((1, 2), path[2]) self.assertEqual((1, 3), path[3]) self.assertEqual((2, 3), path[4])
rect = make_rectangle(rows, row, col, 'brown') ax.add_patch(rect) rect = Rectangle([0, 1], 1.0, 1.0, facecolor='brown', edgecolor='brown') ax.add_patch(rect) rect = Rectangle([cols - 1, 1], 1.0, 1.0, facecolor='brown', edgecolor='brown') ax.add_patch(rect) ax.autoscale_view() plt.draw() return ax; def make_rectangle(rows, row, col, color): (x, y) = (col, row) #(x, y) = (col, rows - row) return Rectangle([x, y], 1.0, 1.0, facecolor=str(color), edgecolor=str(color)) if __name__ == '__main__': maze = generate_maze.maze(30, 15) solution = solve_maze.wall_follow(maze) ax = draw_maze(maze) plt.savefig("solution0.png") draw_paths(maze, solution[1:], ax) #plt.title('Left wall follower') #this doesn't show and it;s right now it's updie down plt.ioff() plt.show() plt.savefig("solution.png")
def test_left_wall_follow_ends_at_the_bottom(self): maze = numpy.array([[1, 0, 1, 1, 1], [1, 0, 0, 0, 1], [1, 1, 1, 0, 1]]) path = solve_maze.wall_follow(maze) self.assertEqual((2, 3), path[-1])
def test_left_wall_follow_starts_at_the_top(self): maze = numpy.array([[1, 0, 1, 1, 1], [1, 0, 0, 0, 1], [1, 1, 1, 0, 1]]) path = solve_maze.wall_follow(maze) self.assertEqual((0, 1), path[0])