Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AStarPathFinder"/> class.
        /// </summary>
        /// <param name="nodeFactory">A reference to the node factory in use.</param>
        /// <param name="map">A refernce to the map isntance.</param>
        /// <param name="pathfinderOptions">The options for this pathfinder.</param>
        public AStarPathFinder(INodeFactory nodeFactory, IMap map, IOptions <AStarPathFinderOptions> pathfinderOptions)
        {
            nodeFactory.ThrowIfNull(nameof(nodeFactory));
            map.ThrowIfNull(nameof(map));
            pathfinderOptions?.Value.ThrowIfNull(nameof(pathfinderOptions));

            this.NodeFactory = nodeFactory;
            this.Map         = map;
            this.Options     = pathfinderOptions.Value;
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AStar"/> class.
        /// </summary>
        /// <param name="nodeFactory">A reference to the node factory in use.</param>
        /// <param name="start">The starting node for the AStar algorithm.</param>
        /// <param name="goal">The goal node for the AStar algorithm.</param>
        /// <param name="maxSearchSteps">Optional. The maximum number of Step operations to perform on the search.</param>
        public AStar(INodeFactory nodeFactory, INode start, INode goal, int maxSearchSteps = 100)
        {
            nodeFactory.ThrowIfNull(nameof(nodeFactory));
            start.ThrowIfNull(nameof(start));
            goal.ThrowIfNull(nameof(goal));

            this.nextToVisit = new SortedList <int, INode>(new DuplicateIntegerComparer());

            this.nodeFactory = nodeFactory;

            this.goal     = goal;
            this.maxSteps = maxSearchSteps;

            this.currentStepCount = 0;

            this.CurrentNode = start;
            this.CurrentNode.ShouldBeVisited = true;

            this.nextToVisit.Add(this.CurrentNode);
        }