private NodePath RunAstar(DefinitionNodeGrid definitionNodeGrid, Point2 gridStart, Point2 gridEnd, out bool succes)
        {
            var aStarAlgorithm = new AStarAlgorithm(definitionNodeGrid.NodeCount, new EuclideanDistance());

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

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

            return(aStarAlgorithm.FindPath(pathfindingNetwork, pathRequest, out succes));
        }
Example #2
0
        public void FindPath_InitializedNodegrid_PathLengthIsNot0(DefinitionNodeGrid definitionNodeGrid, int x1, int y1, int x2, int y2)
        {
            var aStarAlgorithm = new AStarAlgorithm();

            var start = definitionNodeGrid.NodeGrid[x1, y1];
            var end   = definitionNodeGrid.NodeGrid[x1, y1];

            var pathfindingNetwork = new AstarNodeNetwork(definitionNodeGrid, new GridClearanceGenerator(definitionNodeGrid, 5));
            var pathRequest        = new PathRequest <IPath>(start, end);
            var path = aStarAlgorithm.FindPath(pathfindingNetwork, pathRequest, out var _);

            Assert.AreEqual(path.Path.Length > 0, true);
        }
Example #3
0
        public void Setup()
        {
            var factory  = new DefinitionNodeGridFactory();
            var nodeGrid = factory.GeneratePreFilledArray(GenerateNodeGridConnections.All, 320, 200);

            _definitionNodeGrid    = new DefinitionNodeGrid(nodeGrid, new Vector2(1, 1));
            _astarNodeNetwork      = new AstarNodeNetwork(_definitionNodeGrid, new BrushfireClearanceGenerator(_definitionNodeGrid, 1));
            _algorithm             = new AStarAlgorithm(_definitionNodeGrid.NodeCount, new ManhattanDistance());
            _longPathRequest       = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(319, 199));
            _shortPathRequest      = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(20, 20));
            _veryShortPathRequest  = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(1, 0));
            _zeroLengthPathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(0, 0));
        }
Example #4
0
        public static IPathfinder <IDefinitionNodeNetwork, IPathfindNodeNetwork <AstarNode>, WaypointPath> CreateAstarPathfinder(this IPathfindaxManager pathfindaxManager, IDefinitionNodeNetwork nodeNetwork, IDistanceHeuristic _heuristic, int maxClearance = -1, int amountOfThreads = 1)
        {
            var pathfinder = pathfindaxManager.CreatePathfinder(nodeNetwork, new AStarAlgorithm(nodeNetwork.NodeCount, _heuristic), (definitionNodeNetwork, algorithm, cache) =>
            {
                var nodeGenerators = new List <IPathfindNodeGenerator <AstarNode> >();
                if (definitionNodeNetwork is IDefinitionNodeGrid sourceNodeGrid)
                {
                    nodeGenerators.Add(new BrushfireClearanceGenerator(sourceNodeGrid, maxClearance));
                }
                var astarNodeNetwork = new AstarNodeNetwork(definitionNodeNetwork, nodeGenerators.ToArray());
                return(CreateRequestProcesser(astarNodeNetwork, algorithm, cache));
            }, null, amountOfThreads);

            pathfinder.Start();
            return(pathfinder);
        }
Example #5
0
        public void CalculateGridNodeClearances_FilledNodeGrid_Passes()
        {
            const int width            = 4;
            const int height           = 4;
            var       sourceNodeGrid   = new DefinitionNodeGrid(GenerateNodeGridConnections.All, width, height, new Vector2(1, 1));
            var       astarNodeNetwork = new AstarNodeNetwork(sourceNodeGrid, new GridClearanceGenerator(sourceNodeGrid, 5));

            var sourceNodeNetworkCat1 = new Array2D <AstarNode>(astarNodeNetwork.GetCollisionLayerNetwork(PathfindaxCollisionCategory.Cat1), width, height);

            Assert.AreEqual(4, sourceNodeNetworkCat1[0, 0].Clearance);
            Assert.AreEqual(3, sourceNodeNetworkCat1[1, 0].Clearance);
            Assert.AreEqual(2, sourceNodeNetworkCat1[2, 0].Clearance);
            Assert.AreEqual(1, sourceNodeNetworkCat1[3, 0].Clearance);

            Assert.AreEqual(3, sourceNodeNetworkCat1[0, 1].Clearance);
            Assert.AreEqual(3, sourceNodeNetworkCat1[1, 1].Clearance);
            Assert.AreEqual(2, sourceNodeNetworkCat1[2, 1].Clearance);
            Assert.AreEqual(1, sourceNodeNetworkCat1[3, 1].Clearance);
        }