Example #1
0
 public void AddAlchemistToQueue(AlchemistType alchemist)
 {
     SemAlchemists.Wait();
     Alchemists[alchemist]++;
     if (Alchemists[alchemist]++ == 0)
     {
         semNewAlchemist.Release();
     }
     SemAlchemists.Release();
 }
Example #2
0
        private void SatisfyAlchemist(AlchemistType alchemist)
        {
            foreach (var resource in Alchemist.NeededResources[alchemist])
            {
                store.Resources[resource]--;
                store.SemCapacity[resource].Release();
            }

            queue.SemAlchemistsQueue[alchemist].Release();
            queue.Alchemists[alchemist]--;
        }
Example #3
0
 private void TrySatisfyAlchemists(AlchemistType alchemist)
 {
     while (queue.Alchemists[alchemist] > 0)
     {
         if (CanSatisfyAlchemist(alchemist))
         {
             SatisfyAlchemist(alchemist);
         }
         else
         {
             break;
         }
     }
 }
Example #4
0
        private bool CanSatisfyAlchemist(AlchemistType alchemist)
        {
            var neededResources = Alchemist.NeededResources[alchemist];

            return(neededResources.All(resource => store.Resources[resource] > 0));
        }
Example #5
0
 public AlchemistTypeData(AlchemistType type, GlobalState globalState, params Resource[] resourcesRequired)
 {
     ResourcesRequired = resourcesRequired;
     Type        = type;
     GlobalState = globalState;
 }
Example #6
0
 public Alchemist(AlchemistType type, IAlchemistsQueue queue)
 {
     Type       = type;
     this.queue = queue;
 }
Example #7
0
 public Alchemist(int id, AlchemistType type)
 {
     Id   = id;
     Type = type;
     PrintAlchemistMessage("comes for resources.");
 }
Example #8
0
 public void WaitForResources(AlchemistType alchemist)
 {
     SemAlchemistsQueue[alchemist].Wait();
 }