public void ComputeFov_SmallMap_ExpectedFov() { string mapRepresentation = @"#################################### #..................................# #..###.########....................# #....#.#......#....................# #....#.#......#....................# #.............#....................# #....#.#......###################### #....#.#...........................# #....#.#...........................# #..................................# ####################################"; IMapCreationStrategy <Map> mapCreationStrategy2 = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy2); map.ComputeFov(6, 1, 20, true); string expectedFov = @"###########################%%%%%%%%% #..........................%%%%%%%%% #..###.########%%.........%%%%%%%%%% #%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%###%%%%%%%%%%%%%%%%%%%%%%%%%%%%"; Assert.AreEqual(expectedFov.Replace(" ", ""), map.ToString(true)); }
public void TryFindShortestPath_Large200x400MapTrying12KnownPaths_ReturnsExpectedPaths() { KnownSeriesRandom randomX = new KnownSeriesRandom(150, 137, 51, 31, 40, 135, 116, 148, 83, 94, 153, 30, 63, 80, 31, 107, 64, 95, 6, 145, 105, 66, 96, 37); KnownSeriesRandom randomY = new KnownSeriesRandom(255, 359, 175, 279, 169, 293, 335, 208, 235, 327, 67, 234, 56, 272, 241, 215, 230, 377, 194, 301, 161, 348, 89, 171); int[] pathLengths = { 822, 229, 598, 730, 344, 507, 398, 655, 737, 799, 683, 350 }; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(Algorithms.TestSetup.TestHelpers.Map200x400); IMap map = Map.Create(mapCreationStrategy); PathFinder pathFinder = new PathFinder(map); for (int i = 0; i < 12; i++) { int x1 = randomX.Next(199); int y1 = randomY.Next(399); int x2 = randomX.Next(199); int y2 = randomY.Next(399); ICell source = map.GetCell(x1, y1); ICell destination = map.GetCell(x2, y2); Stopwatch timer = Stopwatch.StartNew(); Path shortestPath = pathFinder.TryFindShortestPath(source, destination); Console.WriteLine( $"Path from `{x1}:{y1}` to `{x2}:{y2}` was {shortestPath?.Steps?.Count()} long and took Elapsed Milliseconds: {timer.ElapsedMilliseconds}"); Assert.AreEqual(pathLengths[i % 12], shortestPath?.Steps?.Count()); } }
public void ComputeFov_X6Y1CellRadius20_ExpectedFovMap() { string mapRepresentation = @"#################################### #..................................# #..###.########....................# #....#.#......#....................# #....#.#......#....................# #.............#....................# #....#.#......###################### #....#.#...........................# #....#.#...........................# #..................................# ####################################"; IMapCreationStrategy <LibtcodMap> mapCreationStrategy = new StringDeserializeMapCreationStrategy <LibtcodMap>(mapRepresentation); IMap map = LibtcodMap.Create(mapCreationStrategy); map.ComputeFov(6, 1, 20, true); string expectedFovMap = @"###########################%%%%%%%%% #..........................%%%%%%%%% #..###.########%%.........%%%%%%%%%% #%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%###%%%%%%%%%%%%%%%%%%%%%%%%%%%%"; Assert.AreEqual(expectedFovMap.Replace(" ", string.Empty), map.ToString(true)); }
public void ComputeFov_X6Y1CellRadius20_ExpectedFovMap() { string mapRepresentation = @"#################################### #..................................# #..###.########....................# #....#.#......#....................# #....#.#......#....................# #.............#....................# #....#.#......###################### #....#.#...........................# #....#.#...........................# #..................................# ####################################"; IMapCreationStrategy<LibtcodMap> mapCreationStrategy = new StringDeserializeMapCreationStrategy<LibtcodMap>( mapRepresentation ); IMap map = LibtcodMap.Create( mapCreationStrategy ); map.ComputeFov( 6, 1, 20, true ); string expectedFovMap = @"###########################%%%%%%%%% #..........................%%%%%%%%% #..###.########%%.........%%%%%%%%%% #%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%###%%%%%%%%%%%%%%%%%%%%%%%%%%%%"; Assert.AreEqual( expectedFovMap.Replace( " ", string.Empty ), map.ToString( true ) ); }
public void FindPathAvoiding_BoxedInCornerWithObstacle_ExpectedPath() { string mapRepresentation = @"########### #.....#...# #.....#.#.# #.....#.#.# #.....#.#.# #.....s.#.# ###########"; IMapCreationStrategy<Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy<Map>( mapRepresentation ); IMap map = Map.Create( mapCreationStrategy ); GoalMap goalMap = new GoalMap( map ); goalMap.AddGoal( 2, 2, 0 ); Point obstacle = new Point( 2, 2 ); string expectedPath = "........s..........."; List<Point> path = goalMap.FindPathAvoidingGoals( 1, 2, new List<Point> { obstacle } ); var actualPath = new StringBuilder(); foreach( Point p in path ) { actualPath.Append( map.GetCell( p.X, p.Y ).ToString() ); } Assert.AreEqual( expectedPath, actualPath.ToString() ); }
public void ComputeFov_SmallMap_ExpectedFov() { string mapRepresentation = @"#################################### #..................................# #..###.########....................# #....#.#......#....................# #....#.#......#....................# #.............#....................# #....#.#......###################### #....#.#...........................# #....#.#...........................# #..................................# ####################################"; IMapCreationStrategy<Map> mapCreationStrategy2 = new StringDeserializeMapCreationStrategy<Map>( mapRepresentation ); IMap map = Map.Create( mapCreationStrategy2 ); map.ComputeFov( 6, 1, 20, true ); string expectedFov = @"###########################%%%%%%%%% #..........................%%%%%%%%% #..###.########%%.........%%%%%%%%%% #%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%###%%%%%%%%%%%%%%%%%%%%%%%%%%%%"; Assert.AreEqual( expectedFov.Replace( " ", "" ), map.ToString( true ) ); }
public void GetCellsInDiamond_SmallMap_ExpectedCells() { string mapRepresentation = @"################# ################# ##...#######...## ##.............## ###.###....#...## ###...##.#####.## ###...##...###..# ####............# ##############..# #################"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); string expectedCells = "#..##......#."; IEnumerable <Cell> cells = map.GetCellsInDiamond(3, 3, 3) .OrderBy(c => c.Point.X) .ThenBy(c => c.Point.Y); var actualCells = new StringBuilder(); foreach (Cell cell in cells) { actualCells.Append(cell.ToString()); } Assert.AreEqual(expectedCells, actualCells.ToString()); }
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_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.FindPath(3, 4); Assert.AreEqual(7, path.Length); ICell stepForward = path.StepForward(); Assert.AreEqual(new Cell(4, 4, true, true), stepForward); }
public void AppendFov_X6Y1CellRadius20AndX15Y1CellRadius5_ExpectedFovMap() { string mapRepresentation = @"#################################### #..................................# #..###.########....................# #....#.#......#....................# #....#.#......#....................# #.............#....................# #....#.#......###################### #....#.#...........................# #....#.#...........................# #..................................# ####################################"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); map.ComputeFov(6, 1, 20, true); var visibleCells = map.AppendFov(15, 1, 5, true); string expectedFovMap = @"###########################%%%%%%%%% #..........................%%%%%%%%% #..###.########...........%%%%%%%%%% #%%%%#.#%%%%%%#....%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%#...%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%#..%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%####%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%###%%%%%%%%%%%%%%%%%%%%%%%%%%%%"; Assert.AreEqual(RemoveWhiteSpace(expectedFovMap), RemoveWhiteSpace(map.ToString(true))); Assert.AreEqual(117, visibleCells.Count); }
public void ComputeFov_EmptyMap_ExpectedCollectionOfVisibleCells() { string mapRepresentation = @"#################################### #..................................# #..................................# #..................................# #..................................# #..................................# #..................................# #..................................# #..................................# #..................................# ####################################"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); map.ComputeFov(15, 5, 3, false); string expectedFovMap = @"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%.%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%...%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%.....%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%.......%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%.....%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%...%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%.%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"; Assert.AreEqual(RemoveWhiteSpace(expectedFovMap), RemoveWhiteSpace(map.ToString(true))); }
public void GetBorderCellsInSquare_CenteredOnX0Y0InSmallMap_ExpectedCellsWithoutCenterCell() { string mapRepresentation = @"################# ################# ##...#######...## ##.............## ###.###....#...## ###...##.#####.## ###...##...###..# ####............# ##############..# #################"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); string expectedCells = "###"; IEnumerable <Cell> cells = map.GetBorderCellsInSquare(0, 0, 1) .OrderBy(c => c.Point.X) .ThenBy(c => c.Point.Y); var actualCells = new StringBuilder(); foreach (Cell cell in cells) { actualCells.Append(cell.ToString()); } Assert.AreEqual(expectedCells, actualCells.ToString()); }
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_BigMapFromGame_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); 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......"; List <Point> path = goalMap.FindPath(23, 7, new List <Point>()); var actualPath = new StringBuilder(); foreach (Point p in path) { actualPath.Append(map.GetCell(p.X, p.Y).ToString()); } Assert.AreEqual(expectedPath, actualPath.ToString()); }
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 AppendFov_SmallMap_ExpectedCollectionOfVisibleCells() { string mapRepresentation = @"#################################### #..................................# #..###.########....................# #....#.#......#....................# #....#.#......#....................# #.............#....................# #....#.#......###################### #....#.#...........................# #....#.#...........................# #..................................# ####################################"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); var fieldOfView = new FieldOfView(map); fieldOfView.ComputeFov(6, 1, 20, true); var visibleCells = fieldOfView.AppendFov(15, 1, 5, true); // The field of view should be calculated as follows // // ###########################%%%%%%%%% // #..........................%%%%%%%%% // #..###.########...........%%%%%%%%%% // #%%%%#.#%%%%%%#....%%%%%%%%%%%%%%%%% // %%%%%#.#%%%%%%#...%%%%%%%%%%%%%%%%%% // %%%%%%.%%%%%%%#..%%%%%%%%%%%%%%%%%%% // %%%%%#.#%%%%%%####%%%%%%%%%%%%%%%%%% // %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%###%%%%%%%%%%%%%%%%%%%%%%%%%%%% int floorCells = 0; int wallCells = 0; foreach (ICell cell in visibleCells) { if (cell.IsWalkable) { floorCells++; } else { wallCells++; } } Assert.AreEqual(117, visibleCells.Count); Assert.AreEqual(56, floorCells); Assert.AreEqual(61, wallCells); }
public void TryFindShortestPath_Large200x400MapTrying24KnownPathsFrom1Source_ReturnsExpectedPaths() { KnownSeriesRandom randomX = new KnownSeriesRandom(150, 137, 51, 31, 40, 135, 116, 148, 83, 94, 153, 30, 63, 80, 31, 107, 64, 95, 6, 145, 105, 66, 96, 37); KnownSeriesRandom randomY = new KnownSeriesRandom(255, 359, 175, 279, 169, 293, 335, 208, 235, 327, 67, 234, 56, 272, 241, 215, 230, 377, 194, 301, 161, 348, 89, 171); int[] pathLengths = { 398, 489, 219, 423, 206, 421, 444, 351, 311, 414, 213, 323, 118, 345, 369, 315, 301, 465, 389, 439, 259, 453, 178, 201 }; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(Algorithms.TestSetup.TestHelpers.Map200x400); IMap map = Map.Create(mapCreationStrategy); DijkstraPathFinder dijkstraPathFinder = new DijkstraPathFinder(map); for (int i = 0; i < 24; i++) { int x1 = 7; int y1 = 1; int x2 = randomX.Next(199); int y2 = randomY.Next(399); ICell source = map.GetCell(x1, y1); ICell destination = map.GetCell(x2, y2); Stopwatch timer = Stopwatch.StartNew(); Path shortestPath = dijkstraPathFinder.TryFindShortestPath(source, destination); Console.WriteLine( $"Path from `{x1}:{y1}` to `{x2}:{y2}` was {shortestPath?.Steps?.Count()} long and took Elapsed Milliseconds: {timer.ElapsedMilliseconds}"); Assert.AreEqual(pathLengths[i % 24], shortestPath?.Steps?.Count()); } // Sample Output (Release Mode) //Path from `7:1` to `150:255` was 398 long and took Elapsed Milliseconds: 36 //Path from `7:1` to `137:359` was 489 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `51:175` was 219 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `31:279` was 423 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `40:169` was 206 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `135:293` was 421 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `116:335` was 444 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `148:208` was 351 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `83:235` was 311 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `94:327` was 414 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `153:67` was 213 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `30:234` was 323 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `63:56` was 118 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `80:272` was 345 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `31:241` was 369 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `107:215` was 315 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `64:230` was 301 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `95:377` was 465 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `6:194` was 389 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `145:301` was 439 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `105:161` was 259 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `66:348` was 453 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `96:89` was 178 long and took Elapsed Milliseconds: 0 //Path from `7:1` to `37:171` was 201 long and took Elapsed Milliseconds: 0 }
public void Create_StringDeserializeMapCreationStrategy_ExpectedMap() { string expectedMapRepresentation = @"#### #..# #so# ####"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(expectedMapRepresentation); IMap actualMap = Map.Create(mapCreationStrategy); Assert.AreEqual(RemoveWhiteSpace(expectedMapRepresentation), RemoveWhiteSpace(actualMap.ToString())); }
public void Create_StringDeserializeMapCreationStrategy_ExpectedMap() { string expectedMapRepresentation = @"#### #..# #so# ####"; IMapCreationStrategy <LibtcodMap> mapCreationStrategy = new StringDeserializeMapCreationStrategy <LibtcodMap>(expectedMapRepresentation); IMap actualMap = LibtcodMap.Create(mapCreationStrategy); Assert.AreEqual(expectedMapRepresentation.Replace(" ", string.Empty), actualMap.ToString()); }
public void GetAdjacentCells_X1Y1WithDiagonals_Returns8Cells() { string mapRepresentation = @"... ... ..."; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); IEnumerable <Cell> cells = map.GetAdjacentCells(1, 1, true); Assert.AreEqual(8, cells.Count()); }
public void GetAdjacentCells_BottomRightCorner_Returns2Cells() { string mapRepresentation = @"... ... ..."; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); IEnumerable <Cell> cells = map.GetAdjacentCells(2, 2); Assert.AreEqual(2, cells.Count()); }
public void TryFindShortestPath_Large200x400MapFromX5Y1ToX29Y187_ReturnsExpectedPath() { IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(Algorithms.TestSetup.TestHelpers.Map200x400); IMap map = Map.Create(mapCreationStrategy); ICell source = map.GetCell(5, 1); ICell destination = map.GetCell(29, 187); PathFinder pathFinder = new PathFinder(map); Path shortestPath = pathFinder.TryFindShortestPath(source, destination); Assert.AreEqual(705, shortestPath.Length); }
public void Clone_SmallMap_MapAndCloneHaveDifferentReferencesButSameValues() { string mapRepresentation = @"#### #..# #so# ####"; IMapCreationStrategy<LibtcodMap> mapCreationStrategy = new StringDeserializeMapCreationStrategy<LibtcodMap>( mapRepresentation ); IMap originalMap = LibtcodMap.Create( mapCreationStrategy ); IMap clonedMap = originalMap.Clone(); Assert.AreNotEqual( originalMap, clonedMap ); Assert.AreEqual( originalMap.ToString(), clonedMap.ToString() ); }
public void Clone_SmallMap_MapAndCloneHaveDifferentReferencesButSameValues() { string mapRepresentation = @"#### #..# #so# ####"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap originalMap = Map.Create(mapCreationStrategy); IMap clonedMap = originalMap.Clone(); Assert.AreNotEqual(originalMap, clonedMap); Assert.AreEqual(RemoveWhiteSpace(originalMap.ToString()), RemoveWhiteSpace(clonedMap.ToString())); }
public void ShortestPath_SourceCellNotWalkable_ThrowsPathNotFoundException() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #......# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); DijkstraPathFinder dijkstraPathFinder = new DijkstraPathFinder(map); ICell source = map.GetCell(0, 1); ICell destination = map.GetCell(1, 1); dijkstraPathFinder.ShortestPath(source, destination); }
public void ShortestPath_DestinationIsNull_ThrowsArgumentNullException() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #......# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); PathFinder pathFinder = new PathFinder(map); ICell source = map.GetCell(1, 4); ICell destination = null; Path shortestPath = pathFinder.ShortestPath(source, destination); }
public void TryFindShortestPath_SourceIsNull_ThrowsArgumentNullException() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #......# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); DijkstraPathFinder dijkstraPathFinder = new DijkstraPathFinder(map); ICell source = null; ICell destination = map.GetCell(5, 4); Path shortestPath = dijkstraPathFinder.TryFindShortestPath(source, destination); }
public void FindPath_SourceCellNotWalkable_ThrowsPathNotFoundException() { 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.FindPath(0, 1); }
public void FindPath_DestinationNotWalkableAnd13StepsAway_ThrowsPathNotFoundException() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #......# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); GoalMap goalMap = new GoalMap(map); goalMap.AddGoal(7, 1, 0); goalMap.FindPath(1, 1); }
public void ShortestPath_DestinationUnreachable_ThrowsPathNotFoundException() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #....#.# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); PathFinder pathFinder = new PathFinder(map); ICell source = map.GetCell(1, 1); ICell destination = map.GetCell(6, 1); pathFinder.ShortestPath(source, destination); }
public void TryFindShortestPath_DestinationUnreachable_ReturnsNull() { string mapRepresentation = @"######## #....#.# #.#..#.# #.#..#.# #....#.# ########"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); PathFinder pathFinder = new PathFinder(map); ICell source = map.GetCell(1, 1); ICell destination = map.GetCell(6, 1); Path shortestPath = pathFinder.TryFindShortestPath(source, destination); Assert.AreEqual(null, shortestPath); }
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_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 GetCellsAlongLine_ToDestinationOutsideMap_TrimsLineAtMapEdgeAndReturnsExpectedCells() { string mapRepresentation = @"#### #..# #so# ####"; IMapCreationStrategy <Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy <Map>(mapRepresentation); IMap map = Map.Create(mapCreationStrategy); string expectedPath = "#.o#"; StringBuilder actualPath = new StringBuilder(); foreach (ICell cell in map.GetCellsAlongLine(0, 0, 10, 10)) { actualPath.Append(cell.ToString()); } Assert.AreEqual(expectedPath, actualPath.ToString()); }
public void FindPath_SmallMapAfterAddingAndClearingGoals_ThrowsPathNotFoundException() { 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(); goalMap.FindPath(3, 4); }
//[TestMethod] public void ComputeFovTest() { string mapRepresentation = @"#################################### #..................................# #..###.########....................# #....#.#......#....................# #....#.#......#....................# #.............#....................# #....#.#......###################### #....#.#...........................# #....#.#...........................# #..................................# ####################################"; IMapCreationStrategy<LibtcodMap> mapCreationStrategy1 = new StringDeserializeMapCreationStrategy<LibtcodMap>( mapRepresentation ); IMap libtcodMap = LibtcodMap.Create( mapCreationStrategy1 ); double libtcodTime; libtcodTime = StopwatchHelper.AverageTime( () => libtcodMap.ComputeFov( 6, 1, 20, true ), 100 ); long libtcodElapsed; libtcodElapsed = StopwatchHelper.ElapsedTime( () => libtcodMap.ComputeFov( 6, 1, 20, true ), 100 ); Debug.WriteLine( string.Format( "Libtcod Average: {0} Elapsed: {1}", libtcodTime, libtcodElapsed ) ); IMapCreationStrategy<Map> mapCreationStrategy2 = new StringDeserializeMapCreationStrategy<Map>( mapRepresentation ); IMap map = Map.Create( mapCreationStrategy2 ); double rogueSharpTime; rogueSharpTime = StopwatchHelper.AverageTime( () => map.ComputeFov( 6, 1, 20, true ), 100 ); double rogueSharpElapsed; rogueSharpElapsed = StopwatchHelper.ElapsedTime( () => map.ComputeFov( 6, 1, 20, true ), 100 ); Debug.WriteLine( string.Format( "RogueSharp Average: {0} Elapsed: {1}", rogueSharpTime, rogueSharpElapsed ) ); Assert.IsTrue( rogueSharpElapsed <= libtcodElapsed, string.Format( "Elapsed R#: {0} Lib: {1}", rogueSharpElapsed, libtcodElapsed ) ); Assert.IsTrue( rogueSharpTime <= libtcodTime, string.Format( "Average R#: {0} Lib: {1}", rogueSharpTime, libtcodTime ) ); }
public void GetCellsAlongLine_TopRightToBottomLeft_ExpectedCells() { string mapRepresentation = @"#### #..# #so# ####"; IMapCreationStrategy<LibtcodMap> mapCreationStrategy = new StringDeserializeMapCreationStrategy<LibtcodMap>( mapRepresentation ); IMap map = LibtcodMap.Create( mapCreationStrategy ); string expectedPath = "#.s#"; StringBuilder actualPath = new StringBuilder(); foreach ( Cell cell in map.GetCellsAlongLine( 3, 0, 0, 3 ) ) { actualPath.Append( cell.ToString() ); } Assert.AreEqual( expectedPath, actualPath.ToString() ); }
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 FindPath_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 ) }; List<Point> path = goalMap.FindPath( 3, 4, obstacles ); Assert.AreEqual( 6, path.Count ); Assert.AreEqual( new Point( 2, 4 ), path[1] ); }
public void Create_StringDeserializeMapCreationStrategy_ExpectedMap() { string expectedMapRepresentation = @"#### #..# #so# ####"; IMapCreationStrategy<LibtcodMap> mapCreationStrategy = new StringDeserializeMapCreationStrategy<LibtcodMap>( expectedMapRepresentation ); IMap actualMap = LibtcodMap.Create( mapCreationStrategy ); Assert.AreEqual( expectedMapRepresentation.Replace( " ", string.Empty ), actualMap.ToString() ); }
public void FindPath_BigMapFromGame_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 ); 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......"; List<Point> path = goalMap.FindPath( 23, 7, new List<Point>() ); var actualPath = new StringBuilder(); foreach( Point p in path ) { actualPath.Append( map.GetCell( p.X, p.Y ).ToString() ); } Assert.AreEqual( expectedPath, actualPath.ToString() ); }
public void Restore_AfterComputingFovAndSaving_ExpectedMapWithFov() { string mapRepresentation = @"#################################### #..................................# #..###.########....................# #....#.#......#....................# #....#.#......#....................# #.............#....................# #....#.#......###################### #....#.#...........................# #....#.#...........................# #..................................# ####################################"; IMapCreationStrategy<Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy<Map>( mapRepresentation ); IMap map = Map.Create( mapCreationStrategy ); map.ComputeFov( 6, 1, 20, true ); map.AppendFov( 15, 1, 5, true ); MapState mapState = map.Save(); IMap newMap = new Map(); newMap.Restore( mapState ); string expectedFovMap = @"###########################%%%%%%%%% #..........................%%%%%%%%% #..###.########...........%%%%%%%%%% #%%%%#.#%%%%%%#....%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%#...%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%#..%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%####%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%#.#%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%.%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%###%%%%%%%%%%%%%%%%%%%%%%%%%%%%"; Assert.AreEqual( expectedFovMap.Replace( " ", string.Empty ), newMap.ToString( true ) ); }
public void GetCellsAlongLine_ThirdRowLeftToRight_ExpectedCells() { string mapRepresentation = @"#### #..# #so# ####"; IMapCreationStrategy<Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy<Map>( mapRepresentation ); IMap map = Map.Create( mapCreationStrategy ); string expectedPath = "#so#"; StringBuilder actualPath = new StringBuilder(); foreach ( Cell cell in map.GetCellsAlongLine( 0, 2, 3, 2 ) ) { actualPath.Append( cell.ToString() ); } Assert.AreEqual( expectedPath, actualPath.ToString() ); }
public void GetCellsInRadius_SmallMap_ExpectedCells() { string mapRepresentation = @"################# ################# ##...#######...## ##.............## ###.###....#...## ###...##.#####.## ###...##...###..# ####............# ##############..# #################"; IMapCreationStrategy<Map> mapCreationStrategy = new StringDeserializeMapCreationStrategy<Map>( mapRepresentation ); IMap map = Map.Create( mapCreationStrategy ); string expectedCells = "#..##......#."; IEnumerable<Cell> cells = map.GetCellsInRadius( 3, 3, 2 ) .OrderBy( c => c.X ) .ThenBy( c => c.Y ); var actualCells = new StringBuilder(); foreach( Cell cell in cells ) { actualCells.Append( cell.ToString() ); } Assert.AreEqual( expectedCells, actualCells.ToString() ); }
public void Copy_SmallSourceMapIntoSpecificPostionOfDestinationMap_ExpectedDestinationMap() { string sourceMapRepresentation = @".."; IMapCreationStrategy<LibtcodMap> sourceMapCreationStrategy = new StringDeserializeMapCreationStrategy<LibtcodMap>( sourceMapRepresentation ); IMap sourceMap = LibtcodMap.Create( sourceMapCreationStrategy ); string destinationMapRepresentation = @"#### #..# #so# ####"; IMapCreationStrategy<LibtcodMap> destinationMapCreationStrategy = new StringDeserializeMapCreationStrategy<LibtcodMap>( destinationMapRepresentation ); IMap destinationMap = LibtcodMap.Create( destinationMapCreationStrategy ); string expectedRepresentationAfterCopy = @"#### #..# #..# ####"; destinationMap.Copy( sourceMap, 1, 2 ); Assert.AreEqual( expectedRepresentationAfterCopy.Replace( " ", string.Empty ), destinationMap.ToString() ); }