コード例 #1
0
ファイル: Program.cs プロジェクト: evancg37/Quizup-Bot-3.0
        public static void onNewScreenshot(object sender, FileSystemEventArgs e)
        {
            //When the event is triggered, it is too soon to access the file. We must wait until a file appears in the directory.
            DateTime eventTriggered = DateTime.Now;

            string[] files;
            while (true)
            {
                files = Directory.GetFiles(@"D:\_programming\Quizupbot 3.0\INPUT\");
                if (files.Length == 0)
                {
                    Thread.Sleep(100);
                }
                else
                {
                    break;
                }
            }
            string file = files[0];

            Console.WriteLine("Time from event to execution", (DateTime.Now - eventTriggered).TotalSeconds);

            Bitmap problem = new Bitmap(file);

            Console.WriteLine("New screenshot detected: " + file);

            MathResult result = MathPlayer.solveProblem(problem);

            result.answerScreenshot.Save(SCREENSHOT_DIRECTORY + string.Format("FINAL_ANSWER_{0}.bmp", result.answers.answer));
            Console.Write("\nLOG:\n" + result.log);
            problem.Dispose();
            File.Delete(file);
            Console.WriteLine("Operation completed in {0:F4} seconds", (DateTime.Now - eventTriggered).TotalSeconds);
        }
コード例 #2
0
        public static MathResult solveProblem(Bitmap problem)
        {
            DateTime callTime   = DateTime.Now;
            Bitmap   answerShot = new Bitmap(problem);

            List <MathCharacter> mathList = decipherMathFromArea(getBitmapFromRectangle(problem, QUESTION_DISPLAY));

            /*
             * result.appendLog("Problem mathList: ", newline: false);
             * foreach (MathCharacter character in mathList)
             *  result.appendLog(character.number, newline: false);
             * result.appendLog("");
             */

            int answer = calculateMathFromList(mathList);
            //result.appendLog("Answered successfully retrieved: " + answer);

            MathAnswers answerSet = decipherMathAnswers(problem, answer);

            //result.setAnswer(answerSet);

            using (Graphics g = Graphics.FromImage(answerShot))
            {
                g.DrawImage(problem, 0, 0);
                g.DrawString(answerSet.answer.ToString(), new Font("Arial", 48), new SolidBrush(Color.Aqua), new PointF(505, 600));
                Point curvePoint    = new Point(answerSet.answerPoint.X - 270, answerSet.answerPoint.Y - 30);
                Size  rectangleSize = new Size(540, 60);

                Pen pen;
                if (!answerSet.answerFound)                         //Red circle if guess
                {
                    pen = new Pen(Color.Red, 10.0f);
                }
                else                                                //Green circle if correct
                {
                    pen = new Pen(Color.Green, 10.0f);
                }

                g.DrawEllipse(pen, new Rectangle(curvePoint, rectangleSize));
            }

            MathResult result = new MathResult(problem, answerShot, answerSet, DateTime.Now - callTime);

            return(result);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: evancg37/Quizup-Bot-3.0
        static void Main(string[] args)
        {
            //SCREENCAP MODE

            /*
             * ScreencapStream screencapper = new ScreencapStream(new Rectangle(emulatorTopLeft, emulatorSize));
             * screencapper.beginSnapshotStream();
             *
             * Display disp = new Display();
             * disp.Visible = true;
             *
             * while (true)
             * {
             *  Thread.Sleep(1000);
             *  Console.WriteLine("Looping.");
             *  Bitmap sc = screencapper.getCurrentSnapshot();
             *  Random rd = new Random();
             *  int i = rd.Next(1, 99);
             *  sc.Save(@"D:\_programming\Quizupbot 3.0\SCREENSHOTS\SCREENCAPPER_" + i + ".bmp");
             *  disp.updateDisplay(sc);
             *
             * }
             *
             */

            //MANUAL LOOP MODE

            while (true)
            {
                Console.WriteLine("Ready. Press enter to execute...");
                Console.ReadLine(); Console.Clear();

                Bitmap problem = takeSnapshotOfEmulator();

                problem.Save(SCREENSHOT_DIRECTORY + "PREPROCESSING_SCREENSHOT_" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + ".bmp");
                Console.WriteLine("Screenshot taken.");

                MathResult result = MathPlayer.solveProblem(problem);

                Point clickPoint        = result.answers.answerPoint;
                float SCALE_FACTOR_TEMP = 0.497222f;
                Point adjustedPoint     = new Point((int)(clickPoint.X * SCALE_FACTOR_TEMP), (int)(clickPoint.Y * SCALE_FACTOR_TEMP));
                adjustedPoint = new Point(adjustedPoint.X + emulatorTopLeft.X, adjustedPoint.Y + emulatorTopLeft.Y);

                Console.WriteLine("Clicking at {0}, {1}", adjustedPoint.X, adjustedPoint.Y);
                LeftMouseClick(adjustedPoint.X, adjustedPoint.Y);


                Console.WriteLine("Finished.");
                result.answerScreenshot.Save(SCREENSHOT_DIRECTORY + "POSTPROCESSING_SCREENSHOT_" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + ".bmp");
                Console.WriteLine("LOG:\n" + result.log);
            }


            //FOLDER WATCH MODE

            /*
             * FileSystemWatcher folderWatcher = new FileSystemWatcher(@"D:\_programming\Quizupbot 3.0\INPUT\");
             * folderWatcher.Created += new FileSystemEventHandler(onNewScreenshot);
             *
             * folderWatcher.EnableRaisingEvents = true;
             * Console.WriteLine("Running.");
             * while (true)
             * {
             *  Thread.Sleep(100);
             * }
             */
        }