Esempio n. 1
0
        /// <summary>Creates a populated <see cref="Collection{T}"/> of <see cref="Landmark"/>
        /// instances.</summary>
        /// <param name="board">The board on which the collection of landmarks is to be instantiated.</param>
        /// <param name="landmarkCoords">Board coordinates of the desired landmarks</param>
        public static ILandmarkCollection New(
            INavigableBoard board,
            IFastList <HexCoords> landmarkCoords
            )
        {
            int degreeOfParallelism = Math.Max(1, Environment.ProcessorCount - 1);
            var query = from coords in landmarkCoords.AsParallel()
                        .WithDegreeOfParallelism(degreeOfParallelism)
                        .WithMergeOptions(ParallelMergeOptions.NotBuffered)
#if UseSortedDictionary
                        select Landmark.DictionaryPriorityQueueLandmark(coords, board);
#else
                        select Landmark.HotPriorityQueueLandmark(coords, board);
#endif

            return(Extensions.InitializeDisposable(() => new LandmarkCollection(query)));
        }
        BidirectionalPathfinder(IHex start, IHex goal,
                                LandmarkCollection landmarks, HashSet <HexCoords> closed, Func <int> getBestSoFar
                                )
        {
            _start        = start;
            _goal         = goal;
            _getBestSoFar = getBestSoFar;
            _vectorGoal   = goal.Coords.Canon - start.Coords.Canon;
            _open         = new Dictionary <HexCoords, DirectedPath>();
            _closed       = closed;
            _queue        = new HotPriorityQueue <DirectedPath>(16);
            _landmark     = landmarks
                            .OrderByDescending(l => l.HexDistance(goal.Coords) - l.HexDistance(start.Coords))
                            .FirstOrDefault();
            _heuristic = c => _landmark.HexDistance(c) - _landmark.HexDistance(start.Coords);

            var path = new DirectedPath(goal);

            _open.Add(goal.Coords, path);
            _queue.Enqueue(0, path);
        }