Exemple #1
0
        public static void Main(string[] args)
        {
            Iterator <Image> screen;

            if (USE_SCREEN)
            {
                // wait
                Log.Info("waiting ...");
                Thread.Sleep(5000);

                // full screen
                Console.WriteLine("## scanning for table ##");
                Image fullScreen = new ScreenImageIterator(new Win32Control()).next();
                Point offset     = PatternLocator.locateTable(fullScreen);
                Console.WriteLine("table found at x=" + offset.X + " y=" + offset.Y);

                // desk
                screen = new ScreenImageIterator(new Win32Control(), new Rectangle(offset.X, offset.Y, new TableLayout9().Size.Width, new TableLayout9().Size.Height));
                screen = new WaitDeltaImageIterator(screen);
            }
            else
            {
                screen = new MockOneImageIterator(toImage(new Bitmap("test/table_highlight.png")));
            }

            // identifier
            TableIdentifier tableIdentifier = new TableIdentifier(new TableLayout9());

            tableIdentifier.RenderImageEvent += delegate(Image image, Point point)
            {
                renderer.renderImage(image, point);
            };

            // loop
            while (screen.hasNext())
            {
                // start
                Console.WriteLine("## iteration -> start ##");
                DateTime start = DateTime.Now;

                // clear
                renderer.clearImages();

                // table
                Console.WriteLine("# next table image #");
                Image tableImage = screen.next();
                renderer.renderImage(tableImage, 0, 0);

                // identify table
                Table table = tableIdentifier.identifyTable(tableImage, TableIdentifier.PlayerInfoEnum.BOTH, -1, 0);

                // render table
                Console.WriteLine("# rendering table");
                renderer.render(table, tableIdentifier.Layout);

                // end
                double time = DateTime.Now.Subtract(start).TotalMilliseconds;
                Console.WriteLine("## iteration -> end -> " + time + " ms ##");
            }
        }
Exemple #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();
            }
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            Log.SetLevel(Log.Level.FINEST);

            // patterns
            List <CardPattern> patterns = CardReader.readCardsFromResources();

            Console.WriteLine("read " + patterns.Count + " candidate patterns");

            // renderer
            ImagesRenderer renderer = newImageRenderer();

            // iterator
            Iterator <Image> wait;

            if (USE_SCREEN)
            {
                Thread.Sleep(10);
                TableContainer   table  = new BotAppLogic(new Win32Control()).LocateNewTable(new Settings());
                Rectangle        rect   = new Rectangle(table.Layout.Offset.X, table.Layout.Offset.Y, table.Layout.Size.Width, table.Layout.Size.Height);
                Iterator <Image> screen = new ScreenImageIterator(new Win32Control(), rect);
                wait = new WaitDeltaImageIterator(screen);
            }
            else
            {
                wait = new MockIterator(toImage(new Bitmap("test/table_no_middle_button.png")));
            }

            // proxy
            IteratorProxy <Image> proxyIter = new IteratorProxy <Image>(wait);

            proxyIter.handler += delegate(Image next)
            {
                setImage(renderer, toBitmap(next));
            };
            Console.WriteLine("initialized iterator");

            // identifier
            CardStrategy           strategy   = new CardStrategyFast(patterns, new TableLayout9());
            CardIdentifierIterator identifier = new CardIdentifierIterator(proxyIter,
                                                                           strategy.identifyRegions,
                                                                           strategy.identifyCards);

            // go
            while (identifier.hasNext())
            {
                DateTime    start = DateTime.Now;
                List <Card> cards = identifier.next();
                setText(renderer, toText(cards));
                Console.WriteLine("iteration took " + DateTime.Now.Subtract(start).TotalSeconds + "s");
                Console.ReadKey();
            }
        }
        public static void Main(string[] args)
        {
            Log.SetLevel(Log.Level.FINE);

            // patterns
            List <CardPattern> patterns = CardReader.readCardsFromResources();

            Console.WriteLine("read " + patterns.Count + " candidate patterns");

            // renderer
            ImagesRenderer renderer = newImageRenderer();

            // iterator
            Iterator <Image> wait;

            if (USE_SCREEN)
            {
                Iterator <Image> screen = new ScreenImageIterator(new Win32Control(), new Rectangle(400, 400, 300, 80));
                wait = new WaitDeltaImageIterator(screen);
            }
            else
            {
                wait = new MockIterator(toImage(new Bitmap("test/cards_56.png")));
            }

            Iterator <Image> low = new ReduceColorIterator(wait, new ColorReducers.Card());

            // proxy
            IteratorProxy <Image> proxyIter = new IteratorProxy <Image>(low);

            proxyIter.handler += delegate(Image next)
            {
                setImage(renderer, toBitmap(next));
            };
            Console.WriteLine("initialized iterator");

            // identifier
            CardStrategy           strategy   = new CardStrategySlow(patterns);
            CardIdentifierIterator identifier = new CardIdentifierIterator(proxyIter,
                                                                           strategy.identifyRegions,
                                                                           strategy.identifyCards);

            // go
            while (identifier.hasNext())
            {
                DateTime    start = DateTime.Now;
                List <Card> cards = identifier.next();
                setText(renderer, toText(cards));
                Console.WriteLine("iteration took " + DateTime.Now.Subtract(start).TotalSeconds + "s");
            }
        }
