Ejemplo n.º 1
0
        private static bool IsImBackVisible(TableLayout layout, Image table)
        {
            Image imBackImage = table.crop(layout.ImBack.X, layout.ImBack.X + layout.ImBack.Width,
                                           layout.ImBack.Y, layout.ImBack.Y + layout.ImBack.Height);

            return(PatternLocator.isImBackVisible(imBackImage));
        }
Ejemplo n.º 2
0
        private static bool IsCheckOrFoldMsgBoxVisible(TableLayout layout, Image table)
        {
            Image msgboxImage = table.crop(layout.CheckOrFold.X, layout.CheckOrFold.X + layout.CheckOrFold.Width,
                                           layout.CheckOrFold.Y, layout.CheckOrFold.Y + layout.CheckOrFold.Height);

            return(PatternLocator.isCheckOrFoldMsgBoxVisible(msgboxImage));
        }
Ejemplo n.º 3
0
        private static bool IsPostBlindVisible(TableLayout layout, Image table)
        {
            Image postBlindImage = table.crop(layout.PostBlind.X, layout.PostBlind.X + layout.PostBlind.Width,
                                              layout.PostBlind.Y, layout.PostBlind.Y + layout.PostBlind.Height);

            return(PatternLocator.isPostBlindVisible(postBlindImage));
        }
Ejemplo n.º 4
0
        private void FocusLobby(LobbyLayout layout, Iterator <Image> screen)
        {
            Log.Info("selecting lobby");
            for (int tries = 0; tries < 5; tries++)
            {
                // check
                {
                    Image lobbyCorner = screen.next().crop(0, 300, 0, 300);
                    if (PatternLocator.isLoggedInLobbyVisible(lobbyCorner))
                    {
                        return;
                    }
                }

                // focus
                {
                    Point taskbarLobby = TaskBarLobby(layout);
                    mouse.MoveAndLeftClick(taskbarLobby.X, taskbarLobby.Y, 10, 10);
                    Thread.Sleep(700);
                }

                // check
                {
                    Image lobbyCorner = screen.next().crop(0, 300, 0, 300);
                    if (PatternLocator.isLoggedInLobbyVisible(lobbyCorner))
                    {
                        return;
                    }
                }
            }
            throw new Exception("cannot focus lobby");
        }
Ejemplo n.º 5
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 ##");
            }
        }
Ejemplo n.º 6
0
        private static bool YouHaveBeenRemovedVisible(TableLayout layout, Image table)
        {
            Point offset = layout.Offset;
            Image msgbox = table.crop(layout.YouHaveBeenRemoved.X, layout.YouHaveBeenRemoved.X + layout.YouHaveBeenRemoved.Width,
                                      layout.YouHaveBeenRemoved.Y, layout.YouHaveBeenRemoved.Y + layout.YouHaveBeenRemoved.Height);

            return(PatternLocator.locateError(msgbox));
        }
Ejemplo n.º 7
0
        private static bool IsAutoPostBlindsVisible(TableLayout layout, Image screenshot)
        {
            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);

            return(PatternLocator.locateAutoPostBlinds(blindsImage));
        }
Ejemplo n.º 8
0
        private static bool IsSitOutVisible(TableLayout layout, Image screenshot)
        {
            Image tableImage  = CropTable(screenshot, layout);
            Image sitOutImage = tableImage.crop(layout.SitOutPattern.X, layout.SitOutPattern.X + layout.SitOutPattern.Width,
                                                layout.SitOutPattern.Y, layout.SitOutPattern.Y + layout.SitOutPattern.Height);

            return(PatternLocator.isSitOutVisible(sitOutImage));
        }
Ejemplo n.º 9
0
        private bool YouHaveJustLeftThisTable(TableLayout layout, Image screen)
        {
            Point offset = layout.Offset;
            Image table  = CropTable(screen, layout);
            Image msgbox = table.crop(layout.YouHaveJustLeftThisTable.X, layout.YouHaveJustLeftThisTable.X + layout.YouHaveJustLeftThisTable.Width,
                                      layout.YouHaveJustLeftThisTable.Y, layout.YouHaveJustLeftThisTable.Y + layout.YouHaveJustLeftThisTable.Height);

            return(PatternLocator.locateError(msgbox));
        }
Ejemplo n.º 10
0
        private bool IsSeatOccupied(TableLayout layout, Image screen)
        {
            Point offset = layout.Offset;
            Image table  = CropTable(screen, layout);
            Image msgbox = table.crop(layout.MessageBox.X, layout.MessageBox.X + layout.MessageBox.Width,
                                      layout.MessageBox.Y, layout.MessageBox.Y + layout.MessageBox.Height);

            return(PatternLocator.locateError(msgbox));
        }
Ejemplo n.º 11
0
        private static bool IsBuyInVisible(TableLayout layout, Image screen)
        {
            Point offset = layout.Offset;
            Image table  = CropTable(screen, layout);
            Image buyIn  = table.crop(layout.BuyInIcon.X, layout.BuyInIcon.X + layout.BuyInIcon.Width,
                                      layout.BuyInIcon.Y, layout.BuyInIcon.Y + layout.BuyInIcon.Height);

            return(PatternLocator.isBuyInVisible(buyIn));
        }
