示例#1
0
        public static void Main(string[] args)
        {
            string       hand     = "qh kc";
            string       board    = "qs 7c qc 8d 8s";
            HandAnalysis analysis = HandEvaluator.evalHandSmart(CardParser.parse(hand), CardParser.parse(board));

            Console.WriteLine("chance = " + analysis.Chance);
            Console.WriteLine("basic = " + analysis.HandBasic);
            Console.WriteLine("smart = " + analysis.HandSmart);

            List <Rule>   rules = RulesReader.readRules();
            RuleEvaluator eval  = new RuleEvaluator(rules);
            Rule          rule  = eval.findRule(StreetTypes.Turn, HandTypes.Top_pair, ChanceTypes.Draws, 4, OpponentActionTypes.Check, PositionTypes.Early, 0.5, 0.7);

            Console.WriteLine(rule.Decision);
            Console.ReadKey();
        }
示例#2
0
        public static void Main(string[] args)
        {
            string              hand    = "2d 2s";
            string              board   = "9d 2h 7s 9s Ts";
            StreetTypes         street  = StreetTypes.River;
            int                 opps    = 1;
            OpponentActionTypes action  = OpponentActionTypes.Raise;
            double              maxBet  = 1.26;
            double              potSize = 0.64;

            HandAnalysis analysis = HandEvaluator.evalHandSmart(CardParser.parse(hand), CardParser.parse(board));

            Console.WriteLine("chance = " + analysis.Chance);
            Console.WriteLine("basic = " + analysis.HandBasic);
            Console.WriteLine("smart = " + analysis.HandSmart);

            List <Rule>   rules = RulesReader.readRules();
            RuleEvaluator eval  = new RuleEvaluator(rules);
            Rule          rule  = eval.findRule(street, analysis.HandSmart, analysis.Chance, opps, action, PositionTypes.Early, maxBet, potSize);

            Console.WriteLine("rule = " + rule.Decision);

            Console.ReadKey();
        }
示例#3
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 ##");
            }
        }