Example #1
0
        void handHistoryParser_FoundTableMaxSeatingCapacity(int maxSeatingCapacity)
        {
            this.maxSeatingCapacity = maxSeatingCapacity;

            // Usually the max seating capacity is the last piece of information we need in order to create a visual recognition manager

            // Attempt to create the visual recognition manager
            if (IsVisualRecognitionPossible())
            {
                if (visualRecognitionManager == null)
                {
                    visualRecognitionManager = new VisualRecognitionManager(this, this);
                }

                // TODO REMOVE

                CardList cards = new CardList();
                //cards.AddCard(new Card(CardFace.Six, CardSuit.Spades));
                //cards.AddCard(new Card(CardFace.Eight, CardSuit.Spades));
                cards.AddCard(new Card(CardFace.Ace, CardSuit.Clubs));
                cards.AddCard(new Card(CardFace.Seven, CardSuit.Hearts));

                PlayerHandRecognized(cards);

                CardList board = new CardList();
                cards.AddCard(new Card(CardFace.Ace, CardSuit.Hearts));
                cards.AddCard(new Card(CardFace.Seven, CardSuit.Spades));
                cards.AddCard(new Card(CardFace.Six, CardSuit.Hearts));

                BoardRecognized(board);

                Globals.Director.RunFromGUIThread((Action) delegate()
                {
                    if (displayWindow != null)
                    {
                        displayWindow.SetVisualRecognitionSupported(true);
                    }
                }, false);
            }
            else
            {
                Trace.WriteLine("Visual recognition is not supported for " + this.ToString());

                Globals.Director.RunFromGUIThread((Action) delegate()
                {
                    if (displayWindow != null)
                    {
                        displayWindow.SetVisualRecognitionSupported(false);
                    }
                }, false);
            }
        }
Example #2
0
        /* Tries to match a set of bitmaps into a card list.
         * @param allowPartialMatch If any card fails to match, the operation is aborted and the results obtained so far are returned
         *  (but they might be incomplete). If this parameter is set to false, null is returned on failure. */
        public CardList MatchCards(List <Bitmap> images, bool allowPartialMatch)
        {
            if (images.Count == 0)
            {
                return(null);
            }

            CardList result = new CardList();

            foreach (Bitmap image in images)
            {
                Card card = MatchCard(image);
                if (card != null)
                {
                    result.AddCard(card);
                }
                else if (allowPartialMatch)
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }

            return(result);
        }
Example #3
0
 public void AddCardToList(Card c)
 {
     if (cardListToDisplay != null)
     {
         cardListToDisplay.AddCard(c);
         ReloadGraphics();
     }
 }
Example #4
0
        /* Perform a deep copy */
        public object Clone()
        {
            CardList cardList = (CardList)this.MemberwiseClone();

            cardList.cards = new List <Card>(5);

            foreach (Card c in cards)
            {
                cardList.AddCard((Card)c.Clone());
            }
            return(cardList);
        }
Example #5
0
        /* Tries to match a set of bitmaps into a card list.
         * @param allowPartialMatch If any card fails to match, the operation is aborted and the results obtained so far are returned
         *  (but they might be incomplete). If this parameter is set to false, null is returned on failure. */
        public CardList MatchCards(List <Bitmap> images, bool allowPartialMatch, ArrayList actionMap,
                                   double perfectMatchHistogramThreshold = 0,
                                   double possibleMatchTemplateThreshold = 0,
                                   double allowableSimilarityThreshold   = 0)
        {
            if (images.Count == 0)
            {
                return(null);
            }

            CardList result = new CardList();

            int i = 0;

            foreach (Bitmap image in images)
            {
                Globals.Director.WriteDebug(WRITE_DEBUG, " --- action: " + actionMap[i].ToString());
                Card card = MatchCard(image, actionMap[i].ToString(),
                                      perfectMatchHistogramThreshold,
                                      possibleMatchTemplateThreshold,
                                      allowableSimilarityThreshold);
                ++i;
                if (card != null)
                {
                    result.AddCard(card);
                }
                else if (allowPartialMatch)
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }

            return(result);
        }
Example #6
0
        /* Tries to match a set of bitmaps into a card list.
         * @param allowPartialMatch If any card fails to match, the operation is aborted and the results obtained so far are returned
         *  (but they might be incomplete). If this parameter is set to false, null is returned on failure. */
        public CardList MatchCards(List<Bitmap> images, bool allowPartialMatch)
        {
            if (images.Count == 0) return null;

            CardList result = new CardList();

            foreach (Bitmap image in images)
            {
                Card card = MatchCard(image);
                if (card != null)
                {
                    result.AddCard(card);
                }
                else if (allowPartialMatch)
                {
                    return result;
                }
                else
                {
                    return null;
                }
            }

            return result;
        }
