Exemple #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");
        }
Exemple #2
0
        public void RectNodesFromEmptyUnevenGridLatticeTest()
        {
            List <RectifyRectangle> result = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(10, 20));

            Assert.AreEqual(1, result.Count, "Didn't get the single Rectangle as expected");

            List <RectifyRectangle> result2 = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(15, 10));

            Assert.AreEqual(1, result2.Count, "Didn't get the single Rectangle as expected");
        }
Exemple #3
0
        public void TestPathTranslate()
        {
            var result = Rectify.MakeRectangles(GridLatticeTestData.CornersLattice());

            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

            var resultPath = pathfinder.CalculatePath(new Position(3, 6), new Position(6, 4));

            var resultPathAlt = pathfinder.CalculatePath(new Position(6, 4), new Position(3, 6));

            //Due to changes in underlying code, this test is moot.
        }
Exemple #4
0
        public void TestSingleCellObstruction()
        {
            var result     = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(10));
            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

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

            Assert.AreEqual(4, resultPath.Count, "path was not length 4 as expected");
            resultPath = pathfinder.CalculatePath(new Position(3, 4), new Position(1, 4));
            Assert.AreEqual(5, resultPath.Count, "path was not length 5 as expected");
        }
Exemple #5
0
        public void TestNoPathNecessary()
        {
            var result     = Rectify.MakeRectangles(GridLatticeTestData.HorizBisectedLattice());
            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

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

            Assert.AreEqual(0, resultPath.Count, "Did not generate a zero path as expected");

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

            resultPath = pathfinder.CalculatePath(new Position(2, 0), new Position(2, 4));
            Assert.AreNotEqual(0, resultPath.Count, "Did not generate a non-zero path as expected");
        }
Exemple #6
0
        public void TestLatticeCornerPathing()
        {
            var result = Rectify.MakeRectangles(GridLatticeTestData.CornersLattice());

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

            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

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

            Assert.AreEqual(2, resultPath.Count, "Did not find a path of 2 where expected");
            Assert.AreEqual(new Position(0, 0), resultPath[0]);
            Assert.AreEqual(new Position(1, 0), resultPath[1]);
        }
Exemple #7
0
        public void BiggerSequentialEdgeAdditionTest()
        {
            var result     = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(10));
            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

            //add edges to the same cell one after another

            pathfinder.ReplaceCellEdgeAt(new Position(6, 4), Direction.West, EdgeType.Wall);

            pathfinder.ReplaceCellEdgeAt(new Position(6, 4), Direction.South, EdgeType.Wall);

            pathfinder.ReplaceCellEdgeAt(new Position(7, 4), Direction.West, EdgeType.Wall);

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

            Assert.AreNotEqual(0, resultPath.Count, "Did not find expected path");
        }
Exemple #8
0
        public void TestPathAfterNewEdges()
        {
            var result     = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(10, 10));
            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

            for (int i = 0; i < 10; i++)
            {
                pathfinder.ReplaceCellEdgeAt(new Position(7, i), Direction.West, EdgeType.Wall);
            }

            var resultPath = pathfinder.CalculatePath(new Position(0, 6), new Position(9, 5));

            Assert.AreEqual(0, resultPath.Count, "Did not generate a zero path as expected");

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

            resultPath = pathfinder.CalculatePath(new Position(0, 6), new Position(9, 5));
            Assert.AreEqual(0, resultPath.Count, "Did not generate a zero path as expected");
        }
Exemple #9
0
        public void SequentialEdgeAdditionTest()
        {
            var result     = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice());
            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

            //add edges to the same cell one after another

            pathfinder.ReplaceCellEdgeAt(new Position(1, 1), Direction.West, EdgeType.Wall);
            var resultPath = pathfinder.CalculatePath(new Position(0, 1), new Position(1, 1));

            Assert.AreNotEqual(2, resultPath.Count, "Did not path around wall edge as expected");

            pathfinder.ReplaceCellEdgeAt(new Position(1, 1), Direction.South, EdgeType.Wall);
            resultPath = pathfinder.CalculatePath(new Position(0, 1), new Position(1, 1));
            Assert.AreNotEqual(2, resultPath.Count, "Did not path around wall edge as expected");

            pathfinder.ReplaceCellEdgeAt(new Position(1, 1), Direction.East, EdgeType.Wall);
            resultPath = pathfinder.CalculatePath(new Position(0, 0), new Position(2, 0));
            Assert.AreEqual(3, resultPath.Count, "Did not path around wall edge as expected");
        }
Exemple #10
0
        public void RectNodesFromGridLatticeTest()
        {
            //These two cases result in very similar maps, but are distinct b/c of needing / not needing to deal with 1d segments.
            List <RectifyRectangle> result = Rectify.MakeRectangles(GridLatticeTestData.EdgeTorusGridLattice());

            Assert.AreEqual(5, result.Count, "Didn't get the 5 Rectangles expected");
            List <RectifyRectangle> result2 = Rectify.MakeRectangles(GridLatticeTestData.CenterCellTorusGridLattice());

            Assert.AreEqual(5, result2.Count, "Didn't get the 5 Rectangles expected");

            //Due to how the algorithm works, this can result in EITHER 4 or 2 rectangles, due to it favoring horiz. vs. vertical edges, I think?
            //Probably not worth solving to ensure optimal minimization, since we're already not guarenteeing that due to our
            //in-optimal treatment of holes. (And remedy is the same - join edges where entire edges match width / position && edgetype none for all.)
            List <RectifyRectangle> result3 = Rectify.MakeRectangles(GridLatticeTestData.SingleHorizEdgeGridLattice());

            Assert.AreEqual(2, result3.Count, "Didn't get the 2 Rectangles expected");
            List <RectifyRectangle> result4 = Rectify.MakeRectangles(GridLatticeTestData.SingleVertEdgeGridLattice());

            Assert.AreEqual(4, result4.Count, "Didn't get the 4 Rectangles expected");
        }
Exemple #11
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");
        }
Exemple #12
0
        public void LatticeGetBoundsTest()
        {
            var result = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice());

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

            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

            var bounds = pathfinder.GetRectBordersFromPoint(new Position(0, 0));

            Assert.AreEqual(3, bounds.Item2.xPos, "did not get 3 width as expected");


            var altLattice = new GridLattice <IRectGrid>(10);

            GridLatticeTestData.InitGridLattice(altLattice);
            altLattice[0, 0, Direction.East] = new RectGridCell(1, 1);
            result = Rectify.MakeRectangles(altLattice);
            //cell at 0,0; the rest of the row (1,0 -> 10,0), and the rest of the grid (0,1 -> 10,10)
            Assert.AreEqual(3, result.Count, "Did not get 3 rectangles as expected");
            var altfinder = new RectifyPathfinder(result, StandardLatticeParams);
        }