Example #1
0
def test_paired_rats():
    maze = MultiRatMaze(random_maze(0.5, OneDimensionalLocalizer(6, 3)), False)
    #render_graph(maze.maze(), "temp/paired")
    print(maze)
    rats = [(PairedAlwaysLeftRat(0), 1), (PairedAlwaysLeftRat(1), 2)]
    MAX_ITER = 1000
    iter = maze.solve(rats, MAX_ITER, False, PairedRatMazeInfo())
    print("test_paired_rats solved in %i iterations" % iter)
    assert(iter > 0 and iter < MAX_ITER)
Example #2
0
def test_random_1d_maze():
    maze = SimpleMaze(random_maze(0.5, OneDimensionalLocalizer(25, 5)), False)
    #print(maze)
    render_graph(maze.maze(), "temp/random_1d_maze")
    rat = RandomRat()
    MAX_ITER = 1000
    iter = maze.solve(rat, MAX_ITER)
    print("test_random_1d_maze solved in %i iterations" % iter)
    assert (iter > 0 and iter < MAX_ITER)
Example #3
0
def test_dijkstras_algo():
    SIZE = 25
    maze = random_maze(0.5, OneDimensionalLocalizer(SIZE, 5))
    #print(maze)
    render_graph(maze, "temp/dijkstras_maze")
    distances = dijkstra(maze, 0, SIZE)
    print("test_dijkstras_algo calculated distance to end as %i" %
          distances[SIZE])
    assert (len(distances) == SIZE + 1)
Example #4
0
def test_rat_chat():
    maze = MultiRatMaze(random_maze(0.5, OneDimensionalLocalizer(25, 5)),
                        False)
    render_graph(maze.maze(), "temp/rat_chat")
    rats = [(TestChatRat(0), 2), (TestChatRat(1), 3), (TestChatRat(2), 4)]
    MAX_ITER = 1000
    iter = maze.solve(rats, MAX_ITER, False, RatChatMazeInfo())
    print("test_paired_rats solved in %i iterations" % iter)
    assert (iter > 0 and iter < MAX_ITER)
Example #5
0
def test_memory_rat_no_loops():
    maze = SimpleMaze(random_maze(0.0, OneDimensionalLocalizer(25, 5)), False)
    rat = MemoryRat()
    MAX_ITER = 1000
    iter = maze.solve(rat, MAX_ITER)
    #render_graph(maze.maze(), "temp/memory_maze")
    #render_graph(rat.final_picture(), "temp/memory_picture")
    assert (are_equal_mazes(rat.final_picture(), maze.maze()))
    print("test_memory_rat_no_loops solved in %i iterations" % iter)
    assert (iter > 0 and iter < MAX_ITER)
Example #6
0
def test_cooperative_rats_loops():
    maze = MultiRatMaze(random_maze(0.1, OneDimensionalLocalizer(25, 5)),
                        False)
    #render_graph(maze.maze(), "temp/cooperative_maze_loops")
    # print(maze.maze())
    rats = [(CooperativeRat(r), 1) for r in ["Alice", "Bert", "Charlie"]]
    MAX_ITER = 1000
    iter = maze.solve(rats, MAX_ITER, False, RatChatMazeInfo())
    print("test_cooperative_rats_loops solved in %i iterations" % iter)
    assert (iter > 0 and iter < MAX_ITER)
Example #7
0
def test_random_1d_multimaze():
    maze = MultiRatMaze(random_maze(0.5, OneDimensionalLocalizer(25, 5)),
                        False)
    render_graph(maze.maze(), "temp/random_1d_multimaze")
    rat = RandomRat()
    rats = [(rat, 2), (rat, 3)]
    MAX_ITER = 1000
    iter = maze.solve(rats, MAX_ITER)
    print("test_random_1d_multimaze solved in %i iterations" % iter)
    assert (iter > 0 and iter < MAX_ITER)
Example #8
0
def test_tremaux_rat():
    SIZE = 25
    maze = SimpleMaze(random_maze(0.5, OneDimensionalLocalizer(SIZE, 3)),
                      False)
    #print(maze)
    render_graph(maze.maze(), "temp/tremaux_maze")
    rat = TremauxRat()
    info = TremauxMazeInfo()
    MAX_ITER = 100
    iter = maze.solve(rat, MAX_ITER, info)
    print("test_tremaux_rat solved in %i iterations" % iter)
    assert (iter > 0 and iter < MAX_ITER)
Example #9
0
def test_dijkstras_rat():
    SIZE = 6
    maze = SimpleMaze(random_maze(0.5, OneDimensionalLocalizer(SIZE, 3)), False)
    #print(maze)
    render_graph(maze.maze(), "temp/dijkstras_maze")
    rat = DijkstrasRat(SIZE)
    info = DijkstrasMazeInfo(maze.maze())
    MAX_ITER = 30
    iter = maze.solve(rat, MAX_ITER, info)
    print("test_dijkstras_rat solved in %i iterations" % iter)
    print("  distance from start to end is %i" % rat.distance_to_end())
    assert(iter > 0 and iter < MAX_ITER)
Example #10
0
def test_memory_rat_loops():
    maze = SimpleMaze(random_maze(0.5, OneDimensionalLocalizer(25, 5)), False)
    rat = MemoryRat()
    MAX_ITER = 1000
    iter = maze.solve(rat, MAX_ITER)
    #render_graph(maze.maze(), "temp/memory_maze_loops")
    #if len(rat.final_picture()) < 26:
    #    render_graph(rat.final_picture(), "temp/memory_picture_loops")
    #assert(are_equal_mazes(rat.final_picture(), maze.maze()))

    # are_equal_mazes just blows up out of recursion space if the final_picture
    # is too big.
    final = rat.final_picture()
    if len(final) < 100:
        assert (are_equal_mazes(final, maze.maze()))
    print("test_memory_rat_loops solved in %i iterations" % iter)
    assert (iter > 0 and iter < MAX_ITER)