Example #1
0
        /// <summary>
        /// Generates a random number of milliseconds for the bot to take a break
        /// </summary>
        /// <returns>the number of milliseconds for the bot to rest</returns>
        private int RandomBreakTime()
        {
            double breakType = RNG.NextDouble();
            double mean, stdDev;   //measured in minutes

            //average of 25.1 minutes
            if (breakType < 0.75)   //75%
            {
                mean   = 15;
                stdDev = 5.5;
            }
            else if (breakType < 0.90)  //15%
            {
                mean   = 33;
                stdDev = 8.7;
            }
            else  //10%
            {
                mean   = 89;
                stdDev = 41;
            }

            int minBreakTime = 2;
            int breakLength  = (int)Probability.BoundedGaussian(mean, stdDev, minBreakTime, double.MaxValue);

            return(UnitConversions.MinutesToMilliseconds(breakLength));
        }
Example #2
0
        /// <summary>
        /// Generates a number of milliseconds for the bot to run before logging out and resting
        /// </summary>
        /// <returns>the next work time in milliseconds</returns>
        public int RandomWorkTime()
        {
            double workType = RNG.NextDouble();
            double mean, stdDev;   //measured in minutes

            //average of 84.8 minutes
            if (workType < 0.3)   //30%
            {
                mean   = 45;
                stdDev = 18;
            }
            else if (workType < 0.7) //40%
            {
                mean   = 83;
                stdDev = 35;
            }
            else //30%
            {
                mean   = 127;
                stdDev = 21;
            }

            double workTime = Probability.BoundedGaussian(mean, stdDev, 1, 345);

            workTime = Math.Min(workTime, (RunParams.RunUntil - DateTime.Now).TotalMilliseconds);
            return(UnitConversions.MinutesToMilliseconds(workTime));
        }
Example #3
0
 /// <summary>
 /// Waits for a random time from a Gaussian distribution
 /// </summary>
 /// <param name="meanWaitTime">average wait time</param>
 /// <param name="stdDev">standard deviation froom the mean</param>
 /// <returns>true if the StopFlag has been raised</returns>
 public static bool SafeWait(long meanWaitTime, double stdDev)
 {
     if (meanWaitTime <= 0)
     {
         return(StopFlag);
     }
     else
     {
         int waitTime = (int)Probability.BoundedGaussian(meanWaitTime, stdDev, 0.0, double.MaxValue);
         return(SafeWait(waitTime));
     }
 }
Example #4
0
        public void BoundedGaussianRangeTest(double minValue, double maxValue)
        {
            double total = 0;
            double sample;

            for (int i = 0; i < numSamples; i++)
            {
                sample = Probability.BoundedGaussian(minValue, maxValue);
                Assert.IsFalse(sample < minValue);
                Assert.IsFalse(sample > maxValue);
                total += sample;
            }
            double average      = total / ((double)numSamples);
            double maxDeviation = 2.5 * ((maxValue - minValue) / Math.Sqrt(numSamples));
            double expectedMean = Numerical.Average(minValue, maxValue);
        }
Example #5
0
        public void BoundedGaussianTest(double mean, double stdDev, double minValue, double maxValue, double expectedMean)
        {
            double total = 0;
            double sample;

            for (int i = 0; i < numSamples; i++)
            {
                sample = Probability.BoundedGaussian(mean, stdDev, minValue, maxValue);
                Assert.IsFalse(sample < minValue);
                Assert.IsFalse(sample > maxValue);
                total += sample;
            }
            double average      = total / ((double)numSamples);
            double maxDeviation = 10 * (stdDev / Math.Sqrt(numSamples));

            Assert.AreEqual(expectedMean, average, maxDeviation);
        }
Example #6
0
        /// <summary>
        /// Moves a mouse across a screen like a human would
        /// </summary>
        /// <param name="x">x-coordinate to move to</param>
        /// <param name="y">y-coordinate to move to</param>
        private static void NaturalMove(int x, int y)
        {
            Stopwatch watch            = new Stopwatch();
            Point     startingPosition = SystemLocation;
            double    currentX         = startingPosition.X;
            double    currentY         = startingPosition.Y;
            float     slope            = (float)((y - currentY) / (x - currentX));

            int    sleepTime         = (int)(1000.0 / MOUSE_MOVE_RATE); //milliseconds per mouse movement
            double mouseMoveSpeed    = Probability.BoundedGaussian(MOUSE_MOVE_SPEED, 0.25 * MOUSE_MOVE_SPEED, 0.1 * MOUSE_MOVE_SPEED, double.MaxValue);
            double incrementDistance = mouseMoveSpeed / MOUSE_MOVE_RATE;

            double xDistance         = x - currentX;
            double yDistance         = y - currentY;
            double totalDistance     = Math.Sqrt(Math.Pow(xDistance, 2.0) + Math.Pow(yDistance, 2.0));
            double slowMoveDistance  = Math.Min(totalDistance, Probability.BoundedGaussian(102, 10, 0, double.MaxValue));
            double moveDistance      = totalDistance - slowMoveDistance;
            int    discreteMovements = (int)(moveDistance / incrementDistance);

            moveDistance     = discreteMovements * incrementDistance;
            slowMoveDistance = totalDistance - moveDistance;

            CubicSpline xSpline, ySpline;

            CreateParameterizedSplines(startingPosition, new Point(x, y), out xSpline, out ySpline);

            //move at normal mouse speed when far away from the target
            double completion = 0.0;

            for (int i = 1; i <= discreteMovements; i++)
            {
                if (BotProgram.StopFlag)
                {
                    return;
                }

                watch.Restart();
                completion = (i * incrementDistance) / totalDistance;
                currentX   = xSpline.Eval((float)completion);
                currentY   = ySpline.Eval((float)completion);
                SetCursorPos((int)currentX, (int)currentY);
                Thread.Sleep(Math.Max(0, sleepTime - (int)watch.ElapsedMilliseconds));
            }

            //move the mouse slowly when close to the target
            double completed     = completion;
            double slowIncrement = Probability.BoundedGaussian(0.5 * incrementDistance, 0.15 * incrementDistance, 0.2 * incrementDistance, 0.75 * incrementDistance);
            double slowMovements = (int)(slowMoveDistance / slowIncrement);

            for (int i = 1; i <= slowMovements; i++)
            {
                if (BotProgram.StopFlag)
                {
                    return;
                }

                watch.Restart();
                completion = completed + ((i * slowIncrement) / totalDistance);
                currentX   = xSpline.Eval((float)completion);
                currentY   = ySpline.Eval((float)completion);
                SetCursorPos((int)currentX, (int)currentY);
                Thread.Sleep(Math.Max(0, sleepTime - (int)watch.ElapsedMilliseconds));
            }
            ForceMove(x, y);
        }