public Region() { Negbours = new List <Region>(); internalMarket = new InternalMarket(); externalMarket = new ExternalMarket(this, Negbours); Populations = new List <Population>(); }
public Region Init(int population) { InternalMarket = new InternalMarket(); InternalMarket.Init(); ExternalMarket = new ExternalMarket(this); ExternalMarket.Init(); Populations = new List <Population>(); Random rnd = new Random(); if (population <= 0) { population = 100; } //1.8 + rnd.NextDouble() * 0.4 if (population > 1000000000) { Populations.Add(new Farmer(population / 2, ResourceTypes.ResourceType.Fruit, 10).Init()); } else { Populations.Add(new Farmer(population / 2, ResourceTypes.ResourceType.Fruit, 1.8 + rnd.NextDouble() * 0.4).Init()); } Populations.Add(new Farmer(population / 2, ResourceTypes.ResourceType.Cloth, 1.8 + rnd.NextDouble() * 0.4).Init()); return(this); }
public void Update() { InternalMarket.UpdateMarket(Populations); InternalMarket.ComputeNewStock(ExternalMarket); InternalMarket.DoTrade(Populations); UpdatePopulation(); CleanUp(); }
public Region(bool fruits) { Negbours = new List <Region>(); internalMarket = new InternalMarket(); externalMarket = new ExternalMarket(this, Negbours); Populations = new List <Population>(); if (fruits) { Populations.Add(new Farmer(10000, ResourceTypes.GetResourceType("Fruit"))); } else { Populations.Add(new Farmer(10000, ResourceTypes.GetResourceType("Cloth"))); } }
public void UpdateDemand(InternalMarket market, Population population) { resetDemand(); var lifePriceRatioMap = new Dictionary <ResourceTypes.ResourceType, double>(); foreach (ResourceTypes.ResourceType resourceType in ResourceTypes.GetIterator()) { if (GetAmountNeeded(resourceType) == 0) { continue; } lifePriceRatioMap[resourceType] = Convert.ToDouble(LifeValues[(int)resourceType]) / market.GetPrice(resourceType); } ComputeWhatToBuy(market, population, lifePriceRatioMap); market.AddDemand(ResourceDemand); }
private void ComputeWhatToBuy(InternalMarket market, Population population, Dictionary <ResourceType, double> lifePriceRatioMap) { double money = population.money; IEnumerable <KeyValuePair <ResourceType, double> > orderedLifePriceRatio = lifePriceRatioMap.OrderByDescending(ratio => ratio.Value); foreach (KeyValuePair <ResourceType, double> resoucreTypeRatio in orderedLifePriceRatio) { ResourceType resourceType = resoucreTypeRatio.Key; double price = market.GetPrice(resourceType); double buyAmount = Math.Min(money / price, population.GetPopLevel() * GetAmountNeeded(resourceType)); ResourceDemand.SetResource(new Resource(resourceType, buyAmount)); money -= buyAmount * price; if (money <= 0) { break; } } }
private void ComputeWhatToBuy(InternalMarket market, Population population, Dictionary <ResourceTypes.ResourceType, double> lifePriceRatioMap) { double money = population.Money; IEnumerable <KeyValuePair <ResourceTypes.ResourceType, double> > orderedLifePriceRatio = lifePriceRatioMap.OrderByDescending(ratio => ratio.Value); foreach (KeyValuePair <ResourceTypes.ResourceType, double> resoucreTypeRatio in orderedLifePriceRatio) { ResourceTypes.ResourceType resourceType = resoucreTypeRatio.Key; double price = market.GetPrice(resourceType); double buyAmount = Math.Round(Math.Min(money / price, population.GetIntegerPopLevel() * GetAmountNeeded(resourceType)), 3, MidpointRounding.ToZero); if (buyAmount < minemumDemand) { continue; } ResourceDemand[(int)resourceType].Amount = buyAmount; money -= buyAmount * price; if (money <= 0) { break; } } }
public double GetSallery(InternalMarket market) { return(GetEfficensy() * market.GetPrice(ProducingType)); }
public void UpdateDemand(InternalMarket market) { demand.UpdateDemand(market, this); }
public void CleanUp() { ExternalMarket.FinilizeTrades(); InternalMarket.CleanUp(); }
public double GetResorceCost(ResourceTypes.ResourceType resource) { return(InternalMarket.GetPrice(resource)); }