示例#1
0
        public void FindPath_InitializedNodegrid_ValuesPotentialFieldAreCorrect()
        {
            var potentialFieldAlgorithm = new PotentialFieldAlgorithm(0);

            var definitionNodeGrid = new DefinitionNodeGrid(GenerateNodeGridConnections.All, 3, 3, new Vector2(1, 1));
            var start = definitionNodeGrid.NodeGrid[0, 0];
            var end   = definitionNodeGrid.NodeGrid[2, 2];

            var         pathfindingNetwork = new DijkstraNodeGrid(definitionNodeGrid);
            var         pathRequest        = new PathRequest <IPath>(start, end);
            var         potentialField     = potentialFieldAlgorithm.FindPath(pathfindingNetwork, pathRequest, out var _);
            const float tolerance          = 0.001f;

            Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[0, 0]) - 4f) < tolerance, true);
            Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[1, 0]) - 3f) < tolerance, true);
            Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[2, 0]) - 2f) < tolerance, true);

            Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[0, 1]) - 3f) < tolerance, true);
            Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[1, 1]) - 2f) < tolerance, true);
            Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[2, 1]) - 1f) < tolerance, true);

            Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[0, 2]) - 2f) < tolerance, true);
            Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[1, 2]) - 1f) < tolerance, true);
            Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[2, 2]) - 0f) < tolerance, true);
        }
        private PotentialField RunPotentialField(DefinitionNodeGrid definitionNodeGrid, Point2 gridStart, Point2 gridEnd, out bool succes)
        {
            var potentialFieldAlgorithm = new PotentialFieldAlgorithm(0, definitionNodeGrid.NodeCount);

            var start = definitionNodeGrid.NodeGrid.ToIndex(gridStart.X, gridStart.Y);
            var end   = definitionNodeGrid.NodeGrid.ToIndex(gridEnd.X, gridEnd.Y);

            var pathfindingNetwork = new DijkstraNodeGrid(definitionNodeGrid, 5);
            var pathRequest        = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), start, end, PathfindaxCollisionCategory.Cat1);

            return(potentialFieldAlgorithm.FindPath(pathfindingNetwork, pathRequest, out succes));
        }