Beispiel #1
0
 public BotAppLogic(DeviceControl deviceControl)
 {
     this.deviceControl = deviceControl;
     this.tableOpener   = new TableOpener(deviceControl,
                                          new HumanMouse(deviceControl, HumanMouse.Speed.Fast),
                                          new Keyboard(deviceControl), tableIdentifier);
 }
Beispiel #2
0
        public BotAppLogic(DeviceControl deviceControl, Settings settings)
        {
            this.settings      = settings;
            this.deviceControl = deviceControl;
            this.tableOpener   = new TableOpener(deviceControl,
                                                 new HumanMouse(deviceControl, settings.FastMouse ? HumanMouse.Speed.Super : HumanMouse.Speed.Fast),
                                                 new Keyboard(deviceControl), tableIdentifier);

            // alive keeper
            SetupAliveKeeper();
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            Log.SetLevel(Log.Level.FINEST);
            Thread.Sleep(5000);
            Dictionary <string, string> config = BotAppLogic.ReadConfig();
            Win32Control ctrl     = new Win32Control();
            TableOpener  opener   = new TableOpener(ctrl, new HumanMouse(ctrl), new Keyboard(ctrl), new TableIdentifier(new TableLayout9()));
            Settings     settings = new Settings();

            settings.AutoLocateTablesNum = 1;
            opener.OpenNewTables(settings, ImageRendererForm.newImageRendererForm());
            Thread.Sleep(3000);
            opener.SitIn();
        }
Beispiel #4
0
        private void setAmountText(TableLayout table, double decisionAmount)
        {
            // text
            string amountText = String.Format("{0:0.00}", decisionAmount);

            amountText = amountText.Replace(',', '.');

            // type in and check
            int tries = 0;

            while (true)
            {
                // max tries
                tries++;
                if (tries > 2)
                {
                    ErrorHandler.ReportExceptionWithImage(new Exception("cannot type in amount"), "raise error", screen.next());
                    break;
                }

                // type in amount
                doubleClick(table, table.SliderText);
                Thread.Sleep(RandomInt(150, 250));
                keyboard.pressKeys(amountText);

                // get amount from button
                Thread.Sleep(RandomInt(50, 100));
                Image screenshot             = screen.next();
                Image tableImage             = TableOpener.CropTable(screenshot, table);
                List <TableControl> controls = tableIdentifier.identifyControls(tableImage);
                double amountButton          = getAmountFromButton(controls);

                // double check
                double roundButton   = Math.Round(amountButton, 2, MidpointRounding.AwayFromZero);
                double roundDecision = Math.Round(decisionAmount, 2, MidpointRounding.AwayFromZero);
                if (roundButton >= roundDecision)
                {
                    // ok
                    break;
                }
                else
                {
                    // error
                    Log.Error("cannot type in amount - try " + tries);
                }
            }
        }
