Пример #1
0
        /// <summary>
        /// Buying PrimitiveStorageSet, subsidizations allowed
        /// </summary>
        //internal void SellList(Consumer buyer, StorageSet buying, Country subsidizer)
        //{
        //    foreach (Storage item in buying)
        //        if (item.isNotZero())
        //            buy(buyer, item, subsidizer);
        //}

        /// <summary>
        /// Buying needs in circle, by Procent in time
        /// return true if buying is zero (bought all what it wanted)
        /// </summary>
        internal bool Sell(Producer buyer, StorageSet stillHaveToBuy, Procent buyInTime, List <Storage> ofWhat)
        {
            bool buyingIsFinished = true;

            foreach (Storage what in ofWhat)
            {
                Storage consumeOnThisIteration = new Storage(what.Product, what.get() * buyInTime.get());
                if (consumeOnThisIteration.isZero())
                {
                    return(true);
                }

                // check if consumeOnThisIteration is not bigger than stillHaveToBuy
                if (!stillHaveToBuy.has(consumeOnThisIteration))
                {
                    consumeOnThisIteration = stillHaveToBuy.getBiggestStorage(what.Product);
                }
                var reallyBought = Sell(buyer, consumeOnThisIteration, null);

                stillHaveToBuy.Subtract(reallyBought);

                if (stillHaveToBuy.getBiggestStorage(what.Product).isNotZero())
                {
                    buyingIsFinished = false;
                }
            }
            return(buyingIsFinished);
        }
Пример #2
0
        public bool isAllInputProductsCollected()
        {
            var realNeeds = getRealAllNeeds();

            foreach (var item in realNeeds)
            {
                if (!inputProductsReserve.has(item))
                {
                    return(false);
                }
            }
            return(true);
        }