Ejemplo n.º 12
0
        private void PressSitIn(TableContainer table, Iterator <Image> screen)
        {
            int tries = 0;

            while (true)
            {
                // move mouse
                int xOff = RandomInt(15, table.Layout.SitOutClick.Width);
                mouse.Move(table.Layout.Offset.X + table.Layout.SitOutClick.X + xOff, table.Layout.Offset.Y + table.Layout.SitOutClick.Y);

                // shot
                Image shot      = screen.next();
                bool  isChecked = PatternLocator.isSitOutBoxChecked(CropCheckImage(shot, table.Layout));

                // sanity
                if (tries == 0 && !isChecked)
                {
                    Log.Error("Sit-Out box is not checked");
                }

                // press buttons
                if (PressCheckOrFold(shot))
                {
                    mouse.Move(table.Layout.Offset.X + table.Layout.SitOutClick.X, table.Layout.Offset.Y + table.Layout.SitOutClick.Y);
                    MinimizeAllTables();
                    continue;
                }

                // sit-in
                if (isChecked)
                {
                    // click
                    mouse.LeftClick();

                    // double check
                    bool isUnchecked = PatternLocator.isSitOutBoxUnchecked(CropCheckImage(screen.next(), table.Layout));

                    // continue
                    if (isUnchecked)
                    {
                        table.SitIn();
                        break;
                    }
                }

                // tries
                if (tries > 5)
                {
                    ErrorHandler.ReportExceptionWithImage(new Exception("cannot sit in on table"), "sit-in", shot);
                    table.Close();
                    break;
                }
                tries++;
            }
        }
Ejemplo n.º 13
0
        private List <Point> TaskBarPrograms(LobbyLayout lobby, Image screenshot)
        {
            // screenshot
            Log.Debug("device control display dimensions {W=" + deviceControl.DisplayWidth + ",H="
                      + deviceControl.DisplayHeight + "} crop area {X=" + lobby.Taskbar.X + ",Y=" + lobby.Taskbar.Y + "}");
            Image taskbar = screenshot.crop(lobby.Taskbar.X, deviceControl.DisplayWidth,
                                            lobby.Taskbar.Y, deviceControl.DisplayHeight - 2);
            List <Point> icons = PatternLocator.locateTaskBarPrograms(taskbar, lobby.Taskbar.X, lobby.Taskbar.Y);

            Log.Info("found " + icons.Count + " taskbar icons");
            return(icons);
        }
Ejemplo n.º 14
0
        public static void Main(string[] args)
        {
            Image bar = toImage(new Bitmap("test/taskbar_rows.png"));

            bar = bar.crop(110, 1190, 730, 785);

            DateTime start1 = DateTime.Now;

            Console.WriteLine(PatternLocator.locateTaskBarPrograms(bar, 0, 0).Count);
            Console.WriteLine(DateTime.Now.Subtract(start1).TotalMilliseconds);

            DateTime start2 = DateTime.Now;

            Console.WriteLine(PatternLocator.locateTaskBarPrograms(bar, 0, 0).Count);
            Console.WriteLine(DateTime.Now.Subtract(start2).TotalMilliseconds);

            Console.ReadKey();
        }
Ejemplo n.º 15
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());
            }
        }
Ejemplo n.º 16
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");
            }
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 18
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();
            }
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        private TableContainer OpenTable(LobbyTable table, Settings settings, Iterator <Image> screen, LobbyTable lobby)
        {
            // count programs
            List <Point> taskBarBefore = TaskBarPrograms(lobbyLayout, screen.next());

            // move mouse to row
            mouse.MoveAndLeftClick(table.AbsX, table.AbsY + 4, 10, 2);
            keyboard.pressEnter();
            Thread.Sleep(450);

            // locate table
            Point tableOffset = Point.Empty;
            Image screenshot  = screen.next();
            int   tries       = 0;

            while (true)
            {
                // find
                tableOffset = PatternLocator.locateUnknownTable(screenshot, Offsets(knownTables), new TableLayout9());
                if (tableOffset != Point.Empty)
                {
                    // found table
                    break;
                }
                else if (tries++ > 4)
                {
                    // cannot locate
                    break;
                }
                else
                {
                    // next try
                    Thread.Sleep(500);
                    screenshot = screen.next();
                }
            }

            // not found?
            if (tableOffset == Point.Empty)
            {
                // safe location
                mouse.Move(500, deviceControl.DisplayHeight - 300);

                // close if not found (but is actually there)
                List <Point> taskBarAfter = TaskBarPrograms(lobbyLayout, screen.next());
                if (taskBarAfter.Count > taskBarBefore.Count)
                {
                    // log
                    Log.Info("table not found - validating known offsets");

                    // check known offsets
                    ValidateKnownTables();

                    // error -> table not found
                    ErrorHandler.ReportExceptionWithImage(new Exception("table not found"), "open table failed", screenshot);
                    return(TABLE_NOT_FOUND);
                }
                else
                {
                    // error -> table already joined
                    ErrorHandler.ReportExceptionWithImage(new Exception("table already joined"), "open table failed", screenshot);
                    return(TABLE_ALREADY_JOINED);
                }
            }

            // check for 'you have just left this table'
            if (YouHaveJustLeftThisTable(new TableLayout9(tableOffset), screenshot))
            {
                Log.Info("'you have just left this table' is visible -> closing table");
                keyboard.pressEnter();
                Thread.Sleep(500);
                CloseLastTable(screen);
                return(TABLE_NOT_FOUND);
            }

            // find open seat
            Thread.Sleep(200);
            return(SeatPlayer(tableOffset, screen, lobby));
        }
Ejemplo n.º 21
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 ##");
            }
        }
Ejemplo n.º 22
0
        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);
                }
            }
        }