コード例 #1
0
ファイル: TableOpener.cs プロジェクト: enijkamp/pokerbot
        private TableContainer SeatPlayer(Point offset, Iterator <Image> screenIter, LobbyTable lobby)
        {
            TableLayout layout = new TableLayout9(offset);

            // crop
            Image screenshot = screenIter.next();
            Image tableImage = CropTable(screenshot, layout);

            // find empty seat
            TableIdentifier.OpenSeat openSeat = tableIdentifier.identifyOpenSeat(tableImage);

            // no open seat found or wrong table (too many open seats)
            if (openSeat == TableIdentifier.OpenSeat.NOT_FOUND || openSeat.TotalSeatsOpen > MAX_OPEN_SEATS)
            {
                Log.Info("table full or too many open seats");

                // close window
                CloseLastTable(screenIter);
                Thread.Sleep(250);
                MinimizeAllTables();
                Thread.Sleep(250);
                return(CANNOT_FIND_SEAT);
            }
            else
            {
                // seat player
                int x  = offset.X + openSeat.Offset.X + openSeat.Offset.Width / 2;
                int y  = offset.Y + openSeat.Offset.Y + openSeat.Offset.Height / 2;
                int rx = (int)(openSeat.Offset.Width / 2.5);
                int ry = (int)(openSeat.Offset.Height / 2.5);
                mouse.MoveAndLeftClick(x, y, rx, ry);

                // buy in and seat occupied
                int tries = 0;
                while (true)
                {
                    // tries
                    tries++;
                    if (tries > 25)
                    {
                        ErrorHandler.ReportExceptionWithImage(new Exception("cannot find buy-in or seat-occupied"), "buy in", screenshot);
                        return(CANNOT_FIND_SEAT);
                    }

                    // wait
                    Thread.Sleep(250);
                    screenshot = screenIter.next();

                    // check 'buy in'
                    if (IsBuyInVisible(layout, screenshot))
                    {
                        // buy in
                        keyboard.pressEnter();
                        break;
                    }

                    // check for 'seat is occupied'
                    if (IsSeatOccupied(layout, screenshot))
                    {
                        Log.Info("seat is occupied");

                        // click ok
                        mouse.MoveAndLeftClick(offset.X + layout.Occupied.X, offset.Y + layout.Occupied.Y, 4, 4);
                        Thread.Sleep(RandomInt(500, 1000));

                        // close window
                        CloseLastTable(screenIter);
                        Thread.Sleep(RandomInt(1500, 2000));
                        return(CANNOT_FIND_SEAT);
                    }
                }

                // move mouse near to checkboxes
                mouse.Move(offset.X + layout.SitOutClick.X + RandomInt(0, 15), offset.Y + layout.SitOutClick.Y - RandomInt(40, 60));

                // is "sit out next hand" visible?
                bool isFastTable = true;
                tries = 0;
                while (true)
                {
                    // tries
                    tries++;
                    if (tries > 25)
                    {
                        ErrorHandler.ReportExceptionWithImage(new Exception("cannot find checkboxes after buy-in"), "buy in", screenshot);
                        return(CANNOT_FIND_SEAT);
                    }

                    // screen
                    screenshot = screenIter.next();

                    // check sit-out pattern
                    if (IsSitOutVisible(layout, screenshot))
                    {
                        break;
                    }

                    // sleep
                    Thread.Sleep(RandomInt(300, 700));
                }

                // wait
                Thread.Sleep(RandomInt(100, 200));
                screenshot = screenIter.next();

                // auto-post blinds
                if (IsAutoPostBlindsVisible(layout, screenshot))
                {
                    // click auto-post
                    controller.PressAutoBlind(layout);

                    // is slow table
                    isFastTable = false;

                    // move mouse to safe location
                    mouse.Move(offset.X + layout.SitOutClick.X + RandomInt(0, 15), offset.Y + layout.SitOutClick.Y);
                }

                // double-check auto-post blinds
                screenshot = screenIter.next();
                if (IsAutoPostBlindsVisible(layout, screenshot))
                {
                    tries = 0;
                    while (true)
                    {
                        // tries
                        tries++;
                        if (tries > 3)
                        {
                            ErrorHandler.ReportExceptionWithImage(new Exception("cannot select auto-post blinds"), "blinds", screenshot);
                            Log.Info("Closing table");
                            CloseLastTable(screenIter);
                            Thread.Sleep(400);
                            keyboard.pressEnter();
                            return(CANNOT_FIND_SEAT);
                        }

                        // screen
                        mouse.Move(offset.X + layout.SitOutClick.X + RandomInt(0, 15), offset.Y + layout.SitOutClick.Y);
                        Thread.Sleep(400);
                        screenshot = screenIter.next();

                        // check
                        if (!IsAutoPostBlindsChecked(layout, screenshot))
                        {
                            // click auto-post
                            controller.PressAutoBlind(layout);

                            // is slow table
                            isFastTable = false;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                // sit out
                Thread.Sleep(RandomInt(50, 300));
                Controller.PressSitOut(mouse, layout);

                // check for "I'm back button" button
                tries = 0;
                while (true)
                {
                    // tries
                    tries++;
                    if (tries > 10)
                    {
                        // close window
                        ErrorHandler.ReportExceptionWithImage(new Exception("I'm back button not visible while opening table"), "Open table", tableImage);
                        Log.Info("Closing table");
                        CloseLastTable(screenIter);
                        Thread.Sleep(250);
                        keyboard.pressEnter();
                        Thread.Sleep(RandomInt(1500, 2000));
                        return(CANNOT_FIND_SEAT);
                    }

                    // look for button
                    Thread.Sleep(500);
                    screenshot = screenIter.next();
                    tableImage = CropTable(screenshot, layout);
                    if (IsImBackVisible(layout, tableImage))
                    {
                        break;
                    }
                }

                // container
                Image          cornerTopLeft     = CropTableTopLeftCorner(screenshot, offset);
                Image          cornerBottomRight = CropTableBottomRightCorner(screenshot, offset);
                TableContainer table             = new TableContainer(globalTableNumber++, cornerTopLeft, cornerBottomRight, layout, openSeat.Num, isFastTable, lobby);
                return(table);
            }
        }
コード例 #2
0
ファイル: TableOpener.cs プロジェクト: enijkamp/pokerbot
        public TableContainer LocateNewTable(Settings settings)
        {
            Log.Info("## scanning for tables ##");

            // find offset
            Iterator <Image> screen      = new ScreenImageIterator(deviceControl);
            Image            screenshot  = screen.next();
            Point            foundOffset = PatternLocator.locateUnknownTable(screenshot, Offsets(knownTables), new TableLayout9());

            if (foundOffset == Point.Empty)
            {
                Log.Error("No table found");
                throw new ArgumentException("No table found");
            }

            // check for new table and find seat
            Image cornerTopLeft     = CropTableTopLeftCorner(screenshot, foundOffset);
            Image cornerBottomRight = CropTableBottomRightCorner(screenshot, foundOffset);

            if (!IsOffsetKnown(foundOffset))
            {
                // corner
                Log.Info("unknown table found at x=" + foundOffset.X + " y=" + foundOffset.Y);
                TableLayout layout = new TableLayout9(foundOffset);

                // find seat
                string player = settings.Name;
                Log.Info("looking for '" + player + "' on table" + (knownTables.Count + 1));
                int seat = -1;
                for (int tries = 0; tries < 3; tries++)
                {
                    Table previousTable = tableIdentifier.identifyTableForLocation(CropTable(screen.next(), layout));
                    seat = BotAppLogic.IdentifySeat(previousTable, player);
                    if (seat != -1)
                    {
                        break;
                    }
                    Thread.Sleep(500);
                }
                if (seat == -1)
                {
                    Log.Error("Cannot find player position on table " + (knownTables.Count + 1));
                    throw new ArgumentException("Cannot find player position on table " + (knownTables.Count + 1));
                }
                Log.Info("my seat on new table " + (knownTables.Count + 1) + " is " + (seat + 1));

                // blinds
                Image tableImage  = CropTable(screenshot, layout);
                Image blindsImage = tableImage.crop(layout.AutoBlindPattern.X, layout.AutoBlindPattern.X + layout.AutoBlindPattern.Width,
                                                    layout.AutoBlindPattern.Y, layout.AutoBlindPattern.Y + layout.AutoBlindPattern.Height);
                bool isFast = !PatternLocator.locateAutoPostBlinds(blindsImage);

                // container
                TableContainer table = new TableContainer(knownTables.Count, cornerTopLeft, cornerBottomRight, layout, seat, isFast, LobbyTable.Empty);
                knownTables.Add(table);
                return(table);
            }
            else
            {
                throw new Exception("No unknown table found");
            }
        }