Exemple #5
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++;
            }
        }
Exemple #6
0
        public void StopPokerApplication(Settings settings)
        {
            Log.Info("## stopping poker application ##");
            TextToSpeech.SayAsnc(settings, "stopping poker application");

            // select lobby
            {
                Iterator <Image> screen = new ScreenImageIterator(deviceControl);
                FocusLobby(lobbyLayout, screen);
            }

            // close window
            {
                Thread.Sleep(2000);
                keyboard.pressAltF4AndEnter();
            }
        }
        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());
            }
        }
Exemple #8
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);
                }
            }
        }
Exemple #9
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);
                    }
                }
            }
        }
Exemple #10
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();
        }
Exemple #11
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);
        }
Exemple #12
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");
            }
        }
Exemple #13
0
        public static void Main(string[] args)
        {
            Iterator <Image> screen;

            if (USE_SCREEN)
            {
                // wait
                Log.Info("waiting ...");
                Thread.Sleep(5000);

                // full screen
                Console.WriteLine("## scanning for table ##");
                Image fullScreen = new ScreenImageIterator(new Win32Control()).next();
                Point offset     = PatternLocator.locateTable(fullScreen);
                Console.WriteLine("table found at x=" + offset.X + " y=" + offset.Y);

                // desk
                screen = new ScreenImageIterator(new Win32Control(), new Rectangle(offset.X, offset.Y, new TableLayout9().Size.Width, new TableLayout9().Size.Height));
                screen = new WaitDeltaImageIterator(screen);
            }
            else
            {
                screen = new MockOneImageIterator(toImage(new Bitmap("test/seatsopen_cropped.bmp")));
            }

            // renderer
            ImagesRenderer renderer = newImageRenderer();

            // identifier
            TableIdentifier tableIdentifier = new TableIdentifier(new TableLayout9());

            // pattern
            Log.Debug("reading seat pattern");
            Stream stream  = AssemblyTools.getAssemblyStream("open_seat.png");
            Bitmap bitmap  = Bitmap.FromStream(stream) as Bitmap;
            Image  pattern = toImage(bitmap);

            pattern = new ColorReducers.SeatOpen().reduceColors(pattern);
            stream.Close();

            // loop
            while (screen.hasNext())
            {
                // start
                Console.WriteLine("## iteration -> start ##");
                DateTime start = DateTime.Now;

                // table
                Console.WriteLine("# next table image #");
                Image tableImage = screen.next();

                // reduce
                ColorReducer reducer = new ColorReducers.SeatOpen();

                // rnder
                setImage(renderer, toBitmap(tableImage));

                // identify seats
                List <Point> seats = new List <Point>();
                Log.Fine("scanning lines ...");
                DateTime seatsStart = DateTime.Now;
                foreach (Rectangle seat in new TableLayout9().Seats)
                {
                    bool isOpen = IsOpen(reducer, seat, pattern, tableImage, 5);
                }
                Console.WriteLine("## seat scan -> " + DateTime.Now.Subtract(seatsStart).TotalMilliseconds + " ms ##");

                // print
                foreach (Point seat in seats)
                {
                    Console.WriteLine(seat);
                }

                // end
                double time = DateTime.Now.Subtract(start).TotalMilliseconds;
                Console.WriteLine("## iteration -> end -> " + time + " ms ##");
            }
        }
        public static void Main(string[] args)
        {
            Log.SetLevel(Log.Level.FINEST);
            Iterator <Image> screenIter;

            if (USE_SCREEN)
            {
                // wait
                Log.Info("waiting ...");
                Thread.Sleep(5000);

                // full screen
                Console.WriteLine("## scanning for lobby ##");
                Image fullScreen = new ScreenImageIterator(new Win32Control()).next();
                Point offset     = PatternLocator.locateLobby(fullScreen);
                Console.WriteLine("lobby found at x=" + offset.X + " y=" + offset.Y);

                // desk
                LobbyLayout layout = new LobbyLayout();
                screenIter = new ScreenImageIterator(new Win32Control(), new Rectangle(offset.X + layout.TableList.X, offset.Y + layout.TableList.Y, layout.TableList.Width, layout.TableList.Height));
            }
            else
            {
                screenIter = new MockOneImageIterator(toImage(new Bitmap("test/lobby1.bmp")));
            }

            // screen + reduce + invert
            Iterator <Image> reduceIter  = new ReduceColorIterator(screenIter, new ColorReducers.LobbyChars());
            Iterator <Image> replaceIter = new ReplaceColorIterator(reduceIter, Color.White, Color.Transparent);

            // proxy
            ImagesRenderer        renderer  = newImageRenderer();
            IteratorProxy <Image> proxyIter = new IteratorProxy <Image>(replaceIter);
            ColorReplacer         replacer  = new ColorReplacer(Color.Transparent, Color.Cyan);

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

            // partition + decompose + crop
            Iterator <List <List <Image> > > patitionIter = new ImageHoriPartitionIterator(proxyIter);
            Iterator <List <List <Image> > > cropIter     = new CropImageIterator(patitionIter);

            // patterns
            List <CharPattern> patterns   = CharReader.readCharsFromResourcesLobby();
            CharIdentifier     identifier = new CharIdentifier(patterns);

            // identify
            int count = 0;

            while (cropIter.hasNext())
            {
                List <List <Image> > lines = cropIter.next();
                // line
                foreach (List <Image> line in lines)
                {
                    // chars
                    String textLine = "";
                    foreach (Image chars in line)
                    {
                        List <Image> combos = CharDecomposer.decompose(chars, 0);
                        foreach (Image chr in combos)
                        {
                            Image character = ImageCropper.crop(chr);
                            textLine += identifyChars(identifier, character, ref count);
                        }
                    }

                    Console.WriteLine(textLine);
                }
            }
        }
