public void FindPathAvoiding_NoPathExists_ThrowsPathNotFoundException() { string mapRepresentation = @"############################################### #..........#......................##..........# #..........#..........##..........##..........# #..........#..........##..........##..........# #..........#..........##..........##..........# #.....................##......................# ###############################################"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map); goalMap.AddGoal(2, 2, 0); goalMap.AddObstacle(2, 1); goalMap.AddObstacle(1, 2); Path path = goalMap.FindPathAvoidingGoals(1, 1); }
public void TryFindPathAvoiding_NoPathExists_ReturnsNull() { string mapRepresentation = @"############################################### #..........#......................##..........# #..........#..........##..........##..........# #..........#..........##..........##..........# #..........#..........##..........##..........# #.....................##......................# ###############################################"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map); goalMap.AddGoal(2, 2, 0); goalMap.AddObstacle(2, 1); goalMap.AddObstacle(1, 1); Path path = goalMap.TryFindPathAvoidingGoals(1, 1); Assert.AreEqual(null, path); }
private GoalMap CreateGoalMap() { var goalMap = new GoalMap(map.GetIMap()); // Aim for our random goal goalMap.AddGoal(this.goal.X, this.goal.Y, 100); // Avoid ANYTHING that's solid foreach (var e in map.Objects) { if (e.IsSolid && e != this) { goalMap.AddObstacle(e.X, e.Y); } } return(goalMap); }
public void TryFindPathAvoiding_BoxedInCornerWithObstacle_ExpectedPath() { string mapRepresentation = @"############################################### #..........#......................##..........# #..........#..........##..........##..........# #..........#..........##..........##..........# #..........#..........##..........##..........# #.....................##......................# ###############################################"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map); goalMap.AddGoal(2, 2, 0); goalMap.AddObstacle(2, 1); Path path = goalMap.TryFindPathAvoidingGoals(1, 1); Assert.AreEqual(61, path.Length); Assert.AreEqual(map.GetCell(1, 2), path.StepForward()); Assert.AreEqual(map.GetCell(1, 1), path.Start); Assert.AreEqual(map.GetCell(45, 1), path.End); }