Exemplo n.º 1
0
        public void AddCreature(RatedCreature <Creature> newCreature)
        {
            if (IsBetterThanBest(newCreature))
            {
                HandleNewBest(newCreature);
            }

            if (heap.IsFull)
            {
                if (newCreature.CompareTo(heap.PeekMin()) > 0) //if newCreature is better than the worst of creatures in heap
                {
                    Creature theWorst = heap.ExtractMin().TheCreature;
                    TrySaveDisposedCreature(theWorst);

                    heap.Insert(newCreature);
                }
                else
                {
                    TrySaveDisposedCreature(newCreature.TheCreature);
                }
            }
            else
            {
                heap.Insert(newCreature);
            }
        }
Exemplo n.º 2
0
 private bool IsBetterThanBest(RatedCreature <Creature> creature)
 => bestCreature.CompareTo(creature) < 0;