Exemple #15
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();
        }
Exemple #16
0
        public static void Main(string[] args)
        {
            Log.SetLevel(Log.Level.FINEST);
            Iterator <Image> screenIter;
            LobbyLayout      layout = new LobbyLayout();
            Point            offset;

            if (USE_SCREEN)
            {
                // wait
                Log.Info("waiting ...");
                Thread.Sleep(3000);

                // full screen
                Console.WriteLine("## scanning for lobby ##");
                Image fullScreen = new ScreenImageIterator(new Win32Control()).next();
                offset = PatternLocator.locateLobby(fullScreen);
                Console.WriteLine("lobby found at x=" + offset.X + " y=" + offset.Y);

                // lobby
                screenIter = new ScreenImageIterator(new Win32Control(), new Point(offset.X, offset.Y));
                screenIter = new WaitDeltaImageIterator(screenIter);
            }
            else
            {
                offset     = new Point(0, 0);
                screenIter = new MockOneImageIterator(toImage(new Bitmap("test/lobby1.bmp")));
            }

            // screen + reduce + invert
            ColorReducer  reducer       = new ColorReducers.LobbyChars();
            ColorReducer  reducerJoined = new ColorReducers.LobbyCharsJoined();
            ColorReplacer replacer      = new ColorReplacer(Color.White, Color.Transparent);


            // renderer
            ImagesRenderer renderer      = newImageRenderer();
            ColorReplacer  replacerTrans = new ColorReplacer(Color.Transparent, Color.Cyan);

            // patterns
            List <CharPattern> patterns   = CharReader.readCharsFromResourcesLobby();
            CharIdentifier     identifier = new CharIdentifier(patterns);

            // identify
            while (screenIter.hasNext())
            {
                // rows
                List <LobbyTable> rows = new List <LobbyTable>();

                // image
                Image screen = screenIter.next();

                // list
                Image tableList = screen.crop(layout.TableList.X, layout.TableList.X + layout.TableList.Width,
                                              layout.TableList.Y, layout.TableList.Y + layout.TableList.Height);

                // identify
                List <ValueWithY> playerCounts = identifyValues(tableList, layout.PlayersCountX,
                                                                layout.PlayersCountX + layout.PlayersCountW, tableList.height,
                                                                reducer, replacer, identifier, renderer);
                List <ValueWithY> potSizes = identifyValues(tableList, layout.PotX,
                                                            layout.PotX + layout.PotW, tableList.height,
                                                            reducer, replacer, identifier, renderer);
                List <ValueWithY> flops = identifyValues(tableList, layout.FlopsX,
                                                         layout.FlopsX + layout.FlopsW, tableList.height,
                                                         reducer, replacer, identifier, renderer);

                List <LobbyTable> tables = new List <LobbyTable>();
                for (int i = 0; i < playerCounts.Count; i++)
                {
                    // location
                    int x = offset.X + layout.TableList.X + layout.TableList.Width / 2;
                    int y = offset.Y + layout.TableList.Y + playerCounts[i].Y;

                    // cell
                    int   celly  = playerCounts[i].Y;
                    int   cellx  = layout.PlayersCountX;
                    Image cell   = tableList.crop(cellx, cellx + layout.PlayersCountW, celly, celly + layout.CellHeight);
                    bool  joined = ContainsJoinedColor(cell, reducerJoined, renderer);

                    // table
                    tables.Add(new LobbyTable(i + 1, (int)playerCounts[i].Value, potSizes[i].Value, (int)flops[i].Value, x, y, offset.X, offset.Y, joined));
                }

                // print
                foreach (LobbyTable table in tables)
                {
                    Console.WriteLine(table.ToString());
                }

                // wait
                Console.ReadKey();
            }
        }
Exemple #17
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");
        }