private void ProcessPlayerCardActions(Bitmap screenshot, int seat, bool isHero)
        {
            /* Try to match player cards */
            List <Bitmap> playerCardImages   = new List <Bitmap>();
            ArrayList     playerCardsActions = colorMap.GetPlayerCardsActions(seat);

            foreach (String action in playerCardsActions)
            {
                Globals.Director.WriteDebug(" --- PlayerCardsActions: " + action);
                Rectangle actionRect = recognitionMap.GetRectangleFor(action);
                if (!actionRect.Equals(Rectangle.Empty))
                {
                    //Globals.Director.WriteDebug(" --- Found Rectangle for:: " + action);
                    playerCardImages.Add(ScreenshotTaker.Slice(screenshot, actionRect));
                }
                else
                {
                    Globals.Director.WriteDebug("Warning: could not find a rectangle for action " + action);
                }
            }

            //Globals.Director.WriteDebug("Matching player cards! ");

            //playerCardsActions
            CardList playerCards = matcher.MatchCards(playerCardImages,
                                                      false,
                                                      playerCardsActions,
                                                      table.MatchHistogramThreshold(),
                                                      table.MatchTemplateThreshold(),
                                                      table.AllowableMatchTemplateThreshold());

            if (playerCards != null && isHero)
            {
                Globals.Director.WriteDebug("Matched player cards! " + playerCards.ToString());
                handler.PlayerHandRecognized(playerCards);
            }
            else if (playerCards != null && !isHero)
            {
                Globals.Director.WriteDebug(" -- NOT hero cards. Seat " + seat + " Cards: " + playerCards.ToString());
                handler.VillainHandRecognized(playerCards, seat);
            }
            else
            {
                Globals.Director.WriteDebug(" --- SEAT: " + seat + " Did not find any matching player cards ");
            }

            // Dispose
            foreach (Bitmap image in playerCardImages)
            {
                if (image != null)
                {
                    image.Dispose();
                }
            }
        }
Beispiel #2
0
        public void BoardRecognized(CardList board)
        {
            Globals.Director.RunFromGUIThread((Action) delegate()
            {
                Globals.Director.WriteDebug(WRITE_DEBUG, "\n\t ~~~ BoardRecognized " + board.ToString());
                if (Game == PokerGame.Holdem && DisplayWindow != null)
                {
                    ((HoldemTableDisplayWindow)DisplayWindow).DisplayBoard(board);
                }
            }, true);

            Globals.Director.WriteDebug(WRITE_DEBUG, "\n\t ~~~ Board Count " + board.ToString() + " " + board.Count);

            //TODO - update the state of the Table
            if (board.Count == 5)
            {
                Board finalBoard = new HoldemBoard(board);
                handHistoryParser_FinalBoardAvailable(finalBoard);
            }
        }
Beispiel #3
0
 /* Visual Recognition Manager handlers */
 public void PlayerHandRecognized(CardList playerCards)
 {
     Globals.Director.RunFromGUIThread((Action) delegate()
     {
         Globals.Director.WriteDebug(WRITE_DEBUG, "\n\t ~~~ PlayerHandRecognized " + playerCards.ToString());
         if (DisplayWindow != null)
         {
             DisplayWindow.DisplayPlayerHand(playerCards);
         }
     }, true);
     //TODO - update the state of the Table
 }
        void timedScreenshotTaker_ScreenshotTaken(Bitmap screenshot)
        {
            UpdateCardMatchDialogSpawnLocation();

            /* This code would resize the map and recompute the data in it,
             * but we don't use this approach anymore. */
            //recognitionMap.AdjustToSize(screenshot.Size);

            /* Instead if the screenshot we took differs in size from the map at our disposal
             * we resize the window and retake the screenshot */
            if (!screenshot.Size.Equals(recognitionMap.OriginalMapSize))
            {
                Trace.WriteLine(String.Format("Screenshot size ({0}x{1}) differs from our map image ({2}x{3}), resizing window...",
                                              screenshot.Size.Width, screenshot.Size.Height, recognitionMap.OriginalMapSize.Width, recognitionMap.OriginalMapSize.Height));

                Size winSize = tableWindow.Size;

                Size difference = new Size(screenshot.Size.Width - recognitionMap.OriginalMapSize.Width,
                                           screenshot.Size.Height - recognitionMap.OriginalMapSize.Height);

                Size newSize = winSize - difference;

                tableWindow.Resize(newSize, true);

                return; // At next iteration this code should not be executed because sizes will be the same, unless the player resizes the window
            }

            // If we don't know where the player is seated, we don't need to process any further
            if (table.CurrentHeroSeat == 0)
            {
                return;
            }

            /* Try to match player cards */
            List <Bitmap> playerCardImages   = new List <Bitmap>();
            ArrayList     playerCardsActions = colorMap.GetPlayerCardsActions(table.CurrentHeroSeat);

            foreach (String action in playerCardsActions)
            {
                Rectangle actionRect = recognitionMap.GetRectangleFor(action);
                if (!actionRect.Equals(Rectangle.Empty))
                {
                    playerCardImages.Add(ScreenshotTaker.Slice(screenshot, actionRect));
                }
                else
                {
                    Trace.WriteLine("Warning: could not find a rectangle for action " + action);
                }
            }

            CardList playerCards = matcher.MatchCards(playerCardImages, false);

            if (playerCards != null)
            {
                Trace.WriteLine("Matched player cards! " + playerCards.ToString());
                handler.PlayerHandRecognized(playerCards);
            }

            // Dispose
            foreach (Bitmap image in playerCardImages)
            {
                if (image != null)
                {
                    image.Dispose();
                }
            }

            /* If community cards are supported, try to match them */
            if (colorMap.SupportsCommunityCards)
            {
                List <Bitmap> communityCardImages   = new List <Bitmap>();
                ArrayList     communityCardsActions = colorMap.GetCommunityCardsActions();

                foreach (String action in communityCardsActions)
                {
                    Rectangle actionRect = recognitionMap.GetRectangleFor(action);
                    if (!actionRect.Equals(Rectangle.Empty))
                    {
                        communityCardImages.Add(ScreenshotTaker.Slice(screenshot, actionRect));
                    }
                    else
                    {
                        Trace.WriteLine("Warning: could not find a rectangle for action " + action);
                    }
                }

                // We try to identify as many cards as possible
                CardList communityCards = matcher.MatchCards(communityCardImages, true);
                if (communityCards != null && communityCards.Count > 0)
                {
                    Trace.WriteLine("Matched board cards! " + communityCards.ToString());
                    handler.BoardRecognized(communityCards);
                }

                // Dispose
                foreach (Bitmap image in communityCardImages)
                {
                    if (image != null)
                    {
                        image.Dispose();
                    }
                }
            }

            // Dispose screenshot
            if (screenshot != null)
            {
                screenshot.Dispose();
            }
        }