예제 #1
0
        public void TestBlockPaths()
        {
            var result = Rectify.MakeRectangles(TestData.KeyholeTest(), DataLayout.CodeInitializedArray);

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

            var pathfinder = new RectifyPathfinder(result, StandardParams);

            pathfinder.ReplaceCellAt(new Position(2, 2), 2);

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

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

            Assert.AreEqual(0, resultPath.Count, "found a path when none expected");

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

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

            resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(1, 2));
            Assert.AreEqual(2, resultPath.Count, "Did not find a path where expected");
        }
예제 #2
0
        //[TestMethod]
        //[TestCategory("Pathfinder")]
        public void CachePathTest()
        {
            //The caching was removed, so this test will fail. The prior method of caching worked _pretty_ well, but needs some refinements.
            //could run into an issue where navigating to two adjacent cells cut the corner due to the caching optimistically assuming the diagonal could
            //be taken when it could not. (See TestSingleCellObstruction)

            //I suspect there's a better way to handle caching. Perhaps some way based on the distance from the rectangle traversal edges?


            List <RectDetectPair> edges = new List <RectDetectPair>
            {
                new RectDetectPair(0, 3, EdgeType.Aperture)
            };

            var result = Rectify.MakeRectangles(TestData.UnityModifiedDesertTitans(), DataLayout.CodeInitializedArray, edgeOverrides: edges);

            var pathfinder = new RectifyPathfinder(result, StandardParams);

            var resultPath = pathfinder.CalculatePath(new Position(109, 147), new Position(150, 75), out PathfinderMetrics metrics, (int)EdgeType.None | (int)EdgeType.Aperture);

            Assert.AreEqual(44, resultPath.Count, "fail to find a path as expected");

            //same overall path, this should hit the cache.
            resultPath = pathfinder.CalculatePath(new Position(109, 145), new Position(150, 75), out PathfinderMetrics metricsAfterCache, (int)EdgeType.None | (int)EdgeType.Aperture);

            Assert.AreNotEqual(0, metrics.VisitedNodes, "pathfound w/o traversing nodes somehow");
            Assert.AreEqual(0, metricsAfterCache.VisitedNodes, "pathfound w/o using the cache as intended");
        }
예제 #3
0
        public void MakeRimworldSaveTest()
        {
            //break this down into pieces.
            List <RectifyRectangle> result = null;

            //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(0, 0), new Position(50, 50)); //completes w/o error
            //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(50, 0), new Position(100, 50)); //completes w/o error
            //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(100, 0), new Position(275, 50)); //completes w/o error
            //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(100, 50), new Position(150, 100)); //completes w/o error
            //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(200, 50), new Position(275, 150)); //completes w/o error
            //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(0, 150), new Position(50, 274)); //completes w/o error //for whatever reason, only 274 height. Missed a row originally, I guess?
            //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(150, 150), new Position(250, 200)); //completes w/o error
            //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(0, 25), new Position(100, 200)); //completes w/o error
            //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(100, 0), new Position(275, 200)); //completes w/o error

            //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(15, 0), new Position(275, 274));

            result = Rectify.MakeRectangles(TestData.DesertTitans(), DataLayout.CodeInitializedArray);
            Assert.AreEqual(724, result.Count, "Expect 724 rectangles, probably");

            //let's make sure that no rectangle overlaps. That would be super sad :(
            for (int i = 0; i < result.Count; i++)
            {
                var rr = result[i];
                for (int j = i + 1; j < result.Count; j++)
                {
                    var rr_other = result[j];

                    Assert.IsFalse(
                        rr.Left <rr_other.Right && rr.Right> rr_other.Left &&
                        rr.Top > rr_other.Bottom && rr.Bottom < rr_other.Top, "Intersecting rectangles :(");
                }
            }
        }
예제 #4
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");
        }
예제 #5
0
        public void StardewFarmPathingTest()
        {
            //var result = Rectify.MakeRectangles(TestData.StardewTestData(), new Position(0, 0), new Position(55, 39));
            //var result = Rectify.MakeRectangles(TestData.StardewTestData(), new Position(0, 0), new Position(50, 25));
            var result = Rectify.MakeRectangles(TestData.StardewTestData());

            Assert.AreEqual(195, result.Count);
        }
예제 #6
0
        public void NeighborsInitialTest()
        {
            var result = Rectify.MakeRectangles(TestData.OneDRectangleTest(), DataLayout.CodeInitializedArray);

            Assert.AreEqual(3, result[0].NeighborCount, "0,0::3,2 has 3 neighbors (2 east, 1 south)");
            Assert.AreEqual(3, result[1].NeighborCount, "0,2::8,8 has 3 neighbors (3 north)");
            Assert.AreEqual(3, result[2].NeighborCount, "4,0::8,2 has 3 neighbors (2 west, 1 south)");
            Assert.AreEqual(3, result[3].NeighborCount, "3,0::4,1 has 3 neighbors (1 east, 1 west, 1 south)");
            Assert.AreEqual(4, result[4].NeighborCount, "3,1::4,2 has 4 neighbors (1 east, 1 west, 1 south, 1 north)");
        }
