Beispiel #1
0
    public T Dequeue()
    {
        var ret = top.Key;

        size--;
        top = PairingHeap <T> .Pop(top, compare);

        return(ret);
    }
Beispiel #2
0
        private void FindPaths()
        {
            var frontier = new PairingHeap <double, Location>(new DoubleComparer())
            {
                { 0, HeroLocation }
            };

            CategorizeObject(ObjectMap[HeroLocation]);

            while (frontier.Count != 0)
            {
                var current = frontier.Pop().Value;
                for (var d = Direction.Up; d <= Direction.RightDown; d++)
                {
                    var next = current.NeighborAt(d);
                    if (IsEnemySpawn(next) ||
                        !ObjectMap.ContainsKey(next))
                    {
                        continue;
                    }
                    var mapObject = ObjectMap[next];
                    CategorizeObject(mapObject);
                    var nextTime = TravelTimes[current] + 0.5 * movementCost[mapObject.Terrain];
                    if (TravelTimes.ContainsKey(next) && !(nextTime < TravelTimes[next]))
                    {
                        continue;
                    }
                    TravelTimes[next] = nextTime;
                    if (IsPassable(mapObject))
                    {
                        frontier.Add(nextTime, next);
                    }
                    previousLocation[next] = current;
                }
            }
        }