Exemplo n.º 1
0
        /// <summary>
        /// If you're willing to spend 'resourcesAvailable' and want to buy something with
        /// exponentially increasing cost each purchase (start at priceStart, multiply by priceRatio,
        /// already own currentOwned), how much of it can you buy?
        /// <para>
        /// Adapted from Trimps source code.
        /// </para>
        /// </summary>
        public static BigDouble AffordGeometricSeries(BigDouble resourcesAvailable, BigDouble priceStart,
                                                      BigDouble priceRatio, BigDouble currentOwned)
        {
            var actualStart = priceStart * BigDouble.Pow(priceRatio, currentOwned);

            //return Math.floor(log10(((resourcesAvailable / (priceStart * Math.pow(priceRatio, currentOwned))) * (priceRatio - 1)) + 1) / log10(priceRatio));

            return(BigDouble.Floor(BigDouble.Log10(resourcesAvailable / actualStart * (priceRatio - 1) + 1) / BigDouble.Log10(priceRatio)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// If you're willing to spend 'resourcesAvailable' and want to buy something with
        /// additively increasing cost each purchase (start at priceStart, add by priceAdd,
        /// already own currentOwned), how much of it can you buy?
        /// </summary>
        public static BigDouble AffordArithmeticSeries(BigDouble resourcesAvailable, BigDouble priceStart,
                                                       BigDouble priceAdd, BigDouble currentOwned)
        {
            var actualStart = priceStart + currentOwned * priceAdd;

            //n = (-(a-d/2) + sqrt((a-d/2)^2+2dS))/d
            //where a is actualStart, d is priceAdd and S is resourcesAvailable
            //then floor it and you're done!

            var b  = actualStart - priceAdd / 2;
            var b2 = BigDouble.Pow(b, 2);

            return(BigDouble.Floor(
                       (BigDouble.Sqrt(b2 + priceAdd * resourcesAvailable * 2) - b) / priceAdd
                       ));
        }
Exemplo n.º 3
0
 public static BigDouble Floor(this BigDouble value)
 {
     return(BigDouble.Floor(value));
 }