public void TryFindPath_SmallMapWithTwoGoalsAndTwoObstacles_FindsBestPath() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #......# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map); goalMap.AddGoal(1, 1, 0); goalMap.AddGoal(6, 1, 0); List <Point> obstacles = new List <Point> { new Point(1, 2), new Point(3, 2) }; goalMap.AddObstacles(obstacles); Path path = goalMap.TryFindPath(3, 4); Assert.AreEqual(7, path.Length); ICell stepForward = path.StepForward(); Assert.AreEqual(new Cell(4, 4, true, true, false), stepForward); }
public void TryFindPath_BigMapFromGameAllowingDiagonalMovement_ExpectedPath() { string mapRepresentation = @"########################################################### #.....#...............#...#.....#.....#.s.....s...........# #.....#.#.###########.#...#.#.#.#.....#.#.....#.#.#######.# #.....#.#.#.....s...#.#...s.#.#.#.....#.#.....#.#.#.....#.# #.....#.#.#.....#...#####s#s#######s#####.....#.#.#.....#.# #.....s.#.s.....#...s.....#.......#.#...#.....#.#.#.....s.# #######s#.#######...#.....#.......#.#...#.....#.#.#######.# #.......#.#.....#...#.....#.......#.s...#.....#.#.......#.# #.......#.s.....#####s#.###.......#.#...#####s#.#.####s#### #.......#.#.....s.#...#...#.......s.#...#.s...#.#.#.......# #.......###########...#.###############s###...#.#.#.......# #.......s...#.#...#...#.#.......#.#.......#...#.#.#.......# #######s#...#.#...##s##.s.......#.#.......#...#######s##### #.#.....#...#.#...#...#.#.......#.#.......s...#.....#...#.# #.#.....#...#.#...#####.#.......s.##s######...#.....#...#.# #.#.....#...#.#...#...#.#.......#.#.....#.#...s.....#...#.# #.#.....#...s.###s#...#.####s######.....#s#####s#####...s.# #.#.....#...#.....s...#...#...#...#.....s.....#.....#...#.# #.#.....#####.#.#.#...#.#.#...s...#s#####.....###s###...#.# #.#.....s...#.#.#.#...#.#.#...#...#.....#.....#.....#...#.# #.##s##############...###.######s##############.....####### #.........#.......#...#.......#...#.......#...#.....s.#...# #.#.#.#.#.#.......#####.......#####.......#.###########...# #.#.#.#.#.s.......#...#.......#...#.......s.#.....#...#...# ###s###############...#.......#...####s####.s.....s...#...# #...#.......#.....s...#.......s...#.......#.#.....#...#...# #...#.......#######s###.......##########s##.###s###...s...# #...#.......s...s...#.#.......#.s...#.....#.#...#.#...#...# #...#.......#...#...s.###########...#.....#.#...#.######### #...#.......#...#...#...........#...#.....#.#...#.........# #...#.......######s##.###s#####.#...#.....#.#...#.#######.# #...s.......#.......#.#.......#.s...#.....#.#...s.#.....#.# ########s####.#.#.#.#.#.......#.#...###s###.#######.....s.# #...........#.#.#.#.#.#.......#.#...s.....#.......#.....#.# ###########################################################"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map, true); goalMap.AddGoal(51, 31, 0); goalMap.AddGoal(51, 33, 0); string expectedPath = "...s...s.....s........s.....s.......s...s......s.......s...s...s...........s...s..s.....s.s...s.s..s....s..........s....."; Path path = goalMap.TryFindPath(23, 7); var actualPath = new StringBuilder(); foreach (ICell cell in path.Steps) { actualPath.Append(cell.ToString()); } Assert.AreEqual(expectedPath, actualPath.ToString()); }
public void TryFindPath_DestinationNotWalkableAnd13StepsAway_ReturnsNull() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #......# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map); goalMap.AddGoal(7, 1, 0); Path path = goalMap.TryFindPath(1, 1); Assert.AreEqual(null, path); }
public void TryFindPath_DestinationUnreachable_ReturnsNull() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #....#.# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map); goalMap.AddGoal(6, 1, 0); var paths = goalMap.TryFindPath(1, 1); Assert.AreEqual(null, paths); }
public void TryFindPath_SmallMapAfterAddingAndClearingGoals_ReturnsNull() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #......# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map); goalMap.AddGoal(1, 1, 0); goalMap.AddGoal(6, 1, 0); goalMap.ClearGoals(); Path path = goalMap.TryFindPath(3, 4); Assert.AreEqual(null, path); }