public void FindAllPathsToAllGoals_SmallMapWithTwoGoals_Finds2PathsWith6Points() { 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<List<Point>> paths = goalMap.FindAllPathsToAllGoals( 3, 4 ); string expectedGoalMapRepresentation = @"# # # # # # # # # 0 1 2 3 # 0 # # 1 # 3 4 # 1 # # 2 # 4 5 # 2 # # 3 4 5 5 4 3 # # # # # # # # #"; Assert.AreEqual( expectedGoalMapRepresentation.Replace( " ", string.Empty ), goalMap.ToString().Replace( " ", string.Empty ) ); Assert.AreEqual( 2, paths.Count ); Assert.AreEqual( 6, paths[0].Count ); Assert.AreEqual( 6, paths[1].Count ); }
public void ManualGoalMapTest() { var map = new ArrayMap <bool>(MAP_WIDTH, MAP_HEIGHT); RectangleMapGenerator.Generate(map); var stateMap = new ArrayMap <GoalState>(map.Width, map.Height); foreach (var pos in stateMap.Positions()) { stateMap[pos] = map[pos] ? GoalState.Clear : GoalState.Obstacle; } stateMap[MAP_WIDTH / 2, MAP_WIDTH / 2] = GoalState.Goal; stateMap[MAP_WIDTH / 2 + 5, MAP_HEIGHT / 2 + 5] = GoalState.Goal; var goalMap = new GoalMap(stateMap, Distance.EUCLIDEAN); goalMap.Update(); Assert.AreEqual(null, goalMap[0, 0]); Console.Write(goalMap.ToString(5, "0.00")); }
public void TryFindPaths_SmallMapWithTwoGoalsOfEqualWeightAndDistance_Finds2PathsWith6Points() { 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); ReadOnlyCollection <Path> paths = goalMap.TryFindPaths(3, 4); string expectedGoalMapRepresentation = @"# # # # # # # # # 0 1 2 3 # 0 # # 1 # 3 4 # 1 # # 2 # 4 5 # 2 # # 3 4 5 5 4 3 # # # # # # # # #"; Assert.AreEqual(RemoveWhiteSpace(expectedGoalMapRepresentation), RemoveWhiteSpace(goalMap.ToString())); Assert.AreEqual(2, paths.Count); Assert.AreEqual(6, paths[0].Length); Assert.AreEqual(6, paths[1].Length); }
public void FindPath_SmallMapAfterAddingAndClearingGoals_PathHasOnePointAndAllCellsAreMax() { 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(); List <Point> obstacles = new List <Point> { new Point(1, 2), new Point(3, 2) }; List <Point> path = goalMap.FindPath(3, 4, obstacles); Assert.AreEqual(1, path.Count); Assert.AreEqual(new Point(3, 4), path[0]); string expectedGoalMapRepresentation = @"# # # # # # # # # 48 48 48 48 # 48 # # 48 # 48 48 # 48 # # 48 # 48 48 # 48 # # 48 48 48 48 48 48 # # # # # # # # #"; Assert.AreEqual(expectedGoalMapRepresentation.Replace(" ", string.Empty), goalMap.ToString().Replace(" ", string.Empty)); }
public void FindAllPathsToAllGoals_SmallMapWithTwoGoals_Finds2PathsWith6Points() { 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 <List <Point> > paths = goalMap.FindAllPathsToAllGoals(3, 4); string expectedGoalMapRepresentation = @"# # # # # # # # # 0 1 2 3 # 0 # # 1 # 3 4 # 1 # # 2 # 4 5 # 2 # # 3 4 5 5 4 3 # # # # # # # # #"; Assert.AreEqual(expectedGoalMapRepresentation.Replace(" ", string.Empty), goalMap.ToString().Replace(" ", string.Empty)); Assert.AreEqual(2, paths.Count); Assert.AreEqual(6, paths[0].Count); Assert.AreEqual(6, paths[1].Count); }
public void FindPath_SmallMapAfterAddingAndClearingGoals_PathHasOnePointAndAllCellsAreMax() { 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(); List<Point> obstacles = new List<Point> { new Point( 1, 2 ), new Point( 3, 2 ) }; List<Point> path = goalMap.FindPath( 3, 4, obstacles ); Assert.AreEqual( 1, path.Count ); Assert.AreEqual( new Point( 3, 4 ), path[0] ); string expectedGoalMapRepresentation = @"# # # # # # # # # 48 48 48 48 # 48 # # 48 # 48 48 # 48 # # 48 # 48 48 # 48 # # 48 48 48 48 48 48 # # # # # # # # #"; Assert.AreEqual( expectedGoalMapRepresentation.Replace( " ", string.Empty ), goalMap.ToString().Replace( " ", string.Empty ) ); }