def test_longest_path_to_tail(self): m = Map(6, 6) m.create_food(Pos(4, 4)) s = Snake(m, Direc.RIGHT, [Pos(1, 3), Pos(1, 2), Pos(1, 1)], [PointType.HEAD_R, PointType.BODY_HOR, PointType.BODY_HOR]) solver = PathSolver(s) # noinspection PyUnusedLocal act_path = solver.longest_path_to_tail() act_path = solver.longest_path_to_tail() # Check idempotency expect_path = [ Direc.RIGHT, Direc.DOWN, Direc.DOWN, Direc.DOWN, Direc.LEFT, Direc.LEFT, Direc.LEFT, Direc.UP, Direc.RIGHT, Direc.RIGHT, Direc.UP, Direc.LEFT, Direc.LEFT, Direc.UP ] assert m.point(s.tail()).type == PointType.BODY_HOR assert len(act_path) == len(expect_path) for i, direc in enumerate(act_path): assert direc == expect_path[i] # Empty path because the tail has not been 'emptied' yet, # so it is not a valid position to be added to the queue. # This means that after all the evaluations, None of them check the snake tail # Because it is not valid, according to the function, since # it is part of the body. # Therefore, we pass the path finders through a function called path_to # to remove the 'tail' at that location so it can be evaluated. assert not solver.longest_path_to(s.tail())
def test_longest(): m = Map(6, 6) m.create_food(Pos(4, 4)) s = Snake(m, Direc.RIGHT, [Pos(1, 3), Pos(1, 2), Pos(1, 1)], [PointType.HEAD_R, PointType.BODY_HOR, PointType.BODY_HOR]) solver = PathSolver(s) act_path = solver.longest_path_to_tail() act_path = solver.longest_path_to_tail() # Check idempotence expect_path = [ Direc.RIGHT, Direc.DOWN, Direc.DOWN, Direc.DOWN, Direc.LEFT, Direc.LEFT, Direc.LEFT, Direc.UP, Direc.RIGHT, Direc.RIGHT, Direc.UP, Direc.LEFT, Direc.LEFT, Direc.UP ] assert m.point(s.tail()).type == PointType.BODY_HOR assert len(act_path) == len(expect_path) for i, direc in enumerate(act_path): assert direc == expect_path[i] # Empty path assert not solver.longest_path_to(s.tail())