Exemplo n.º 1
0
        private TableContainer FocusTable(LobbyLayout layout, List <TableContainer> candidates, Point taskBarPosition)
        {
            Iterator <Image> screen = new ScreenImageIterator(deviceControl);
            int tries = 0;

            while (true)
            {
                // tries
                if (tries > 2)
                {
                    ErrorHandler.ReportException(new Exception("cannot focus table"), "focus table");
                    return(TABLE_NOT_FOUND);
                }

                // check for other window
                Image screenshot = screen.next();

                // press buttons
                if (PressCheckOrFold(screenshot))
                {
                    continue;
                }

                // click task bar
                int randomOff = (int)(random.NextDouble() * 3);
                mouse.Move(taskBarPosition.X + randomOff, taskBarPosition.Y + randomOff);
                Thread.Sleep(150);
                mouse.LeftClick();
                Thread.Sleep(350);

                // check for other window
                screenshot = screen.next();

                // check focus
                foreach (TableContainer table in candidates)
                {
                    if (IsTableVisible(table, CropTable(screenshot, table.Layout)))
                    {
                        return(table);
                    }
                }

                // move somewhere else
                mouse.Move(taskBarPosition.X - 100, taskBarPosition.Y - 50);
                Thread.Sleep(200 + tries * 100);

                // tries
                tries++;
            }
        }
Exemplo n.º 2
0
        public void SitIn()
        {
            // move mouse to safe location
            mouse.Move(10, deviceControl.DisplayHeight - 300);

            // minimize tables
            Iterator <Image> screen = new ScreenImageIterator(deviceControl);

            MinimizeAllTables();

            // focus tables
            List <TableContainer> tablesNotFocused = new List <TableContainer>(knownTables);
            int lastTaskBarPosition = 1;

            while (true)
            {
                // next
                List <Point> taskBarPositions = TaskBarPrograms(lobbyLayout, screen.next());

                // break
                if (lastTaskBarPosition == taskBarPositions.Count)
                {
                    break;
                }

                // icon
                Point taskBarPosition = taskBarPositions[lastTaskBarPosition];

                // focus
                TableContainer foundTable = FocusTable(lobbyLayout, tablesNotFocused, taskBarPosition);

                // process
                if (foundTable != TABLE_NOT_FOUND)
                {
                    // sit-in
                    Log.Info("table " + (foundTable.Number + 1) + " found -> sit-in");
                    tablesNotFocused.Remove(foundTable);
                    PressSitIn(foundTable, screen);

                    // next icon
                    lastTaskBarPosition++;
                }
                else
                {
                    // close if we cannot focus this table
                    Log.Error("table not found -> closing table");
                    CloseLastTable(taskBarPosition);
                    mouse.Move(taskBarPosition.X, taskBarPosition.Y - 300);
                }
            }
            // remove tables
            foreach (TableContainer table in tablesNotFocused)
            {
                Log.Error("removing offset with no associated table -> x=" + table.Layout.Offset.X + " y=" + table.Layout.Offset.Y);
                knownTables.Remove(table);
                table.Close();
            }
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            while (true)
            {
                for (int i = 0; i < 100; i++)
                {
                    if (i == 3)
                    {
                        break;
                    }
                }
            }


            List <TableContainer> containers = new List <TableContainer>();

            containers.Add(TableContainer.EmptyContainer());
            if (containers.Contains(TableContainer.EmptyContainer()))
            {
                Console.WriteLine("argh");
            }
            else
            {
                Console.WriteLine("ok");
            }

            Thread.Sleep(2000);
            Iterator <Image> screen = new ScreenImageIterator(new Win32Control());
            Image            s1     = screen.next();
            Image            s2     = screen.next();

            DateTime start = DateTime.Now;

            areImagesEqual(s1, s1);

            Console.WriteLine(DateTime.Now.Subtract(start).TotalMilliseconds / 1000);
            Console.ReadKey();
        }
