Beispiel #1
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();
            }
        }
Beispiel #2
0
        public bool IsTableVisible(TableContainer container, Image image)
        {
            Image screenTopLeftCorner     = CropTableTopLeftCorner(image, new Point(0, 0));
            Image screenBottomRightCorner = CropTableBottomRightCorner(image, new Point(0, 0));
            bool  areBothCornersVisible   = ImageTools.match(screenTopLeftCorner, container.CornerTopLeft) &&
                                            ImageTools.match(screenBottomRightCorner, container.CornerBottomRight);

            return(areBothCornersVisible);
        }
Beispiel #3
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++;
            }
        }
Beispiel #4
0
 private void WaitForBlind(Controller controller, TableContainer container)
 {
     if (container.IsFastTable)
     {
         controller.PressWaitForBlind(container.Layout);
     }
     else
     {
         controller.PressAutoBlind(container.Layout);
     }
     container.WaitForBlindToClose();
 }
Beispiel #5
0
        public TableContainer LocateNewTable(Settings settings)
        {
            TableContainer foundTable = tableOpener.LocateNewTable(settings);

            // delegate (-> UI)
            if (TableFoundEvent != null)
            {
                TableFoundEvent(foundTable);
            }

            return(foundTable);
        }
Beispiel #6
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);
                }
            }
        }
Beispiel #7
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();
        }
Beispiel #8
0
 private void SitOut(Controller controller, TableContainer container)
 {
     controller.PressSitOut(container.Layout);
     container.SitOut();
 }
Beispiel #9
0
 private void CloseTable(TableContainer container, Controller controller)
 {
     Log.Info("closing " + (container.IsFastTable ? "fast" : "slow") + " table " + (container.Number + 1));
     controller.CloseTableWithEnter(container.Layout);
     container.Close();
 }
Beispiel #10
0
        public void ProcessTable(Settings settings,
                                 Image tableImage,
                                 TableRenderer renderer,
                                 Table table,
                                 TableContainer container,
                                 RuleEvaluator evaluator,
                                 RuleInterpreter interpreter,
                                 Controller controller,
                                 Replayer replayer,
                                 RandomClicker clicker,
                                 List <TableControl> controls)
        {
            // hand visible?
            if (table.Hand.Count != 0)
            {
                // identify situation
                Situation situation = SituationEvaluator.evaluateSituation(tableImage, table, controls, settings.BigBlind);

                // wait for blinds activatd or not enough players or money reached
                if (!container.IsWaitingForBlind && situation.Street == StreetTypes.Preflop)
                {
                    // override blinds?
                    if (waitForBlinds)
                    {
                        Log.Info("table " + (container.Number + 1) + " override blinds");
                        WaitForBlind(controller, container);
                    }
                    // out of players?
                    else if (table.IsOutOfPlayers)
                    {
                        Log.Info("table " + (container.Number + 1) + " ran out of players");
                        CloseTable(container, controller);
                        return;
                    }
                    // reached money?
                    else if (settings.CloseTableActivated && table.HasSeat && table.MyPlayer.HasMoney)
                    {
                        if (table.MyPlayer.Money > settings.CloseTableMoneyMax)
                        {
                            Log.Info("table " + (container.Number + 1) + " reached money limit " + table.MyPlayer.Money);
                            CloseTable(container, controller);
                            return;
                        }
                    }
                }

                // evaluate rule
                Rule rule = evaluator.findRule(situation.Street,
                                               situation.Hand,
                                               situation.Chance,
                                               situation.Opponents,
                                               situation.OpponentAction,
                                               situation.Position,
                                               table.MaxBet,
                                               table.Pot);
                // decision
                Decision decision = interpreter.interpret(table, rule.Decision);

                // render table
                Log.Debug("# rendering table");
                if (renderer != null)
                {
                    renderer.render(table, container.Layout, situation, rule, decision, controls);
                }

                // beep
                if (decision.DecisionType == Decision.Types.BET ||
                    decision.DecisionType == Decision.Types.CALL ||
                    decision.DecisionType == Decision.Types.RAISE)
                {
                    if (situation.Hand != HandTypes.None)
                    {
                        Beep(settings);
                        TextToSpeech.SayAsnc(settings, situation.Hand);
                    }
                }

                // random click on table
                if (RandomBool(0.05) && settings.AutoClick)
                {
                    Log.Debug("# auto click on table");
                    clicker.click(container.Layout);
                }

                // sit out
                if (!container.IsSittingOut && sitOutNextHand)
                {
                    SitOut(controller, container);
                }

                // press buttons
                Log.Debug("# press controls");
                Thread.Sleep(RandomInt(100, 500));
                controller.Handle(decision, container.Layout, controls);

                // random mouse moves
                if (RandomBool(0.05) && settings.AutoMoveMouse)
                {
                    Log.Debug("# auto move mouse");
                    Sleep(settings, RandomInt(100, 300));
                    AutoMoveMouse(controller.Mouse);
                }
                if (situation.Opponents > 2 && RandomBool(0.05) && settings.ReplayMouseMoves)
                {
                    Log.Debug("# replay mouse");
                    Sleep(settings, RandomInt(100, 300));
                    replayer.ReplayRandomShort();
                }
            }
            else
            {
                // render table
                Log.Debug("# rendering table");
                renderer.render(table, container.Layout);
            }
        }
Beispiel #11
0
        private TableContainer SeatPlayer(Point offset, Iterator <Image> screenIter, LobbyTable lobby)
        {
            TableLayout layout = new TableLayout9(offset);

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

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

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

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

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

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

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

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

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

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

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

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

                    // screen
                    screenshot = screenIter.next();

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

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

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

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

                    // is slow table
                    isFastTable = false;

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

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

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

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

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

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

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

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

                // container
                Image          cornerTopLeft     = CropTableTopLeftCorner(screenshot, offset);
                Image          cornerBottomRight = CropTableBottomRightCorner(screenshot, offset);
                TableContainer table             = new TableContainer(globalTableNumber++, cornerTopLeft, cornerBottomRight, layout, openSeat.Num, isFastTable, lobby);
                return(table);
            }
        }
Beispiel #12
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();
        }
Beispiel #13
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);
        }
Beispiel #14
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");
            }
        }