Beispiel #5
0
        private void ProcessTables(Settings settings, bool resetMouse)
        {
            // screen
            Iterator <Image> screen = new ScreenImageIteratorFast(deviceControl);

            // evaluator
            List <Rule>     rules       = RulesReader.readRules();
            RuleEvaluator   evaluator   = new RuleEvaluator(rules);
            RuleInterpreter interpreter = new RuleInterpreter(settings.SmallBlind, settings.BigBlind);

            if (settings.PreCheckRules)
            {
                DateTime startCheck = DateTime.Now;
                interpreter.precheck(rules);
                Log.Info("# prechecking rules took " + DateTime.Now.Subtract(startCheck).TotalMilliseconds + " ms");
            }

            // controller
            double     betSlideTextLimit = settings.PlayMoney ? 100 : 0.2;
            Mouse      mouse             = new HumanMouse(deviceControl, settings.FastMouse ? HumanMouse.Speed.Fast : HumanMouse.Speed.Normal);
            Keyboard   keyboard          = new Keyboard(deviceControl);
            Controller controller        = new Controller(keyboard, mouse, betSlideTextLimit, tableIdentifier, new ScreenImageIterator(deviceControl));

            // clicker
            RandomClicker clicker = new RandomClicker(new Point(deviceControl.DisplayWidth, 0), mouse);

            // replayer
            Replayer replayer = new Replayer(deviceControl);

            // table switcher
            TableSwitcher switcher = new TableSwitcher(mouse, deviceControl, settings.TaskbarColors);

            // reset mouse
            if (resetMouse)
            {
                deviceControl.ResetMouse();
            }

            // loop
            while (screen.hasNext())
            {
                // start
                Log.Debug("## iteration -> start ##");
                DateTime start = DateTime.Now;

                // screenshot
                DateTime startScreen      = DateTime.Now;
                Image    unsafeScreenshot = screen.next();
                Log.Debug("screenshot took " + DateTime.Now.Subtract(startScreen).TotalMilliseconds + " ms");

                // tables
                foreach (TableContainer container in tableOpener.KnownTables)
                {
                    // table image
                    Log.Debug("# processing table " + (container.Number + 1));
                    Image unsafeTableImage = TableOpener.CropTable(unsafeScreenshot, container.Layout);

                    // render table
                    if (container.Renderer != null)
                    {
                        DateTime startRender = DateTime.Now;
                        container.Renderer.clearImages();
                        container.Renderer.renderImage(unsafeTableImage, 0, 0);
                        tableIdentifier.Renderer = container.Renderer;
                        Log.Debug("rendering took " + DateTime.Now.Subtract(startRender).TotalMilliseconds + " ms");
                    }

                    // table status
                    bool isTableVisible    = tableOpener.IsTableVisible(container, unsafeTableImage);
                    bool areControlsActive = isTableVisible ? tableIdentifier.identifyMove(unsafeTableImage) : false;
                    Log.Debug("# table" + container.Number + ": vis=" + isTableVisible + " buttons=" + areControlsActive);

                    // HANDLE ERRORS: table window should not be visible, but it is
                    if (isTableVisible)
                    {
                        // "you have been removed"
                        if (!areControlsActive && YouHaveBeenRemovedVisible(container.Layout, unsafeTableImage))
                        {
                            // close it
                            switcher.action();
                            ErrorHandler.ReportExceptionWithImage(new Exception("You have been removed"), "handle errors", unsafeTableImage);
                            keyboard.pressEnter();
                            controller.CloseTableWithEnter(container.Layout);
                            container.Close();
                            // wait, otherwise table is visible on next screenshot
                            Thread.Sleep(500);
                            break;
                        }

                        // "I'm back"
                        if (!sitOutNextHand && !areControlsActive && !container.IsWaitingForBlind && IsImBackVisible(container.Layout, unsafeTableImage))
                        {
                            // close it
                            switcher.action();
                            ErrorHandler.ReportExceptionWithImage(new Exception("I'm back visible"), "handle errors", unsafeTableImage);
                            controller.CloseTableWithEnter(container.Layout);
                            container.Close();
                            // wait, otherwise table is visible on next screenshot
                            Thread.Sleep(500);
                            break;
                        }

                        // "Post Blind"
                        if (!container.IsWaitingForBlind && areControlsActive && IsPostBlindVisible(container.Layout, unsafeTableImage))
                        {
                            // close it
                            switcher.action();
                            ErrorHandler.ReportExceptionWithImage(new Exception("Post Blind visible"), "handle errors", unsafeTableImage);
                            controller.CloseTableWithEnter(container.Layout);
                            container.Close();
                            // wait, otherwise table is visible on next screenshot
                            Thread.Sleep(500);
                            break;
                        }

                        // "Check or Fold"
                        if (areControlsActive && IsCheckOrFoldMsgBoxVisible(container.Layout, unsafeTableImage))
                        {
                            // press check
                            switcher.action();
                            ErrorHandler.ReportExceptionWithImage(new Exception("Check or Fold visible"), "handle errors", unsafeTableImage);
                            keyboard.pressEnter();
                            // wait
                            Thread.Sleep(500);
                            break;
                        }
                    }

                    // HANDLE TABLE: processing table and handling controls (if the corner image matches)
                    if (isTableVisible && (areControlsActive || container.IsWaitingForBlind))
                    {
                        // move mouse if required
                        if (switcher.isSameContainer(container.Number) && !switcher.hasPrevIterationAction() && !areControlsActive)
                        {
                            // same table and nothing happend since previous iteration
                            Sleep(settings, RandomInt(300, 500));
                        }
                        else
                        {
                            // move mouse to safe location (screenshot)
                            MoveMouseToSafePosition(controller.Mouse, container.Layout);
                            Sleep(settings, RandomInt(50, 100));
                        }

                        // take clean screenshot
                        Image safeScreenshot = screen.next();
                        Image safeTableImage = TableOpener.CropTable(safeScreenshot, container.Layout);
                        if (container.Renderer != null)
                        {
                            container.Renderer.clearImages();
                            container.Renderer.renderImage(safeTableImage, 0, 0);
                        }

                        // CLOSE TABLE: check if table has to be closed
                        if (container.IsWaitingForBlind)
                        {
                            Log.Debug("table " + (container.Number + 1) + " checking for big blind indication");

                            // detect
                            bool fastTableToClose = container.IsFastTable && IsImBackVisible(container.Layout, safeTableImage);
                            bool slowTableToClose = container.IsSlowTable && IsPostBlindVisible(container.Layout, safeTableImage);

                            // close it
                            if (fastTableToClose || slowTableToClose)
                            {
                                // click on close and press enter
                                CloseTable(container, controller);

                                // wait, otherwise table is visible on next screenshot
                                Thread.Sleep(500);

                                // done with this table
                                break;
                            }
                        }

                        // HANDLE CONTROLS: identify controls, table, press butto´n
                        if (areControlsActive)
                        {
                            Log.Info("table " + (container.Number + 1) + " handling controls");

                            // active container (-> UI)
                            container.Active();

                            // identify controls
                            List <TableControl> controls = new List <TableControl>();
                            try
                            {
                                controls = tableIdentifier.identifyControls(safeTableImage);
                            }
                            catch (Exception ex)
                            {
                                // error beep
                                ErrorHandler.BeepError();

                                // press fold
                                PressFold(container.Layout, controller);

                                // report
                                ErrorHandler.ReportTableException(ex, safeTableImage, "Identify controls");

                                continue;
                            }

                            // process table actions
                            try
                            {
                                // identify table
                                DateTime startIdentify = DateTime.Now;
                                Log.Debug("table " + (container.Number + 1) + " identifying");
                                Table table = tableIdentifier.identifyTable(safeTableImage, container.Seat);
                                Log.Debug("identify took " + DateTime.Now.Subtract(startIdentify).TotalMilliseconds + " ms");

                                // remember money
                                if (table.HasSeat && table.MyPlayer.HasMoney)
                                {
                                    container.Money = table.MyPlayer.Money;
                                }

                                // fire money changed event
                                MoneyChanged();

                                // identify max bet
                                table.MaxBet = GetMaxBet(controls);
                                Log.Debug("max bet on table " + (container.Number + 1) + " is " + table.MaxBet);

                                // press buttons
                                Log.Debug("table " + (container.Number + 1) + " pressing buttons");
                                ProcessTable(settings, safeTableImage, container.Renderer, table, container, evaluator, interpreter,
                                             controller, replayer, clicker, controls);

                                // done something
                                switcher.action();
                            }
                            catch (Exception ex)
                            {
                                // done something
                                switcher.action();

                                // error beep
                                ErrorHandler.BeepError();

                                // press fold
                                PressCheckOrFold(controls, container.Layout, controller);

                                // move mouse to taskbar
                                MoveMouseToTaskBar(controller.Mouse);

                                // report
                                ErrorHandler.ReportTableException(ex, safeTableImage, "Identify table");

                                continue;
                            }
                        }
                    }
                }

                // check table highlights
                switcher.check(settings.WindowSwitcherActivated);

                // sleep
                Thread.Sleep(RandomInt(200, 300));

                // end
                double time = DateTime.Now.Subtract(start).TotalMilliseconds;
                Log.Debug("## iteration -> end -> " + time + " ms ##");
            }
        }