Esempio n. 1
0
 public Region()
 {
     Negbours       = new List <Region>();
     internalMarket = new InternalMarket();
     externalMarket = new ExternalMarket(this, Negbours);
     Populations    = new List <Population>();
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void Update()
        {
            InternalMarket.UpdateMarket(Populations);
            InternalMarket.ComputeNewStock(ExternalMarket);
            InternalMarket.DoTrade(Populations);

            UpdatePopulation();
            CleanUp();
        }
Esempio n. 4
0
        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")));
            }
        }
Esempio 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);
        }
Esempio n. 6
0
        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;
                }
            }
        }
Esempio n. 7
0
        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;
                }
            }
        }
Esempio n. 8
0
 public double GetSallery(InternalMarket market)
 {
     return(GetEfficensy() * market.GetPrice(ProducingType));
 }
Esempio n. 9
0
 public void UpdateDemand(InternalMarket market)
 {
     demand.UpdateDemand(market, this);
 }
Esempio n. 10
0
 public void CleanUp()
 {
     ExternalMarket.FinilizeTrades();
     InternalMarket.CleanUp();
 }
Esempio n. 11
0
 public double GetResorceCost(ResourceTypes.ResourceType resource)
 {
     return(InternalMarket.GetPrice(resource));
 }