Пример #1
0
def test_path_2():
    input = """#######...#####
#.....#...#...#
#.....#...#...#
......#...#...#
......#...###.#
......#.....#.#
^########...#.#
......#.#...#.#
......#########
........#...#..
....#########..
....#...#......
....#...#......
....#...#......
....#####......"""

    m = str_to_map(input)
    v = find_vaccumm_robots(m)
    p = find_path(v[0], m)

    cmds = solve_commands(p)

    assert p == [
        "R", "8", "R", "8", "R", "4", "R", "4", "R", "8", "L", "6", "L", "2",
        "R", "4", "R", "4", "R", "8", "R", "8", "R", "8", "L", "6", "L", "2"
    ]

    assert cmds == ["A,B,C,B,A,C", "R,8,R,8", "R,4,R,4,R,8", "L,6,L,2"]
Пример #2
0
def test_can_parse_string_map():
    input = """..#..........
..#..........
#######...###
#.#...#...#.#
#############
..#...#...#..
..#####...^.."""
    m = str_to_map(input)
    s = print_map(m)
    bounds = find_bounds(m)

    intersections = find_intersections(m)

    c = calibrate(intersections)

    v = find_vaccumm_robots(m)
    p = find_path(v[0], m)

    assert s == input
    assert m[(2, 2)] == "#"
    assert bounds == (0, 12, 0, 6)
    assert intersections == [(2, 2), (2, 4), (6, 4), (10, 4)]
    assert c == 76
    assert v[0] == ((10, 6), "^")
    assert p == [
        "4", "R", "2", "R", "2", "R", "12", "R", "2", "R", "6", "R", "4", "R",
        "4", "R", "6"
    ]
Пример #3
0
 def test_easy(self):
     map_ = [[".#",
              "#."],
             ["..",
              ".."]]
     labyrinth = Labyrinth3d(map_)
     info = self.get_info([Location(0, 0, 0),
                           Location(0, 0, 1),
                           Location(0, 1, 1),
                           Location(1, 1, 1),
                           Location(1, 1, 0)],
                          State(Location(1, 1, 0), 0))
     solve_info = solve(labyrinth, Location(0, 0, 0), Location(1, 1, 0), 0)
     path = find_path(labyrinth, solve_info)
     expected = find_path(labyrinth, info)
     self.assertEqual(path, expected)
Пример #4
0
 def test_empty(self):
     map_ = ["...",
             "...",
             "..."]
     labyrinth = Labyrinth3d([map_, map_])
     info = self.get_info([Location(0, 0, 0),
                           Location(0, 0, 1),
                           Location(0, 1, 1),
                           Location(0, 2, 1),
                           Location(1, 2, 1),
                           Location(2, 2, 1)],
                          State(Location(2, 2, 1), 0))
     solve_info = solve(labyrinth, Location(0, 0, 0), Location(2, 2, 1), 0)
     path = find_path(labyrinth, solve_info)
     expected = find_path(labyrinth, info)
     self.assertEqual(path, expected)
Пример #5
0
 def test_economy(self):
     map_ = [[".......",
              "######.",
              "......."]]
     labyrinth = Labyrinth3d(map_)
     info = solve(labyrinth, Location(0, 0), Location(2, 0), 1)
     expected = ["XXXXXXX",
                 "######X",
                 "XXXXXXX"]
     self.assertEqual(find_path(labyrinth, info), expected)
Пример #6
0
 def test_empty(self):
     map_ = ["..",
             ".."]
     labyrinth = Labyrinth3d([map_, map_])
     info = self.get_info([Location(0, 0, 0),
                           Location(1, 0, 0),
                           Location(1, 1, 0),
                           Location(1, 1, 1)],
                          State(Location(1, 1, 1), 0))
     expected = ['X.',
                 'XX',
                 '',
                 '..',
                 '.X']
     self.assertEqual(find_path(labyrinth, info), expected)
Пример #7
0
 def test_bomb_hard(self):
     map_ = ["........",
             "###..#..",
             "#.######",
             "...##..#",
             ".#...#..",
             "........"]
     labyrinth = Labyrinth3d([map_])
     info = solve(labyrinth, Location(0, 0), Location(5, 0), 10)
     expected = ["XX......",
                 "#B#..#..",
                 "#X######",
                 "XX.##..#",
                 "X#...#..",
                 "X......."]
     self.assertEqual(find_path(labyrinth, info), expected)
Пример #8
0
def test_find_path():
    for trips in [
            *examples.trips,
            *[random_trips(random.randint(1, 8)) for _ in range(10)],
    ]:
        waypoint_outputs = find_path(trips)

        assert len(waypoint_outputs) == 2 * len(trips)

        for index, pickup_output in enumerate(waypoint_outputs):
            if pickup_output.type == WaypointType.PICKUP:
                dropoff_outputs = [
                    waypoint_output
                    for waypoint_output in waypoint_outputs[index + 1:]
                    if waypoint_output.trip_id == pickup_output.trip_id
                ]

                assert len(dropoff_outputs) == 1
                assert dropoff_outputs[0].type == WaypointType.DROPOFF
Пример #9
0
 def test_bombs(self):
     map_ = [["....",
              "####",
              "...."],
             ["####",
              "....",
              "####"]]
     labyrinth = Labyrinth3d(map_)
     info = self.get_info([Location(0, 0, 0),
                           Location(1, 0, 0),
                           Location(1, 0, 1),
                           Location(1, 1, 1),
                           Location(1, 2, 1),
                           Location(2, 2, 1)],
                          State(Location(2, 2, 1), 0))
     expected = ["X...",
                 "B###",
                 "....",
                 '',
                 "####",
                 "XXX.",
                 "##B#"]
     self.assertEqual(find_path(labyrinth, info), expected)