Exemplo n.º 4
0
        public void SitOut()
        {
            // taskbar position and remove lobby
            Iterator <Image> screen           = new ScreenImageIterator(deviceControl);
            List <Point>     taskBarPositions = TaskBarPrograms(lobbyLayout, screen.next());

            taskBarPositions.RemoveAt(0);

            // tables
            List <TableContainer> tablesNotFocused = new List <TableContainer>(knownTables);

            // sit out
            foreach (Point position in taskBarPositions)
            {
                TableContainer table = FocusTable(new LobbyLayout(), tablesNotFocused, position);
                if (table != null)
                {
                    tablesNotFocused.Remove(table);
                    Controller.PressSitOut(mouse, table.Layout);
                }
            }
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            ImagesRenderer renderer = newImageRenderer();

            Iterator <Image>      imageIter      = new ScreenImageIterator(new Win32Control(), new Rectangle(100, 400, 80, 30));
            Image                 background     = imageIter.next();
            Iterator <Image>      deltaIter      = new DeltaImageAnalyzer(background, imageIter);
            IteratorProxy <Image> proxyDeltaIter = new IteratorProxy <Image>(deltaIter);

            proxyDeltaIter.handler += delegate(Image next)
            {
                setImage(renderer, toBitmap(next));
            };

            HashSet <HashImage>      hashImages   = new HashSet <HashImage>();
            Iterator <List <Image> > patitionIter = new ImageVerticalPartitioner(proxyDeltaIter);
            int count = 0;

            while (patitionIter.hasNext())
            {
                List <Image> images = patitionIter.next();
                foreach (Image image in images)
                {
                    if (!hasMinimumDimensions(image))
                    {
                        continue;
                    }
                    HashImage hash = new HashImage(image);
                    if (!hashImages.Contains(hash))
                    {
                        hashImages.Add(hash);
                        System.Drawing.Image bitmap = toBitmap(image);
                        addImage(renderer, bitmap);
                        saveBitmap("card", count++, bitmap);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void ValidateKnownTables()
        {
            // log
            Log.Info("checking known table offsets");

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

            // move mouse to safe location
            mouse.Move(10, deviceControl.DisplayHeight - RandomInt(300, 350));

            // focus tables
            List <TableContainer> tablesNotFocused = new List <TableContainer>(knownTables);
            int lastTaskBarPosition = 1;

            while (true)
            {
                // minimize tables
                MinimizeAllTables();

                // sleep
                Thread.Sleep(300);

                // next
                List <Point> taskBarPositions = TaskBarPrograms(lobbyLayout, screen.next());

                // break
                if (lastTaskBarPosition >= taskBarPositions.Count)
                {
                    break;
                }

                // icon
                Point taskBarPosition = taskBarPositions[lastTaskBarPosition];

                // focus
                TableContainer foundTable = FocusTable(lobbyLayout, tablesNotFocused, taskBarPosition);

                // process
                if (foundTable != TABLE_NOT_FOUND)
                {
                    // ## 1 : table found ##
                    // found
                    Log.Info("table " + (foundTable.Number + 1) + " found");
                    tablesNotFocused.Remove(foundTable);

                    // next icon
                    lastTaskBarPosition++;
                }
                else
                {
                    // ## 2 : table unknown but has taskbar icon ##
                    // close if we cannot focus this table
                    Log.Error("closing table -> no known offset found");
                    CloseLastTable(taskBarPosition);
                    Thread.Sleep(500);
                    keyboard.pressEnter();
                    Thread.Sleep(500);
                }

                // move mouse to safe location
                mouse.Move(taskBarPosition.X, deviceControl.DisplayHeight - RandomInt(300, 350));
            }

            // remove offsets with no associated table
            foreach (TableContainer table in tablesNotFocused)
            {
                // ## 3 : table offset with no taskbar icon ##
                Log.Error("removing offset with no associated table -> x=" + table.Layout.Offset.X + " y=" + table.Layout.Offset.Y);
                knownTables.Remove(table);
                table.Close();
            }

            // restore state
            MinimizeAllTables();
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public void StartPokerApplication(Settings settings)
        {
            Iterator <Image> screen = new ScreenImageIterator(deviceControl);
            int width  = deviceControl.DisplayWidth;
            int height = deviceControl.DisplayHeight;

            ThreadStart bootup = delegate()
            {
                // start pokerstars
                {
                    Log.Info("## starting poker application ##");
                    TextToSpeech.SayAsnc(settings, "starting poker application");

                    int tries = 0;
                    while (true)
                    {
                        // tries
                        tries++;
                        if (tries > 10)
                        {
                            throw new Exception("cannot open application, lobby not found");
                        }

                        // click
                        Log.Info("double click poker application icon");
                        mouse.Move(lobbyLayout.Icon.X, lobbyLayout.Icon.Y);
                        mouse.LeftClick();
                        Thread.Sleep(500);
                        keyboard.pressEnter();

                        // check
                        mouse.Move(300, 10);
                        Thread.Sleep(10000);
                        if (PatternLocator.isNotLoggedInLobbyVisible(screen.next()))
                        {
                            break;
                        }
                    }
                }

                // news
                {
                    Log.Info("checking for news window");
                    Thread.Sleep(4000);
                    int   xOff = (int)(width * .4), yOff = (int)(height * .5);
                    Image newsScreen = screen.next().crop(xOff, (int)(width * .8), yOff, (int)(height * .8));
                    Point newsClose  = PatternLocator.locateLobbyNewsPattern(newsScreen);
                    if (newsClose != Point.Empty)
                    {
                        mouse.MoveAndLeftClick(xOff + newsClose.X + 5, yOff + newsClose.Y + 5, 4, 4);
                    }
                }

                // login
                {
                    Thread.Sleep(2000);
                    Log.Info("pressing login");
                    int   xOff = (int)(width * .7), yOff = (int)(height * .6);
                    Image loginScreen = screen.next().crop(xOff, width, yOff, height);
                    Point login       = PatternLocator.locateLobbyLogin(loginScreen);
                    if (login != Point.Empty)
                    {
                        mouse.MoveAndLeftClick(xOff + login.X + 5, yOff + login.Y + 5, 10, 10);
                    }
                    else
                    {
                        throw new Exception("cannot find login");
                    }
                }

                // ok
                {
                    Thread.Sleep(3000);
                    Log.Info("pressing login ok");
                    int   xOff = (int)(width * .4), yOff = (int)(height * .4);
                    Image okScreen = screen.next().crop(xOff, (int)(width * .7), yOff, height);
                    Point ok       = PatternLocator.locateLobbyLoginOk(okScreen);
                    if (ok != Point.Empty)
                    {
                        mouse.MoveAndLeftClick(xOff + ok.X, yOff + ok.Y, 4, 4);
                    }
                    else
                    {
                        throw new Exception("cannot find login ok");
                    }
                }

                // news
                {
                    Log.Info("checking for news window");
                    Thread.Sleep(3000);
                    int   xOff = (int)(width * .4), yOff = (int)(height * .5);
                    Image newsScreen = screen.next().crop(xOff, (int)(width * .8), yOff, (int)(height * .8));
                    Point newsClose  = PatternLocator.locateLobbyNewsPattern(newsScreen);
                    if (newsClose != Point.Empty)
                    {
                        mouse.MoveAndLeftClick(xOff + newsClose.X + 5, yOff + newsClose.Y + 5, 4, 4);
                    }
                }

                // wait for layout (VIP status)
                {
                    Log.Info("waiting for layout (VIP status)");
                    Thread.Sleep(1000);
                }
            };

            // main logic
            for (int bootups = 0; bootups < 10; bootups++)
            {
                // boot
                bootup();

                // check network connection
                int tries = 0;
                while (true)
                {
                    // tries
                    tries++;
                    if (tries > 10)
                    {
                        Log.Error("poker application is not connected - restarting");
                        keyboard.pressAltF4();
                        break;
                    }

                    // check
                    Thread.Sleep(1000);
                    Image screenshot = screen.next();
                    int   xOff = (int)(width * .4), yOff = (int)(height * .4);
                    Image network = screen.next().crop(xOff, (int)(width * .6), yOff, (int)(height * .7));
                    if (!PatternLocator.isConnectingVisible(network))
                    {
                        return;
                    }
                }
            }

            // error
            throw new Exception("cannot start poker application");
        }
Exemplo n.º 9
0
        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");
            }
        }