Example #7
0
            public ClassificationPostflop(HoldemHand hand, HoldemGamePhase phase, HoldemBoard board)
            {
                CardList communityCards = board.GetBoardAt(phase);

                // Default
                this.hand         = HandType.Unknown;
                this.kicker       = KickerType.Unknown;
                this.pair         = PairType.Irrelevant;
                this.draw         = DrawType.Irrelevant;
                this.straightDraw = StraightDrawType.None;

                Trace.Assert(communityCards.Count > 0, "Cannot classificate an empty list of community cards.");

                // Create a new list including the board cards and the cards from the hand
                CardList cards = new CardList(communityCards.Count + 2);

                foreach (Card c in communityCards)
                {
                    cards.AddCard(c);
                }
                cards.AddCard(hand.GetFirstCard());
                cards.AddCard(hand.GetSecondCard());

                // --- Royal flush
                if (IsRoyalFlush(cards))
                {
                    this.hand   = HandType.RoyalFlush;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // -- Four of a kind
                if (cards.HaveIdenticalFaces(4))
                {
                    this.hand   = HandType.FourOfAKind;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // -- Full House
                // If we have three of a kind and two pair at the same time, we have a full house
                bool isThreeOfAKind = cards.HaveIdenticalFaces(3);
                bool isTwoPair      = IsTwoPair(cards);

                if (isThreeOfAKind && isTwoPair)
                {
                    this.hand   = HandType.FullHouse;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // -- Flush
                for (int i = 0; i < cards.Count; i++)
                {
                    int numCardsSameSuit = 0;
                    for (int j = i + 1; j < cards.Count; j++)
                    {
                        if (cards[i].Suit == cards[j].Suit)
                        {
                            numCardsSameSuit++;
                        }
                    }

                    if (numCardsSameSuit >= 4)
                    {
                        this.hand   = HandType.Flush;
                        this.kicker = KickerType.Irrelevant;
                        return;
                    }
                }

                // -- Straight
                if (IsStraight(cards))
                {
                    this.hand   = HandType.Straight;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // Calculate draws (if we got until here, there might be some)
                // Also, no draws are possible at the river
                if (phase == HoldemGamePhase.River)
                {
                    draw         = DrawType.None;
                    straightDraw = StraightDrawType.None;
                }
                else
                {
                    draw = GetDrawType(cards);

                    if (IsInsideStraightDraw(cards))
                    {
                        straightDraw = StraightDrawType.InsideStraightDraw;
                    }

                    if (IsOpenEndedStraightDraw(cards))
                    {
                        straightDraw = StraightDrawType.OpenEndedStraightDraw;
                    }
                }

                // -- Trips
                if (isThreeOfAKind)
                {
                    this.hand   = HandType.ThreeOfAKind;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // -- Two pair
                if (isTwoPair)
                {
                    this.hand   = HandType.TwoPair;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // -- Pair
                Card matching;

                if (cards.HaveIdenticalFaces(2, out matching))
                {
                    // Sort list by face value (ace high first)
                    cards.Sort(SortUsing.AceHigh);

                    // Find kicker (check from end of the list where face values are higher)
                    Card kicker = cards[0];
                    for (int i = cards.Count - 1; i >= 0; i--)
                    {
                        if (cards[i].Face != matching.Face)
                        {
                            kicker = cards[i];
                            break;
                        }
                    }


                    this.hand   = HandType.Pair;
                    this.kicker = GetKickerTypeFromCard(kicker);
                    this.pair   = GetPairType(communityCards, matching, hand.GetFirstCard(), hand.GetSecondCard());
                    return;
                }

                // -- High card
                cards.Sort(SortUsing.AceHigh);
                Card highCard = cards.Last;

                this.hand   = HandType.HighCard;
                this.kicker = GetKickerTypeFromCard(highCard);
            }
Example #8
0
        void handHistoryParser_FoundTableMaxSeatingCapacity(int maxSeatingCapacity)
        {
            this.maxSeatingCapacity = maxSeatingCapacity;

            // Usually the max seating capacity is the last piece of information we need in order to create a visual recognition manager

            // Attempt to create the visual recognition manager
            if (IsVisualRecognitionPossible())
            {
                if (visualRecognitionManager == null)
                {
                    visualRecognitionManager = new VisualRecognitionManager(this, this);
                }

                // TODO REMOVE

                CardList cards = new CardList();
                //cards.AddCard(new Card(CardFace.Six, CardSuit.Spades));
                //cards.AddCard(new Card(CardFace.Eight, CardSuit.Spades));
                cards.AddCard(new Card(CardFace.Ace, CardSuit.Clubs));
                cards.AddCard(new Card(CardFace.Seven, CardSuit.Hearts));

                PlayerHandRecognized(cards);

                CardList board = new CardList();
                cards.AddCard(new Card(CardFace.Ace, CardSuit.Hearts));
                cards.AddCard(new Card(CardFace.Seven, CardSuit.Spades));
                cards.AddCard(new Card(CardFace.Six, CardSuit.Hearts));

                BoardRecognized(board);

                Globals.Director.RunFromGUIThread((Action)delegate()
                {
                    if (displayWindow != null) displayWindow.SetVisualRecognitionSupported(true);
                }, false);
            }
            else
            {
                Trace.WriteLine("Visual recognition is not supported for " + this.ToString());

                Globals.Director.RunFromGUIThread((Action)delegate()
                {
                    if (displayWindow != null) displayWindow.SetVisualRecognitionSupported(false);
                }, false);
            }
        }
Example #9
0
            public ClassificationPostflop(HoldemHand hand, HoldemGamePhase phase, HoldemBoard board)
            {
                CardList communityCards = board.GetBoardAt(phase);

                // Default
                this.hand = HandType.Unknown;
                this.kicker = KickerType.Unknown;
                this.pair = PairType.Irrelevant;
                this.draw = DrawType.Irrelevant;
                this.straightDraw = StraightDrawType.None;

                Trace.Assert(communityCards.Count > 0, "Cannot classificate an empty list of community cards.");

                // Create a new list including the board cards and the cards from the hand
                CardList cards = new CardList(communityCards.Count + 2);
                foreach (Card c in communityCards) cards.AddCard(c);
                cards.AddCard(hand.GetFirstCard());
                cards.AddCard(hand.GetSecondCard());

                // --- Royal flush
                if (IsRoyalFlush(cards))
                {
                    this.hand = HandType.RoyalFlush;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // -- Four of a kind
                if (cards.HaveIdenticalFaces(4))
                {
                    this.hand = HandType.FourOfAKind;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // -- Full House
                // If we have three of a kind and two pair at the same time, we have a full house
                bool isThreeOfAKind = cards.HaveIdenticalFaces(3);
                bool isTwoPair = IsTwoPair(cards);
                if (isThreeOfAKind && isTwoPair)
                {
                    this.hand = HandType.FullHouse;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // -- Flush
                for (int i = 0; i < cards.Count; i++)
                {
                    int numCardsSameSuit = 0;
                    for (int j = i + 1; j < cards.Count; j++)
                    {
                        if (cards[i].Suit == cards[j].Suit)
                        {
                            numCardsSameSuit++;
                        }
                    }

                    if (numCardsSameSuit >= 4)
                    {
                        this.hand = HandType.Flush;
                        this.kicker = KickerType.Irrelevant;
                        return;
                    }
                }

                // -- Straight
                if (IsStraight(cards))
                {
                    this.hand = HandType.Straight;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // Calculate draws (if we got until here, there might be some)
                // Also, no draws are possible at the river
                if (phase == HoldemGamePhase.River)
                {
                    draw = DrawType.None;
                    straightDraw = StraightDrawType.None;
                }
                else
                {
                    draw = GetDrawType(cards);

                    if (IsInsideStraightDraw(cards))
                    {
                        straightDraw = StraightDrawType.InsideStraightDraw;
                    }

                    if (IsOpenEndedStraightDraw(cards))
                    {
                        straightDraw = StraightDrawType.OpenEndedStraightDraw;
                    }
                }

                // -- Trips
                if (isThreeOfAKind)
                {
                    this.hand = HandType.ThreeOfAKind;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // -- Two pair
                if (isTwoPair)
                {
                    this.hand = HandType.TwoPair;
                    this.kicker = KickerType.Irrelevant;
                    return;
                }

                // -- Pair
                Card matching;
                if (cards.HaveIdenticalFaces(2, out matching))
                {
                    // Sort list by face value (ace high first)
                    cards.Sort(SortUsing.AceHigh);

                    // Find kicker (check from end of the list where face values are higher)
                    Card kicker = cards[0];
                    for (int i = cards.Count - 1; i >= 0; i--)
                    {
                        if (cards[i].Face != matching.Face)
                        {
                            kicker = cards[i];
                            break;
                        }
                    }

                    this.hand = HandType.Pair;
                    this.kicker = GetKickerTypeFromCard(kicker);
                    this.pair = GetPairType(communityCards, matching, hand.GetFirstCard(), hand.GetSecondCard());
                    return;
                }

                // -- High card
                cards.Sort(SortUsing.AceHigh);
                Card highCard = cards.Last;

                this.hand = HandType.HighCard;
                this.kicker = GetKickerTypeFromCard(highCard);
            }