Esempio n. 1
0
        public void TestBlockPathsLattice()
        {
            var result = Rectify.MakeRectangles(GridLatticeTestData.KeyholeApertureLattice());

            Assert.AreEqual(2, result.Count, "Did not get 2 initial rectangles as expected");

            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

            var resultPath = pathfinder.CalculatePath(new Position(2, 3), new Position(2, 1));

            Assert.AreEqual(3, resultPath.Count, "Did not find a path where expected");

            pathfinder.ReplaceCellEdgeAt(new Position(2, 2), Direction.North, EdgeType.Wall);

            Assert.AreEqual(5, pathfinder.NodeCount, "Did not get the 5 total rectangles expected");


            resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(2, 3));
            Assert.AreEqual(0, resultPath.Count, "did not find a path when expected");

            resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(2, 1));
            Assert.AreEqual(2, resultPath.Count, "found a path when none expected");


            resultPath = pathfinder.CalculatePath(new Position(1, 2), new Position(2, 2));
            Assert.AreEqual(2, resultPath.Count, "Did not find a path where expected");
        }
Esempio n. 2
0
        public void TestAStarBlockPathsLattice()
        {
            var result = GridLatticeTestData.KeyholeApertureLattice();

            var pathfinder = new RectifyAStarPathfinder(result);

            var resultPath = pathfinder.CalculatePath(new Position(2, 3), new Position(2, 0));

            Assert.AreEqual(4, resultPath.Count, "Did not find a path where expected");

            result[2, 2, Direction.North] = new RectGridCell(8, 1);
            pathfinder = new RectifyAStarPathfinder(result);

            resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(2, 3));
            Assert.AreEqual(0, resultPath.Count, "did not find a path when expected");

            resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(2, 1));
            Assert.AreEqual(2, resultPath.Count, "found a path when none expected");

            resultPath = pathfinder.CalculatePath(new Position(1, 2), new Position(2, 2));
            Assert.AreEqual(2, resultPath.Count, "Did not find a path where expected");
        }