Ejemplo n.º 1
0
 public void UpdatedPrices()
 {
     foreach (ResourceTypes.ResourceType resourceType in ResourceTypes.GetIterator())
     {
         GetSupplyToDemandRatio(resourceType).ResourcesPrice = GetNewPrice(resourceType);
     }
 }
Ejemplo n.º 2
0
        public void DoTrade(List <Population> populations)
        {
            foreach (ResourceTypes.ResourceType resourceType in ResourceTypes.GetIterator())
            {
                var demmand = Demand.GetAmount(resourceType);
                if (demmand == 0 || SupplySum[(int)resourceType].Amount == 0)
                {
                    return;
                }

                var    resoucreData  = GetSupplyToDemandRatio(resourceType);
                var    resourceRatio = resoucreData.GetSupplyToDemandRatio();
                double price         = resoucreData.ResourcesPrice;

                var supply = GetSupply(resourceType);

                var exportSupply = GetExternalSupply(resourceType);

                double sellRatio = Math.Min(1, 1 / GetSupplyToDemandRatio(resourceType).ComputeSupplyToDemandRatio(demmand, SupplySum[(int)resourceType].Amount));
                demmand = AutoTrade(resourceType);
                double newBuyRatio = Math.Min(1, GetSupplyToDemandRatio(resourceType).ComputeSupplyToDemandRatio(demmand, SupplySum[(int)resourceType].Amount));

                foreach (Population pop in populations)
                {
                    pop.BuyAmount(newBuyRatio, price, resourceType);
                }

                supply.TradingResourceList.ForEach(tr => tr.Trade(sellRatio, price));
                supply.TradingResourceList.RemoveAll(su => su.Empty());

                exportSupply.TradingResourceList.ForEach(tr => tr.Trade(sellRatio, price));
                exportSupply.TradingResourceList.RemoveAll(su => su.Empty());
            }
        }
Ejemplo n.º 3
0
        public void Init()
        {
            ResourceData   = new List <SupplyToDemandRatio>();
            Supply         = new List <TradingResources>();
            ExternalSupply = new List <ExternalTradingResources>();
            int i = 0;

            foreach (ResourceTypes.ResourceType resourceType in ResourceTypes.GetIterator())
            {
                ResourceData.Add(new SupplyToDemandRatio(resourceType));
                Supply.Add(new TradingResources(resourceType).Init());
                ExternalSupply.Add(new ExternalTradingResources());
                i++;
            }
        }
Ejemplo n.º 4
0
        public void ComputeNewStock(ExternalMarket externalMarket)
        {
            foreach (ResourceTypes.ResourceType resourceType in ResourceTypes.GetIterator())
            {
                ComputeResourceRatio(resourceType);
                externalMarket.ComputeExternalTrade(GetExternalSupply(resourceType), Demand.GetAmount(resourceType), resourceType, GetSupplyToDemandRatio(resourceType).GetSupplyToDemandRatio(), this);
            }
            externalMarket.UpdateTrade(ExternalSupply);

            foreach (ResourceTypes.ResourceType resourceType in ResourceTypes.GetIterator())
            {
                MergeDublicates(GetSupply(resourceType));
                MergeDublicates(GetExternalSupply(resourceType));
                ComputeResourceRatio(resourceType);
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public Demand Init()
        {
            ResourceDemand = new PrimitivResource[Resource.ResourceTypeSize()];

            foreach (ResourceTypes.ResourceType resourceType in ResourceTypes.GetIterator())
            {
                ResourceDemand[(int)resourceType] = new PrimitivResource(resourceType, 0);
            }

            AmountNeeded = new double[Resource.ResourceTypeSize()];
            LifeValues   = new double[Resource.ResourceTypeSize()];
            double lifeValueFruit = 100;
            double lifeValueCloth = 10;

            TotalLifleValue = lifeValueFruit + lifeValueCloth;

            SetDemand(ResourceTypes.ResourceType.Fruit, 1, lifeValueFruit / TotalLifleValue);
            SetDemand(ResourceTypes.ResourceType.Cloth, 1, lifeValueCloth / TotalLifleValue);

            return(this);
        }
Ejemplo n.º 7
0
        public void Consume()
        {
            FoodLevel = 0;

            foreach (ResourceTypes.ResourceType resourceType in ResourceTypes.GetIterator())
            {
                double neededAmount = demand.GetDemand(resourceType);
                if (neededAmount == 0)
                {
                    continue;
                }

                double amountInStock = Stock.GetAmount(resourceType);

                if (amountInStock == 0)
                {
                    continue;
                }

                double ratio = Math.Min(1, amountInStock / neededAmount);
                FoodLevel += ratio * demand.GetLifeValueAdjusted(resourceType);
                Stock.Adjust(new PrimitivResource(resourceType, -ratio * neededAmount));
            }
        }