예제 #7
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");
        }
예제 #8
0
        public void MultiEdgePathfinderTest()
        {
            var result = Rectify.MakeRectangles(TestData.OneDRectangleTest(), DataLayout.CodeInitializedArray);

            var pathfinder = new RectifyPathfinder(result, StandardParams);

            var resultPath = pathfinder.CalculatePath(new Position(0, 6), new Position(7, 6), (int)EdgeType.None + (int)EdgeType.Wall);

            Assert.AreEqual(5, resultPath.Count, "Didn't find straight-line path as expected");
        }
예제 #9
0
        public void NoPathPathfinderTest()
        {
            var result = Rectify.MakeRectangles(TestData.OneDRectangleTest(), DataLayout.CodeInitializedArray);

            var pathfinder = new RectifyPathfinder(result, StandardParams);

            var resultPath = pathfinder.CalculatePath(new Position(0, 1), new Position(3, 6), (int)EdgeType.None);

            Assert.AreEqual(0, resultPath.Count, "Didn't fail to find a path as expected");
        }
예제 #10
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.
        }
예제 #11
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");
        }
예제 #12
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]);
        }
예제 #13
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");
        }
예제 #14
0
        public void LPathTest()
        {
            List <RectDetectPair> edges = new List <RectDetectPair>
            {
                new RectDetectPair(0, 3, EdgeType.Aperture)
            };

            var result = Rectify.MakeRectangles(TestData.LPathTest(), DataLayout.CodeInitializedArray, edgeOverrides: edges);

            var pathfinder = new RectifyPathfinder(result, StandardParams);

            var resultPath = pathfinder.CalculatePath(new Position(1, 6), new Position(7, 0), (int)EdgeType.None | (int)EdgeType.Aperture);

            Assert.AreNotEqual(13, resultPath.Count, "failed to find a path as expected");
        }
예제 #15
0
        public void TestAddToRectangles()
        {
            var result = Rectify.MakeRectangles(TestData.UniformRectangle(), DataLayout.CodeInitializedArray);

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

            var pathfinder = new RectifyPathfinder(result, StandardParams);

            pathfinder.ReplaceCellAt(new Position(2, 2), 4);

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

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

            Assert.AreEqual(0, resultPath.Count, "found a path when none expected");
        }
예제 #16
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");
        }
예제 #17
0
        public void TestCacheInvalidated()
        {
            var result     = Rectify.MakeRectangles(TestData.BigKeyholeTest(), DataLayout.CodeInitializedArray);
            var pathfinder = new RectifyPathfinder(result, StandardParams);

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

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

            pathfinder.ReplaceCellAt(new Position(2, 4), 2);

            //either the caching algorithm isn't really working in the first place, or the checks we're already doing
            //wind up failling with the new rectangles.

            //This test is moot.
            resultPath = pathfinder.CalculatePath(new Position(0, 0), new Position(0, 5));
            Assert.AreEqual(0, resultPath.Count, "Found previous path, cache not invalidated");
        }
예제 #18
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");
        }
예제 #19
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");
        }
예제 #20
0
        public void TestAddToTorus()
        {
            var result = Rectify.MakeRectangles(TestData.BigTorusTest(), DataLayout.CodeInitializedArray);

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

            var pathfinder = new RectifyPathfinder(result, StandardParams);

            pathfinder.ReplaceCellAt(new Position(3, 3), 4);

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

            //These succeed because a wall already exists between the two regions.
            var resultPath = pathfinder.CalculatePath(new Position(3, 3), new Position(2, 2));

            Assert.AreEqual(0, resultPath.Count, "found a path when none expected");

            resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(3, 3));
            Assert.AreEqual(0, resultPath.Count, "found a path when none expected");
        }
예제 #21
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");
        }
예제 #22
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);
        }
예제 #23
0
        public void MakeRectanglesTest()
        {
            var result = Rectify.MakeRectangles(TestData.BinaryConcaveShapeNoHoles(), DataLayout.CodeInitializedArray);

            Assert.AreEqual(17, result.Count, "did not make 17 total rectangles as expected");
        }
예제 #24
0
        public void BaseEdgeTest()
        {
            var result = Rectify.MakeRectangles(TestData.BaseEdge(), DataLayout.CodeInitializedArray);

            Assert.AreEqual(36, result.Count, "did not make 36 total rectangles as expected");
        }
예제 #25
0
        public void VertexConcavityTest()
        {
            var result = Rectify.MakeRectangles(TestData.VertexConcavity(), DataLayout.CodeInitializedArray);

            Assert.AreEqual(10, result.Count, "did not make 10 total rectangles as expected");
        }
예제 #26
0
        public void TorusTest()
        {
            var result = Rectify.MakeRectangles(TestData.TorusTest(), DataLayout.CodeInitializedArray);

            Assert.AreEqual(9, result.Count, "did not make 9 total rectangles as expected");
        }
예제 #27
0
        public void MeteorWallTest()
        {
            var result = Rectify.MakeRectangles(TestData.MeteorWall(), DataLayout.CodeInitializedArray);

            Assert.AreEqual(21, result.Count, "did not make 21 total rectangles as expected");
        }