Example #1
0
        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, false), stepForward);
        }