Example #1
0
        private List <LobbyTable> IdentifyLobbyTables(LobbyIdentifier lobbyIdentifier, LobbyLayout layout, Iterator <Image> screen, Point offset)
        {
            for (int tries = 0; tries < 10; tries++)
            {
                // time
                DateTime startLobby = DateTime.Now;

                // select last row
                mouse.MoveAndLeftClick(offset.X + layout.LastRow.X, offset.Y + layout.LastRow.Y, 20, 5);

                // move mouse
                mouse.Move(offset.X + layout.Mouse.X, offset.Y + layout.Mouse.Y);
                Thread.Sleep(100);

                // shot
                Image screenshot = screen.next();

                // crop
                Image window    = screenshot.crop(offset.X, screenshot.width, offset.Y, screenshot.height);
                Image tableList = window.crop(layout.TableList.X, layout.TableList.X + layout.TableList.Width,
                                              layout.TableList.Y, layout.TableList.Y + layout.TableList.Height);
                try
                {
                    List <LobbyTable> lobbyTables = lobbyIdentifier.identifyLobbyTables(tableList, offset);

                    // log
                    Log.Info("identified " + lobbyTables.Count + " joinable lobby tables");

                    // nothing found?
                    if (lobbyTables.Count == 0)
                    {
                        throw new Exception("identified 0 lobby tables, trying again");
                    }

                    return(lobbyTables);
                }
                catch (Exception ex)
                {
                    // handle error
                    ErrorHandler.ReportExceptionWithImage(ex, "lobby identifier error", tableList);

                    // sleep
                    Thread.Sleep(1000);

                    // focus lobby
                    FocusLobby(layout, screen);

                    continue;
                }
            }
            throw new Exception("cannot identify lobby table list");
        }
Example #2
0
        public static void Main(string[] args)
        {
            Thread.Sleep(10 * 1000);

            LobbyIdentifier identifier = new LobbyIdentifier();
            DeviceControl   device     = new Win32Control();
            Image           screenshot = new ScreenImageIterator(device).next();
            Point           offset     = PatternLocator.locateLobby(screenshot);
            LobbyLayout     layout     = new LobbyLayout();

            Image window    = screenshot.crop(offset.X, screenshot.width, offset.Y, screenshot.height);
            Image tableList = window.crop(layout.TableList.X, layout.TableList.X + layout.TableList.Width,
                                          layout.TableList.Y, layout.TableList.Y + layout.TableList.Height);
            List <LobbyTable> lobbyTables = identifier.identifyLobbyTables(tableList, offset);

            foreach (LobbyTable lobby in lobbyTables)
            {
                Console.WriteLine(lobby.ToString());
            }
        }
Example #3
0
        public List <TableContainer> OpenNewTables(Settings settings, ImageRenderer imageRenderer, TableFoundDelegate tableDelegate)
        {
            Log.Info("## scanning for lobby ##");

            // identifier
            LobbyIdentifier lobbyIdentifier = new LobbyIdentifier();

            // set renderer
            tableIdentifier.Renderer = imageRenderer;
            lobbyIdentifier.Renderer = imageRenderer;

            // screen
            Iterator <Image> screen = new ScreenImageIterator(deviceControl);
            LobbyLayout      layout = new LobbyLayout();

            // find lobby
            FocusLobby(layout, screen);
            Image screenshot  = screen.next();
            Point lobbyOffset = PatternLocator.locateLobby(screenshot);

            // loop until we got enough tables
            List <TableContainer> tables = new List <TableContainer>();

            while (knownTables.Count < settings.AutoLocateTablesNum)
            {
                // check for tables
                PressCheckOrFold(screenshot);

                // scan lobby
                List <LobbyTable> lobbyTables = IdentifyLobbyTables(lobbyIdentifier, layout, screen, lobbyOffset);

                // open tables?
                if (HasOpenTables(lobbyTables))
                {
                    // select table
                    LobbyTable bestTable = SelectBestTable(lobbyTables);

                    // render
                    if (imageRenderer != null)
                    {
                        imageRenderer.renderImage(ImageTools.rectImage(), new Point(bestTable.RelX, bestTable.RelY));
                    }

                    // open table
                    Log.Info("opening table " + bestTable.ToString() + " with score " + String.Format("{0:0.00}", bestTable.Score));
                    TableContainer container = OpenTable(bestTable, settings, screen, bestTable);
                    if (container != TABLE_ALREADY_JOINED && container != TABLE_NOT_FOUND && container != CANNOT_FIND_SEAT)
                    {
                        // add to known tables
                        tables.Add(container);
                        knownTables.Add(container);
                        Log.Info("added new table " + tables.Count);

                        // invoke delegate
                        if (tableDelegate != null)
                        {
                            tableDelegate(container);
                        }
                    }

                    // reselect lobby (otherwise automatically selected by pokerstars -> close table)
                    if (container == TABLE_NOT_FOUND || knownTables.Count > 0)
                    {
                        FocusLobby(layout, screen);
                        keyboard.pressPageUp(3);
                    }
                    // move up for "better" tables
                    else
                    {
                        keyboard.pressPageUp(2);
                        Thread.Sleep(100);
                    }
                }
                else
                {
                    // scroll
                    keyboard.pressPageDown();
                    Thread.Sleep(1000);
                }
            }

            // minimize lobby
            Thread.Sleep(1000);

            return(tables);
        }