コード例 #1
0
ファイル: TestRulesReader.cs プロジェクト: enijkamp/pokerbot
        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
ファイル: TestSituation.cs プロジェクト: enijkamp/pokerbot
        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
        public void ProcessTable(Settings settings,
                                 Image tableImage,
                                 TableRenderer renderer,
                                 Table table,
                                 TableContainer container,
                                 RuleEvaluator evaluator,
                                 RuleInterpreter interpreter,
                                 Controller controller,
                                 Replayer replayer,
                                 RandomClicker clicker,
                                 List <TableControl> controls)
        {
            // hand visible?
            if (table.Hand.Count != 0)
            {
                // identify situation
                Situation situation = SituationEvaluator.evaluateSituation(tableImage, table, controls, settings.BigBlind);

                // wait for blinds activatd or not enough players or money reached
                if (!container.IsWaitingForBlind && situation.Street == StreetTypes.Preflop)
                {
                    // override blinds?
                    if (waitForBlinds)
                    {
                        Log.Info("table " + (container.Number + 1) + " override blinds");
                        WaitForBlind(controller, container);
                    }
                    // out of players?
                    else if (table.IsOutOfPlayers)
                    {
                        Log.Info("table " + (container.Number + 1) + " ran out of players");
                        CloseTable(container, controller);
                        return;
                    }
                    // reached money?
                    else if (settings.CloseTableActivated && table.HasSeat && table.MyPlayer.HasMoney)
                    {
                        if (table.MyPlayer.Money > settings.CloseTableMoneyMax)
                        {
                            Log.Info("table " + (container.Number + 1) + " reached money limit " + table.MyPlayer.Money);
                            CloseTable(container, controller);
                            return;
                        }
                    }
                }

                // evaluate rule
                Rule rule = evaluator.findRule(situation.Street,
                                               situation.Hand,
                                               situation.Chance,
                                               situation.Opponents,
                                               situation.OpponentAction,
                                               situation.Position,
                                               table.MaxBet,
                                               table.Pot);
                // decision
                Decision decision = interpreter.interpret(table, rule.Decision);

                // render table
                Log.Debug("# rendering table");
                if (renderer != null)
                {
                    renderer.render(table, container.Layout, situation, rule, decision, controls);
                }

                // beep
                if (decision.DecisionType == Decision.Types.BET ||
                    decision.DecisionType == Decision.Types.CALL ||
                    decision.DecisionType == Decision.Types.RAISE)
                {
                    if (situation.Hand != HandTypes.None)
                    {
                        Beep(settings);
                        TextToSpeech.SayAsnc(settings, situation.Hand);
                    }
                }

                // random click on table
                if (RandomBool(0.05) && settings.AutoClick)
                {
                    Log.Debug("# auto click on table");
                    clicker.click(container.Layout);
                }

                // sit out
                if (!container.IsSittingOut && sitOutNextHand)
                {
                    SitOut(controller, container);
                }

                // press buttons
                Log.Debug("# press controls");
                Thread.Sleep(RandomInt(100, 500));
                controller.Handle(decision, container.Layout, controls);

                // random mouse moves
                if (RandomBool(0.05) && settings.AutoMoveMouse)
                {
                    Log.Debug("# auto move mouse");
                    Sleep(settings, RandomInt(100, 300));
                    AutoMoveMouse(controller.Mouse);
                }
                if (situation.Opponents > 2 && RandomBool(0.05) && settings.ReplayMouseMoves)
                {
                    Log.Debug("# replay mouse");
                    Sleep(settings, RandomInt(100, 300));
                    replayer.ReplayRandomShort();
                }
            }
            else
            {
                // render table
                Log.Debug("# rendering table");
                renderer.render(table, container.Layout);
            }
        }
コード例 #4
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 ##");
            }
        }