public void AddAlchemistToQueue(AlchemistType alchemist) { SemAlchemists.Wait(); Alchemists[alchemist]++; if (Alchemists[alchemist]++ == 0) { semNewAlchemist.Release(); } SemAlchemists.Release(); }
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]--; }
private void TrySatisfyAlchemists(AlchemistType alchemist) { while (queue.Alchemists[alchemist] > 0) { if (CanSatisfyAlchemist(alchemist)) { SatisfyAlchemist(alchemist); } else { break; } } }
private bool CanSatisfyAlchemist(AlchemistType alchemist) { var neededResources = Alchemist.NeededResources[alchemist]; return(neededResources.All(resource => store.Resources[resource] > 0)); }
public AlchemistTypeData(AlchemistType type, GlobalState globalState, params Resource[] resourcesRequired) { ResourcesRequired = resourcesRequired; Type = type; GlobalState = globalState; }
public Alchemist(AlchemistType type, IAlchemistsQueue queue) { Type = type; this.queue = queue; }
public Alchemist(int id, AlchemistType type) { Id = id; Type = type; PrintAlchemistMessage("comes for resources."); }
public void WaitForResources(AlchemistType alchemist) { SemAlchemistsQueue[alchemist].Wait(); }