コード例 #1
0
ファイル: GoalMapTest.cs プロジェクト: weedkiller/RogueSharp
        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);
        }
コード例 #2
0
ファイル: GoalMapTest.cs プロジェクト: weedkiller/RogueSharp
        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());
        }
コード例 #3
0
ファイル: GoalMapTest.cs プロジェクト: weedkiller/RogueSharp
        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);
        }
コード例 #4
0
ファイル: GoalMapTest.cs プロジェクト: weedkiller/RogueSharp
        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);
        }
コード例 #5
0
ファイル: GoalMapTest.cs プロジェクト: weedkiller/RogueSharp
        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);
        }