コード例 #1
0
ファイル: Card.cs プロジェクト: manboygames/capsa
 public CardData(Card.Suit suit, Card.Rank rank, bool shown = true)
 {
     this.suit = suit;
     this.rank = rank;
     value     = (int)suit + (int)rank * Enum.GetValues(typeof(Card.Suit)).Length;
     isShown   = shown;
 }
コード例 #2
0
    private Card.Rank[] GetOnePairRanks(List <Card> pokerHand, int[] numberEachRank)
    {
        Card.Rank[] highestRanks = new Card.Rank[] { Card.Rank.none, Card.Rank.none, Card.Rank.none, Card.Rank.none, Card.Rank.none };
        List <Card> highCardHand = new List <Card>();

        for (int i = 0; i < numberEachRank.Length; i++)
        {
            if (numberEachRank[i] >= 2)
            {
                highestRanks[0] = (Card.Rank)i;
            }
        }

        foreach (Card el in pokerHand)
        {
            if (el.GetRank() != highestRanks[0])
            {
                highCardHand.Add(el);
            }
        }

        var sortedTwoPairHand = highCardHand.OrderByDescending(x => (int)(x.GetRank())).ToList();

        highestRanks[1] = sortedTwoPairHand[0].GetRank();
        highestRanks[2] = sortedTwoPairHand[1].GetRank();
        highestRanks[3] = sortedTwoPairHand[2].GetRank();

        return(highestRanks);
    }
コード例 #3
0
        public HoleCards(Card.Rank rank1, Card.Suite suite1, Card.Rank rank2, Card.Suite suite2)
        {
            Card0 = new Card(suite1, rank1);
            Card1 = new Card(suite2, rank2);

            SortCards();
        }
コード例 #4
0
    private Card.Rank[] GetFullHouseRanks(int[] numberEachRank)
    {
        Card.Rank[] highestRanks = new Card.Rank[] { Card.Rank.none, Card.Rank.none, Card.Rank.none, Card.Rank.none, Card.Rank.none };
        bool        threeOfAKind = false;
        bool        twoOfAKind   = false;

        for (int i = 0; i < numberEachRank.Length; i++)
        {
            if (numberEachRank[i] >= 2)
            {
                if (numberEachRank[i] >= 3 && !threeOfAKind)
                {
                    highestRanks[0] = (Card.Rank)i;
                    threeOfAKind    = true;
                }
                else if (!twoOfAKind || threeOfAKind)
                {
                    if (numberEachRank[i] >= 3 && threeOfAKind)
                    {
                        highestRanks[1] = highestRanks[0];
                        highestRanks[0] = (Card.Rank)i;
                    }
                    else
                    {
                        highestRanks[1] = (Card.Rank)i;
                    }
                    twoOfAKind = true;
                }
            }
        }
        return(highestRanks);
    }
コード例 #5
0
ファイル: Deck.cs プロジェクト: manboygames/capsa
    public Card GetCard(Card.Suit suit, Card.Rank rank)
    {
        Card card = cardsDict[cardNamePrefix + Enum.GetName(typeof(Card.Suit), suit) + Enum.GetName(typeof(Card.Rank), rank)];

        deckCardsList.Remove(card);
        return(card);
    }
コード例 #6
0
        public Deck()
        {
            deck = new List <Card>();
            Bitmap image;

            int rankNum;

            foreach (Card.Suit suit in Card.valuesS)
            {
                rankNum = 2;
                for (int x = 0; x < 13; x++)
                {
                    Card.Rank rank = Card.ranks[x];
                    if (x > 7)
                    {
                        switch (x)
                        {
                        case 8:
                            image = Program.playingCards.ElementAt(8 * ((int)suit + 1));
                            rank  = Card.Rank.Ten;
                            break;

                        case 9:
                            image = Program.playingCards.ElementAt(9 * ((int)suit + 1));
                            rank  = Card.Rank.Jack;
                            break;

                        case 10:
                            image = Program.playingCards.ElementAt(10 * ((int)suit + 1));
                            rank  = Card.Rank.Queen;
                            break;

                        case 10 + 1:
                            image = Program.playingCards.ElementAt((10 + 1) * ((int)suit + 1));
                            rank  = Card.Rank.King;
                            break;

                        case 12:
                            image = Program.playingCards.ElementAt(12 * ((int)suit + 1));
                            rank  = Card.Rank.Ace;
                            break;

                        default:
                            Console.WriteLine("FIENDADJWANDWJAKWA\nTHAT\'S NOT 89!!!");
                            image = Program.playingCards.ElementAt(0);
                            rank  = Card.Rank.Ten;
                            break;
                        }
                    }
                    else
                    {
                        image = Program.playingCards.ElementAt(x * ((int)suit + 1));
                    }
                    deck.Add(new Card(suit, rank, image, rankNum));
                    rankNum++;
                }
            }

            deal = deck.GetEnumerator();
        }
コード例 #7
0
    private Card.Rank[] GetFourOfAKindRanks(List <Card> pokerHand, int[] numberEachRank)
    {
        Card.Rank   foursRank    = Card.Rank.none;
        Card.Rank[] highestRanks = new Card.Rank[] { Card.Rank.none, Card.Rank.none, Card.Rank.none, Card.Rank.none, Card.Rank.none };
        List <Card> highCardHand = new List <Card>();

        for (int i = 0; i < numberEachRank.Length; i++)
        {
            if (numberEachRank[i] >= 4)
            {
                foursRank       = (Card.Rank)i;
                highestRanks[0] = foursRank;
            }
        }

        foreach (Card el in pokerHand)
        {
            if (el.GetRank() != foursRank)
            {
                highCardHand.Add(el);
            }
        }

        var sortedFoursHand = highCardHand.OrderByDescending(x => (int)(x.GetRank())).ToList();

        highestRanks[1] = sortedFoursHand[0].GetRank();
        return(highestRanks);
    }
コード例 #8
0
    private Card.Rank[] GetFlushRanks(List <Card> pokerHand, int[] numberEachSuit)
    {
        Card.Suit   flushSuit = Card.Suit.none;
        List <Card> flushHand = new List <Card>();

        Card.Rank[] highestRanks = new Card.Rank[] { Card.Rank.none, Card.Rank.none, Card.Rank.none, Card.Rank.none, Card.Rank.none };

        for (int i = 0; i < numberEachSuit.Length; i++)
        {
            if (numberEachSuit[i] >= 5)
            {
                flushSuit = (Card.Suit)i;
            }
        }

        foreach (Card el in pokerHand)
        {
            if (el.GetSuit() == flushSuit)
            {
                flushHand.Add(el);
            }
        }

        var sortedFlushHand = flushHand.OrderByDescending(x => (int)(x.GetRank())).ToList();

        for (int i = 0; i < 5; i++)
        {
            highestRanks[i] = sortedFlushHand[i].GetRank();
        }

        return(highestRanks);
    }
コード例 #9
0
ファイル: Deck.cs プロジェクト: cueda/video-poker
    private Deck()
    {
        cards = new Card[52];

        // Add the 13 cards for each suit into the deck
        int index = 0;

        for (int i = 0; i < 4; i++)
        {
            Card.Suit suit = (Card.Suit)i;
            for (int j = 0; j < 13; j++)
            {
                Card.Rank rank = (Card.Rank)j;
                cards[index] = new Card(suit, rank);
                index++;
            }
        }

        if (DebugObject.Instance.DEBUG_MODE)
        {
            for (int i = 0; i < Mathf.Min(DebugObject.Instance.debugCardRanks.Length, DebugObject.Instance.debugCardSuits.Length); i++)
            {
                cards[i] = new Card(DebugObject.Instance.debugCardSuits[i], DebugObject.Instance.debugCardRanks[i]);
                Debug.Log("Replacing card " + i + " with " + cards[i]);
            }
        }
        ShuffleDeck();
    }
コード例 #10
0
 public void Reset()
 {
     rank        = HandRank.HighCard;
     primaryRank = Card.Rank.Unknown;
     secondRank  = Card.Rank.Unknown;
     kicker1Rank = Card.Rank.Unknown;
     kicker2Rank = Card.Rank.Unknown;
     kicker3Rank = Card.Rank.Unknown;
 }
コード例 #11
0
 public HandStrength(HandStrength copy)
 {
     rank        = copy.rank;
     primaryRank = copy.primaryRank;
     secondRank  = copy.secondRank;
     kicker1Rank = copy.kicker1Rank;
     kicker2Rank = copy.kicker2Rank;
     kicker3Rank = copy.kicker3Rank;
 }
コード例 #12
0
 // should probably change this to do a binary search....rather than linear
 public bool ContainsRank(Card.Rank rank)
 {
     foreach (Card item in hand)
     {
         if (item.RANK.Equals(rank))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #13
0
 public bool HasRank(Card.Rank whichRank, List <Card> whichHand)
 {
     for (int x = 0; x < whichHand.Count; x++)
     {
         if (whichHand[x].GetRank() == whichRank)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #14
0
        public static Card[] RetrieveCommunityCards()
        {
            Bitmap currentCommunityCards = CaptureCommunityCardsImage();

            int foundCount = 0;
            int cardsToSearch;

            Card[] hand;

            //Check to see how many cards you need to find, if no cards are on the table return null.
            if (BitmapHandler.SearchBitmap(currentCommunityCards, RetrieveBitmap("3cards")))
            {
                cardsToSearch = 3;
                hand          = new Card[3];
            }
            else if (BitmapHandler.SearchBitmap(currentCommunityCards, RetrieveBitmap("4cards")))
            {
                cardsToSearch = 4;
                hand          = new Card[4];
            }
            else if (BitmapHandler.SearchBitmap(currentCommunityCards, RetrieveBitmap("5cards")))
            {
                cardsToSearch = 5;
                hand          = new Card[5];
            }
            else
            {
                return(null);
            }

            foreach (NamedBitmap cardImage in cardPics)
            {
                if (BitmapHandler.SearchBitmap(currentCommunityCards, cardImage.bitmap))
                {
                    //Split the Bitmap filenames up into two seperate strings. EX) filename == S7, then stringSuit = "S", and stringRank = "7"
                    string stringSuit = cardImage.name.Substring(0, 1);
                    string stringRank = cardImage.name.Substring(1);

                    //Get the Bitmap filenames into Suit and Rank Enums. EX) filename == S7, then cardSuit = Suit.Spades, and cardRank = Rank.Seven
                    Card.Suit cardSuit = ConvertStringToSuit(stringSuit);
                    Card.Rank cardRank = ConvertStringToRank(stringRank);

                    hand[foundCount] = new Card(cardSuit, cardRank);
                    foundCount++;

                    //If you found all the cards, stop searching
                    if (foundCount == cardsToSearch)
                    {
                        break;
                    }
                }
            }
            return(hand);
        }
コード例 #15
0
ファイル: MeldChecker.cs プロジェクト: visualsquid/gin-rummy
        public bool IsSet(Meld m)
        {
            List <Card> cardsInMeld = m.GetListOfCardsInMeld();

            if (cardsInMeld.Count < MinimumSetSize)
            {
                return(false);
            }

            Card.Rank firstItemRank = cardsInMeld[0].RankValue;

            if (cardsInMeld.Distinct(new GinRummySuitEqualityComparer()).Count() != cardsInMeld.Count)
            {
                return(false);
            }

            return(cardsInMeld.All(i => i.RankValue == firstItemRank));
        }
コード例 #16
0
        /// <summary>
        /// Requests a <see cref="Card.Rank"/> from the other player.
        /// If the requested <see cref="Card.Rank"/> exists in their hand,
        /// the <see cref="Card"/> is removed from their hand and added to the hand of the requester.
        /// </summary>
        /// <param name="myHand">The hand of the requester</param>
        /// <param name="yourHand">The hand of the responder</param>
        /// <param name="value">The <see cref="Card.Rank"/> value requested</param>
        /// <returns>true if the requested card exists in yourHand, false otherwise</returns>
        private static bool AskForCard(List <Card> myHand, List <Card> yourHand, Card.Rank value)
        {
            bool foundMatch = false;
            Card foundCard  = new Card();

            foreach (var card in yourHand)
            {
                if (card.CardRank == value) // Match!
                {
                    foundCard = card;
                    myHand.Add(foundCard);
                    foundMatch = true;
                    break;
                }
            }

            yourHand.Remove(foundCard);
            return(foundMatch);
        }
コード例 #17
0
ファイル: PokerHands.cs プロジェクト: cueda/video-poker
    // Checks for a first sequential pair,
    // then searches for a second pair with a separate rank from the first
    // If a second pair is found, hand contains a two-pair
    private static bool IsHandTwoPair(Card[] rankSortedHand)
    {
        Card.Rank firstPairRank  = rankSortedHand[0].rank;
        Card.Rank secondPairRank = rankSortedHand[0].rank;
        bool      firstPairFound = false;

        for (int i = 1; i < rankSortedHand.Length; i++)
        {
            if (!firstPairFound)
            {
                if (firstPairRank == rankSortedHand[i].rank)
                {
                    firstPairFound = true;
                    if (i < rankSortedHand.Length - 1)
                    {
                        secondPairRank = rankSortedHand[i + 1].rank;
                        i++;
                    }
                }
                else
                {
                    firstPairRank = rankSortedHand[i].rank;
                }
            }
            else
            {
                if (secondPairRank != firstPairRank)
                {
                    if (secondPairRank == rankSortedHand[i].rank)
                    {
                        return(true);
                    }
                    else
                    {
                        secondPairRank = rankSortedHand[i].rank;
                    }
                }
            }
        }

        return(false);
    }
コード例 #18
0
        public static string ConvertRankToString(Card.Rank rank)
        {
            switch (rank)
            {
            case Rank.Ace: return("A");

            case Rank.King: return("K");

            case Rank.Queen: return("Q");

            case Rank.Jack: return("J");

            case Rank.Ten: return("T");

            case Rank.NotFound: return("0");

            default:
                return(((int)rank).ToString());
            }
            return("0");
        }
コード例 #19
0
        public static Card[] RetrieveYourHand()
        {
            Bitmap currentHand = CaptureYourHandImage();

            //First check to see if there are no cards in your hand to avoid unnessicary searching.
            if (BitmapHandler.SearchBitmap(currentHand, RetrieveBitmap("NoHand")))
            {
                return(null);
            }
            else
            {
                int    foundCount    = 0;
                int    cardsToSearch = 2;
                Card[] hand          = new Card[2];

                foreach (NamedBitmap cardImage in cardPics)
                {
                    if (BitmapHandler.SearchBitmap(currentHand, cardImage.bitmap))
                    {
                        //Split the Bitmap filenames up into two seperate strings. EX) filename == S7, then stringSuit = "S", and stringRank = "7"
                        string stringSuit = cardImage.name.Substring(0, 1);
                        string stringRank = cardImage.name.Substring(1);

                        //Get the Bitmap filenames into Suit and Rank Enums. EX) filename == S7, then cardSuit = Suit.Spades, and cardRank = Rank.Seven
                        Card.Suit cardSuit = ConvertStringToSuit(stringSuit);
                        Card.Rank cardRank = ConvertStringToRank(stringRank);

                        hand[foundCount] = new Card(cardSuit, cardRank);
                        foundCount++;

                        //If you found all the cards, stop searching
                        if (foundCount == cardsToSearch)
                        {
                            break;
                        }
                    }
                }
                return(hand);
            }
        }
コード例 #20
0
    private List <Card> GetStraightHand(List <Card> pokerHand, int[] numberEachRank)
    {
        int rankInRow = 0;

        Card.Rank   highestRank  = Card.Rank.none;
        List <Card> straightHand = new List <Card>();

        for (int i = 0; i < numberEachRank.Length; i++)
        {
            if (numberEachRank[numberEachRank.Length - 1 - i] > 0)
            {
                rankInRow++;
            }
            else
            {
                rankInRow = 0;
            }

            if (rankInRow == 5)
            {
                int j = numberEachRank.Length - i + 3;
                highestRank = (Card.Rank)j;
            }

            if (i == numberEachRank.Length && highestRank == Card.Rank.none)
            {
                highestRank = Card.Rank.five;
            }
        }

        foreach (Card el in pokerHand)
        {
            if ((int)el.GetRank() <= (int)highestRank && (int)el.GetRank() >= (int)highestRank - 4)
            {
                straightHand.Add(el);
            }
        }
        return(straightHand);
    }
コード例 #21
0
    private Card.Rank[] GetStraightRanks(List <Card> pokerHand)
    {
        Card.Rank[] highestRanks = new Card.Rank[] { Card.Rank.none, Card.Rank.none, Card.Rank.none, Card.Rank.none, Card.Rank.none };

        var sortedHand = pokerHand.OrderByDescending(x => (int)(x.GetRank())).ToList();

        if (sortedHand[0].GetRank() == Card.Rank.A)
        {
            if (sortedHand[1].GetRank() == Card.Rank.five || sortedHand[2].GetRank() == Card.Rank.five || sortedHand[3].GetRank() == Card.Rank.five)
            {
                highestRanks[0] = Card.Rank.five;
            }
            else
            {
                highestRanks[0] = Card.Rank.A;
            }
        }
        else
        {
            highestRanks[0] = sortedHand[0].GetRank();
        }

        return(highestRanks);
    }
コード例 #22
0
ファイル: PokerHands.cs プロジェクト: cueda/video-poker
    // If a given rank is found four times in successive cards, it is a four-of-a-kind
    private static bool IsHandFourOfAKind(Card[] rankSortedHand)
    {
        Card.Rank curRank = rankSortedHand[0].rank;
        int       count   = 0;

        for (int i = 0; i < rankSortedHand.Length; i++)
        {
            if (curRank == rankSortedHand[i].rank)
            {
                count++;
                if (count >= 4)
                {
                    return(true);
                }
            }
            else
            {
                count   = 1;
                curRank = rankSortedHand[i].rank;
            }
        }

        return(false);
    }
コード例 #23
0
        public static string Card_Rank_ToString(Card.Rank cr)
        {
            string str_ret = "";

            switch ((int)cr)
            {
            case 2:
                str_ret = "2";
                break;

            case 3:
                str_ret = "3";
                break;

            case 4:
                str_ret = "4";
                break;

            case 5:
                str_ret = "5";
                break;

            case 6:
                str_ret = "6";
                break;

            case 7:
                str_ret = "7";
                break;

            case 8:
                str_ret = "8";
                break;

            case 9:
                str_ret = "9";
                break;

            case 10:
                str_ret = "10";
                break;

            case 11:
                str_ret = "J";
                break;

            case 12:
                str_ret = "Q";
                break;

            case 13:
                str_ret = "K";
                break;

            case 14:
                str_ret = "A";
                break;

            default:
                break;
            }
            return(str_ret);
        }
コード例 #24
0
 public Card(Card.Suit cs, Card.Rank cr)
 {
     this.suit = cs;
     this.rank = cr;
 }
コード例 #25
0
ファイル: Deck.cs プロジェクト: manboygames/capsa
 public Sprite GetCardSprite(Card.Suit suit, Card.Rank rank)
 {
     return(spritesDict[cardNamePrefix + Enum.GetName(typeof(Card.Suit), suit) + StringEnum.GetStringValue(rank)]);
 }
コード例 #26
0
        // Retrieve Pocket cards
        public Card[] RetrievePocketCards()
        {
            Card[] pocketCards = new Card[2];

            // Get bounds
            GraphicsUnit gu     = GraphicsUnit.Pixel;
            RectangleF   bounds = bitmap.GetBounds(ref gu);

            // ------------------------------------------------------------------//
            // Define relative ratios ~ For relative reading
            float relativeCardStartX     = 347.0f / 794.0f; ///0.33477135461f;
            float relativeCardStartRankY = 337.0f / 545.0f; //0.3153942428f;
            float relativeCardWidth      = 15.0f / 794.0f;  //0.02188868042f;
            float relativeCardRankHeight = 22.0f / 545.0f;  //0.05006257822f;

            float relativeCardSpacing = 48.0f / 794.0f;

            // Relative suit region (266, 198, 14, 14) (794, 547);
            float relativeSuitRegionX = 349.0f / 794.0f;
            float relativeSuitRegionY = 354.0f / 547.0f;
            float relativeSuitRegionW = 14.0f / 794.0f;
            float relativeSuitRegionH = 14.0f / 547.0f;

            // ------------------------------------------------------------------//
            // Capture:
            for (int i = 0; i < 2; i++)
            {
                Rectangle rankRegion = new Rectangle((int)Math.Floor((relativeCardStartX + ((relativeCardSpacing) * i)) * (bounds.Width)),
                                                     (int)Math.Floor(relativeCardStartRankY * bounds.Height),
                                                     (int)Math.Floor(relativeCardWidth * bounds.Width),
                                                     (int)Math.Floor(relativeCardRankHeight * bounds.Height));

                Rectangle suitRegion = new Rectangle((int)Math.Floor((relativeSuitRegionX + (relativeCardSpacing * i)) * (bounds.Width)),
                                                     (int)Math.Floor(relativeSuitRegionY * bounds.Height),
                                                     (int)Math.Floor(relativeSuitRegionW * bounds.Width),
                                                     (int)Math.Floor(relativeSuitRegionH * bounds.Height));
                //Console.WriteLine(suitRegion.ToString());
                //Rectangle rankRegion = new Rectangle(397, 269, 18, 22);
                Bitmap section = CopyBitmapSection(bitmap, rankRegion);
                //Bitmap sectionSuit = CopyBitmapSection(bitmap, suitRegion);
                //sectionSuit.Save("Suitsec" + i + ".png", ImageFormat.Png);

                // Filter out noise
                filterBMP(section);

                // Stitch multiple sections together (To improve read accuracy)
                Bitmap   b = new Bitmap(rankRegion.Width * 4, rankRegion.Height);
                Graphics g = Graphics.FromImage(b);
                g.DrawImage(section, 0, 0);
                g.DrawImage(section, rankRegion.Width, 0);
                g.DrawImage(section, rankRegion.Width * 2, 0);
                g.DrawImage(section, rankRegion.Width * 3, 0);
                g.Dispose();
                section = b;

                // Perform read
                //filterBMP2(section);
                if (rankRegion.Width < 10.0f)
                {
                    section = upscaleBmp(section);
                }
                section.Save("Card" + i + ".png", ImageFormat.Png);
                Card.Rank rank = getCardRankFromBitmap(section);

                // Determine suit


                /*
                 *  Determines the suit of the given card by sampling the average colour in a given region.
                 */
                Color     sample = sampleBitmapAverageColour(bitmap, suitRegion);
                Card.Suit suit   = Card.Suit.NotFound;

                if (rank != Card.Rank.NotFound)
                {
                    if ((sample.R > 150) || (sample.R > 110 && sample.G < 90 && sample.B < 90))
                    {
                        suit = Card.Suit.Hearts;
                    }
                    else if (sample.G > 130)
                    {
                        suit = Card.Suit.Clubs;
                    }
                    else if (sample.B > 150)
                    {
                        suit = Card.Suit.Diamonds;
                    }
                    else if (sample.R < 100 && sample.G < 100 && sample.B < 100)
                    {
                        suit = Card.Suit.Spades;
                    }
                }

                pocketCards[i] = new Card(suit, rank);
            }
            return(pocketCards);
        }
コード例 #27
0
        // Retrieve Community Cards
        public Card[] RetieveCommunityCards()
        {
            Card[] communityCards = new Card[5];

            // Get bounds
            GraphicsUnit gu     = GraphicsUnit.Pixel;
            RectangleF   bounds = bitmap.GetBounds(ref gu);

            // ------------------------------------------------------------------//
            // Define relative ratios ~ For relative reading
            float relativeCardStartX     = 266.0f / 794.0f; ///0.33477135461f;
            float relativeCardStartRankY = 177.0f / 545.0f; //0.3153942428f;
            float relativeCardWidth      = 15.0f / 794.0f;  //0.02188868042f;
            float relativeCardRankHeight = 20.0f / 545.0f;  //0.05006257822f;
            //float relativeCardSpacing     = 54.0f / 794.0f;//0.06801007556f;//0.06557377049f;

            // relative spacing

            /*
             * Spacing is based on the raw size of the card. There are preset card sizes: ( in pixels)
             *
             * 0 = 30w 42h
             * 1 = 36w 51h
             * 2 = 42w 59h
             * 3 = 50w 70h
             * 4 = 60w 84h
             * 5 = 70w 98h
             * 6 = 84w 118h
             *
             * these are decided based on the overall size of the window.
             *
             * Examples:
             *
             *  Table size: 534w 368h uses size 1.
             *  Table size: 1159w 799h uses size 5
             *
             * approximation nearest size: tableWidth/16
             * Spacing should therefore be equal to width of  card + min(max( 3,size), 8);
             */
            float relativeCardSpacing = 54.0f / 794.0f;

            // Relative suit region (266, 198, 14, 14) (794, 547);
            float relativeSuitRegionX = 266.0f / 794.0f;
            float relativeSuitRegionY = 198.0f / 547.0f;
            float relativeSuitRegionW = 14.0f / 794.0f;
            float relativeSuitRegionH = 14.0f / 547.0f;

            // ------------------------------------------------------------------//

            // Capture:
            for (int i = 0; i < 5; i++)
            {
                Rectangle rankRegion = new Rectangle((int)Math.Floor((relativeCardStartX + ((relativeCardSpacing) * i)) * (bounds.Width)),
                                                     (int)Math.Floor(relativeCardStartRankY * bounds.Height),
                                                     (int)Math.Floor(relativeCardWidth * bounds.Width),
                                                     (int)Math.Floor(relativeCardRankHeight * bounds.Height));

                Rectangle suitRegion = new Rectangle((int)Math.Floor((relativeSuitRegionX + (relativeCardSpacing * i)) * (bounds.Width)),
                                                     (int)Math.Floor(relativeSuitRegionY * bounds.Height),
                                                     (int)Math.Floor(relativeSuitRegionW * bounds.Width),
                                                     (int)Math.Floor(relativeSuitRegionH * bounds.Height));
                //Console.WriteLine(suitRegion.ToString());
                //Rectangle rankRegion = new Rectangle(397, 269, 18, 22);
                Bitmap section = CopyBitmapSection(bitmap, rankRegion);
                //Bitmap sectionSuit = CopyBitmapSection(bitmap, suitRegion);
                //sectionSuit.Save("Suitsec" + i + ".png", ImageFormat.Png);

                // Filter out noise
                filterBMP(section);

                // Stitch multiple sections together (To improve read accuracy)
                Bitmap   b = new Bitmap(rankRegion.Width * 4, rankRegion.Height);
                Graphics g = Graphics.FromImage(b);
                g.DrawImage(section, 0, 0);
                g.DrawImage(section, rankRegion.Width, 0);
                g.DrawImage(section, rankRegion.Width * 2, 0);
                g.DrawImage(section, rankRegion.Width * 3, 0);
                g.Dispose();
                section = b;

                // Perform read
                //filterBMP2(section);
                if (rankRegion.Width < 10.0f)
                {
                    section = upscaleBmp(section);
                }
                section.Save("Card" + i + ".png", ImageFormat.Png);
                Card.Rank rank = getCardRankFromBitmap(section);

                // Determine suit


                /*
                 *  Determines the suit of the given card by sampling the average colour in a given region.
                 */
                Color     sample = sampleBitmapAverageColour(bitmap, suitRegion);
                Card.Suit suit   = Card.Suit.NotFound;

                if (rank != Card.Rank.NotFound)
                {
                    /*if (colourIsSimilar(sample, Color.FromArgb(200, 10, 10))) {         suit = Card.Suit.Hearts;      }
                     * else if (colourIsSimilar(sample, Color.Black)) {  suit = Card.Suit.Spades;      }
                     * else if (colourIsSimilar(sample, Color.FromArgb(45, 135, 15))) {  suit = Card.Suit.Clubs;       }
                     * else if (colourIsSimilar(sample, Color.Blue)) {   suit = Card.Suit.Diamonds;    }*/
                    if ((sample.R > 150) || (sample.R > 110 && sample.G < 90 && sample.B < 90))
                    {
                        suit = Card.Suit.Hearts;
                    }
                    else if (sample.G > 130)
                    {
                        suit = Card.Suit.Clubs;
                    }
                    else if (sample.B > 150)
                    {
                        suit = Card.Suit.Diamonds;
                    }
                    else if (sample.R < 100 && sample.G < 100 && sample.B < 100)
                    {
                        suit = Card.Suit.Spades;
                    }
                }

                communityCards[i] = new Card(suit, rank);
            }
            return(communityCards);
        }
コード例 #28
0
        public void AddCard(Card.Suit cs, Card.Rank cr)
        {
            Card c = new Card(cs, cr);

            this.cards.Add(c);
        }
コード例 #29
0
        // Methods to compare hands and determine there strength
        public static int CompareTo(Hand hand_1, Hand hand_2)
        {
            // This method compares two hands.
            // Return a 1 if hand1 beats hand2
            // Return a 0 if hand1 loses to hand2
            // Return a -1 if hand1 ties hand2
            int ret_val = 0;

            // Check whether hand objects can be compared safely
            Hand.HandType ht_1 = hand_1.GetHandType();
            Hand.HandType ht_2 = hand_2.GetHandType();
            if (ht_1 == Hand.HandType.NotAssignedYet || ht_2 == Hand.HandType.NotAssignedYet)
            {
                throw new Exception("One of the hands passed to CompareTo() has not been assigned a handtype yet!! Need to call EvaluateHandtype method first.");
            }

            // If hand1 has a higher rank, we know right away that it beats hand2
            if ((int)ht_1 > (int)ht_2)
            {
                return(1);
            }
            // If hand2 has a higher rank, we know right away that it beats hand1
            if ((int)ht_2 > (int)ht_1)
            {
                return(0);
            }
            // hands should be of same handtype if we are executing code below here
            if ((int)ht_1 != (int)ht_2)
            {
                throw new Exception("ht_1 != ht_2 in the CompareTo() and that shouldn't happen");
            }

            // if hands are of the same rank, we need to compare them card by card
            if (ht_1 != HandType.OnePair && hand_1.IsSorted() == false)
            {
                hand_1.Sort();
            }
            if (ht_2 != HandType.OnePair && hand_2.IsSorted() == false)
            {
                hand_2.Sort();
            }
            // COMPARING STRAIGHT FLUSHES
            if (ht_1 == Hand.HandType.StraightFlush)
            {
                // Check for low ace straights
                Card.Rank hand1_last_card  = hand_1.cards[4].GetRank();
                Card.Rank hand2_last_card  = hand_2.cards[4].GetRank();
                Card.Rank hand1_first_card = hand_1.cards[0].GetRank();
                Card.Rank hand2_first_card = hand_2.cards[0].GetRank();
                // two low ace straights tie
                if ((int)hand1_last_card == 14 && (int)hand1_first_card == 2 && ((int)hand2_last_card == 14 && (int)hand2_first_card == 2))
                {
                    return(-1);
                }
                // first hand is low ace straight and other hand isn't so other hand must win
                if ((int)hand1_last_card == 14 && (int)hand1_first_card == 2 && (int)hand2_first_card >= 2)
                {
                    return(0);
                }
                // second hand is low ace straight and other hand isn't so other hand must win
                if ((int)hand2_last_card == 14 && (int)hand2_first_card == 2 && (int)hand1_first_card >= 2)
                {
                    return(1);
                }
                // Done checking for low ace straights

                int tied_cards = 0;
                for (int i = 4; i >= 0; i--) // progress from right to left
                {
                    Card.Rank hand1_card_rank = hand_1.cards[i].GetRank();
                    Card.Rank hand2_card_rank = hand_2.cards[i].GetRank();
                    if (hand1_card_rank > hand2_card_rank)
                    {
                        return(1);
                    }
                    if (hand2_card_rank > hand1_card_rank)
                    {
                        return(0);
                    }
                    if (hand1_card_rank == hand2_card_rank)
                    {
                        tied_cards++;
                    }
                }
                if (tied_cards == 5)
                {
                    return(-1);
                }
            }
            // COMPARING FOUR OF A KINDS
            if (ht_1 == Hand.HandType.FourOfAKind)
            {
                // first check quads rank
                Card.Rank hand1_quads_rank = hand_1.cards[4].GetRank();
                Card.Rank hand2_quads_rank = hand_2.cards[4].GetRank();
                if (hand1_quads_rank > hand2_quads_rank)
                {
                    return(1);
                }
                if (hand2_quads_rank > hand1_quads_rank)
                {
                    return(0);
                }
                // second check kicker rank
                Card.Rank hand1_kicker_rank = hand_1.cards[0].GetRank();
                Card.Rank hand2_kicker_rank = hand_2.cards[0].GetRank();
                //Console.WriteLine("Comparing Kicker ranks of four of a kinds");
                if (hand1_kicker_rank > hand2_kicker_rank)
                {
                    return(1);
                }
                if (hand2_kicker_rank > hand1_kicker_rank)
                {
                    return(0);
                }
                // if quads ranks and kicker ranks are the same then they tie
                if ((hand1_quads_rank == hand2_quads_rank) && (hand1_kicker_rank == hand2_kicker_rank))
                {
                    return(-1);
                }
            }
            // COMPARING FLUSHES
            if (ht_1 == Hand.HandType.Flush)
            {
                int tied_cards = 0;
                for (int i = 4; i >= 0; i--) // progress from right to left
                {
                    Card.Rank hand1_card_rank = hand_1.cards[i].GetRank();
                    Card.Rank hand2_card_rank = hand_2.cards[i].GetRank();
                    if (hand1_card_rank > hand2_card_rank)
                    {
                        return(1);
                    }
                    if (hand2_card_rank > hand1_card_rank)
                    {
                        return(0);
                    }
                    if (hand1_card_rank == hand2_card_rank)
                    {
                        tied_cards++;
                    }
                }
                if (tied_cards == 5)
                {
                    return(-1);
                }
            }
            // COMPARING STRAIGHTS
            if (ht_1 == Hand.HandType.Straight)
            {
                // Check for low ace straights
                Card.Rank hand1_last_card  = hand_1.cards[4].GetRank();
                Card.Rank hand2_last_card  = hand_2.cards[4].GetRank();
                Card.Rank hand1_first_card = hand_1.cards[0].GetRank();
                Card.Rank hand2_first_card = hand_2.cards[0].GetRank();
                // two low ace straights tie
                if ((int)hand1_last_card == 14 && (int)hand1_first_card == 2 && ((int)hand2_last_card == 14 && (int)hand2_first_card == 2))
                {
                    return(-1);
                }
                // first hand is low ace straight and other hand isn't so other hand must win
                if ((int)hand1_last_card == 14 && (int)hand1_first_card == 2 && (int)hand2_first_card >= 2)
                {
                    return(0);
                }
                // second hand is low ace straight and other hand isn't so other hand must win
                if ((int)hand2_last_card == 14 && (int)hand2_first_card == 2 && (int)hand1_first_card >= 2)
                {
                    return(1);
                }
                int tied_cards = 0;
                for (int i = 4; i >= 0; i--) // progress from right to left
                {
                    Card.Rank hand1_card_rank = hand_1.cards[i].GetRank();
                    Card.Rank hand2_card_rank = hand_2.cards[i].GetRank();

                    if (hand1_card_rank > hand2_card_rank)
                    {
                        return(1);
                    }
                    if (hand2_card_rank > hand1_card_rank)
                    {
                        return(0);
                    }
                    if (hand1_card_rank == hand2_card_rank)
                    {
                        tied_cards++;
                    }
                }
                if (tied_cards == 5)
                {
                    return(-1);
                }
            }
            // COMPARING THREE OF A KINDS
            if (ht_1 == Hand.HandType.ThreeOfAKind)
            {
                // first check trips rank
                Card.Rank hand1_trips_rank = hand_1.cards[4].GetRank();
                Card.Rank hand2_trips_rank = hand_2.cards[4].GetRank();
                if (hand1_trips_rank > hand2_trips_rank)
                {
                    return(1);
                }
                if (hand2_trips_rank > hand1_trips_rank)
                {
                    return(0);
                }
                // second check - first kicker rank
                Card.Rank hand1_kicker_rank = hand_1.cards[1].GetRank();
                Card.Rank hand2_kicker_rank = hand_2.cards[1].GetRank();
                if (hand1_kicker_rank > hand2_kicker_rank)
                {
                    return(1);
                }
                if (hand2_kicker_rank > hand1_kicker_rank)
                {
                    return(0);
                }
                // third check - second kicker rank
                hand1_kicker_rank = hand_1.cards[0].GetRank();
                hand2_kicker_rank = hand_2.cards[0].GetRank();
                if (hand1_kicker_rank > hand2_kicker_rank)
                {
                    return(1);
                }
                if (hand2_kicker_rank > hand1_kicker_rank)
                {
                    return(0);
                }
                // check for tie
                if ((hand1_trips_rank == hand2_trips_rank) && (hand1_kicker_rank == hand2_kicker_rank))
                {
                    return(-1);
                }
            }
            // COMPARING TWO PAIRS
            if (ht_1 == Hand.HandType.TwoPair)
            {
                // first check big pair rank
                Card.Rank big_pair_rank1 = hand_1.cards[4].GetRank();
                Card.Rank big_pair_rank2 = hand_2.cards[4].GetRank();
                if (big_pair_rank1 > big_pair_rank2)
                {
                    return(1);
                }
                if (big_pair_rank2 > big_pair_rank1)
                {
                    return(0);
                }
                // second check - small pair rank
                Card.Rank small_pair_rank1 = hand_1.cards[2].GetRank();
                Card.Rank small_pair_rank2 = hand_2.cards[2].GetRank();
                if (small_pair_rank1 > small_pair_rank2)
                {
                    return(1);
                }
                if (small_pair_rank2 > small_pair_rank1)
                {
                    return(0);
                }
                // third check - check kicker
                Card.Rank hand1_kicker_rank = hand_1.cards[0].GetRank();
                Card.Rank hand2_kicker_rank = hand_2.cards[0].GetRank();
                if (hand1_kicker_rank > hand2_kicker_rank)
                {
                    return(1);
                }
                if (hand2_kicker_rank > hand1_kicker_rank)
                {
                    return(0);
                }
                // if nothing has returned yet then its a tie
                return(-1);
            }
            // COMPARING ONE PAIRS
            if (ht_1 == Hand.HandType.OnePair)
            {
                //// first check big pair rank
                //Card.Rank pair_rank1 = hand_1.cards[4].GetRank();
                //Card.Rank pair_rank2 = hand_2.cards[4].GetRank();
                //if (pair_rank1 > pair_rank2)
                //    return 1;
                //if (pair_rank2 > pair_rank1)
                //    return 0;
                //// second check - first kicker
                //Card.Rank kicker_rank1 = hand_1.cards[2].GetRank();
                //Card.Rank kicker_rank2 = hand_2.cards[2].GetRank();
                //if (kicker_rank1 > kicker_rank2)
                //    return 1;
                //if (kicker_rank2 > kicker_rank1)
                //    return 0;
                //// third check - second kicker
                //kicker_rank1 = hand_1.cards[1].GetRank();
                //kicker_rank2 = hand_2.cards[1].GetRank();
                //if (kicker_rank1 > kicker_rank2)
                //    return 1;
                //if (kicker_rank2 > kicker_rank1)
                //    return 0;
                //// fourth check - third kicker
                //kicker_rank1 = hand_1.cards[0].GetRank();
                //kicker_rank2 = hand_2.cards[0].GetRank();
                //if (kicker_rank1 > kicker_rank2)
                //    return 1;
                //if (kicker_rank2 > kicker_rank1)
                //    return 0;
                //// if nothing has been returned yet then its a tie
                //return -1;
                int hand1_pair_rank = Program.pairRankDict[hand_1.GetPrimeRank()];
                int hand2_pair_rank = Program.pairRankDict[hand_2.GetPrimeRank()];
                if (hand1_pair_rank == hand2_pair_rank)
                {
                    return(-1);
                }
                else if (hand1_pair_rank < hand2_pair_rank)
                {
                    return(1);
                }
                else if (hand1_pair_rank > hand2_pair_rank)
                {
                    return(0);
                }
            }
            //COMPARING FULL HOUSE
            if (ht_1 == Hand.HandType.FullHouse)
            {
                // first check trips rank
                Card.Rank hand1_trips_rank = hand_1.cards[4].GetRank();
                Card.Rank hand2_trips_rank = hand_2.cards[4].GetRank();
                if (hand1_trips_rank > hand2_trips_rank)
                {
                    return(1);
                }
                if (hand2_trips_rank > hand1_trips_rank)
                {
                    return(0);
                }
                // second check doublets rank
                Card.Rank hand1_doublet_rank = hand_1.cards[0].GetRank();
                Card.Rank hand2_doublet_rank = hand_2.cards[0].GetRank();
                if (hand1_doublet_rank > hand2_doublet_rank)
                {
                    return(1);
                }
                if (hand2_doublet_rank > hand1_doublet_rank)
                {
                    return(0);
                }
                // if nothing has returned yet, doublet and triple ranks are same
                return(-1);
            }
            // COMPARING HIGH CARDS
            if (ht_1 == Hand.HandType.HighCard)
            {
                int tied_cards = 0;
                for (int i = 4; i >= 0; i--) // progress from right to left
                {
                    Card.Rank hand1_card_rank = hand_1.cards[i].GetRank();
                    Card.Rank hand2_card_rank = hand_2.cards[i].GetRank();

                    if (hand1_card_rank > hand2_card_rank)
                    {
                        return(1);
                    }
                    if (hand2_card_rank > hand1_card_rank)
                    {
                        return(0);
                    }
                    if (hand1_card_rank == hand2_card_rank)
                    {
                        tied_cards++;
                    }
                }
                if (tied_cards == 5)
                {
                    return(-1);
                }
            }
            return(ret_val);
        }
コード例 #30
0
        // Sort hand
        public void Sort()
        {
            //put doubles triples and quads at end
            //each multiplet should be sorted by suit
            //separate quads, triples, doubles to new lists
            //don't forget the case of a low ace
            bool[] has_been_added = new bool[5];
            // init to false
            for (int k = 0; k < 5; k++)
            {
                has_been_added[k] = false;
            }

            bool        has_pair_been_found = false;
            List <Card> lst_singles         = new List <Card> {
            };
            List <Card> lst_doubles1        = new List <Card> {
            };
            List <Card> lst_doubles2        = new List <Card> {
            };
            List <Card> lst_triples         = new List <Card> {
            };
            List <Card> lst_quads           = new List <Card> {
            };
            List <Card> mylist = new List <Card> {
            };

            mylist.Capacity = 5;
            for (int i = 2; i < 15; i++)
            {
                //1) decompose hand into singles, doubles, triples, etc lists
                //2) sort singles by rank
                //3) concatenate lists together in order
                //4) this way the hands can be compared to each other easily

                switch (rank_tally[i])
                {
                case 4:
                    for (int k = 0; k < 5; k++)
                    {
                        Card.Rank cr = cards[k].GetRank();
                        if ((int)cr == i && has_been_added[k] == false)
                        {
                            Card.Suit cs = cards[k].GetSuit();
                            Card      cc = new Card(cs, cr);
                            lst_quads.Add(cc);
                            has_been_added[k] = true;
                        }
                    }
                    break;

                case 3:
                    for (int k = 0; k < 5; k++)
                    {
                        Card.Rank cr = cards[k].GetRank();
                        if ((int)cr == i && has_been_added[k] == false)
                        {
                            Card.Suit cs = cards[k].GetSuit();
                            Card      cc = new Card(cs, cr);
                            lst_triples.Add(cc);
                            has_been_added[k] = true;
                        }
                    }
                    break;

                case 2:
                    // TODO: REPLACE WITH METHOD CALL BC ITS BLOCK COPIED BELOW
                    if (has_pair_been_found == false)
                    {
                        has_pair_been_found = true;

                        for (int k = 0; k < 5; k++)
                        {
                            Card.Rank cr = cards[k].GetRank();

                            if ((int)cr == i && has_been_added[k] == false)
                            {
                                Card.Suit cs = cards[k].GetSuit();
                                Card      cc = new Card(cs, cr);
                                lst_doubles1.Add(cc);
                                has_been_added[k] = true;
                            }
                        }
                    }
                    if (has_pair_been_found == true)
                    {
                        for (int k = 0; k < 5; k++)
                        {
                            Card.Rank cr = cards[k].GetRank();

                            if ((int)cr == i && has_been_added[k] == false)
                            {
                                Card.Suit cs = cards[k].GetSuit();
                                Card      cc = new Card(cs, cr);
                                lst_doubles2.Add(cc);
                                has_been_added[k] = true;
                            }
                        }
                    }
                    break;

                case 1:
                    for (int k = 0; k < 5; k++)
                    {
                        Card.Rank cr = cards[k].GetRank();

                        if ((int)cr == i && has_been_added[k] == false)
                        {
                            Card.Suit cs = cards[k].GetSuit();
                            Card      cc = new Card(cs, cr);
                            lst_singles.Add(cc);
                            has_been_added[k] = true;
                        }
                    }

                    break;

                default:
                    break;
                } // end of switch statement
            }     // end of for loop over rank_tally. cards should be split up into separate lists

            for (int i = 0; i < lst_singles.Count; i++)
            {
                mylist.Add(lst_singles[i]);
            }
            // check which double is bigger so they are sorted low to high
            if (lst_doubles1.Count == 2 && lst_doubles2.Count == 2 && (lst_doubles1[0].GetRank() > lst_doubles2[0].GetRank()))
            {
                for (int i = 0; i < lst_doubles2.Count; i++)
                {
                    mylist.Add(lst_doubles2[i]);
                }
                for (int i = 0; i < lst_doubles1.Count; i++)
                {
                    mylist.Add(lst_doubles1[i]);
                }
            }
            else if (lst_doubles1.Count == 2 && lst_doubles2.Count == 2 && (lst_doubles1[0].GetRank() < lst_doubles2[0].GetRank()))
            {
                for (int i = 0; i < lst_doubles1.Count; i++)
                {
                    mylist.Add(lst_doubles1[i]);
                }
                for (int i = 0; i < lst_doubles2.Count; i++)
                {
                    mylist.Add(lst_doubles2[i]);
                }
            }
            else
            {
                for (int i = 0; i < lst_doubles1.Count; i++)
                {
                    mylist.Add(lst_doubles1[i]);
                }
            }
            for (int i = 0; i < lst_triples.Count; i++)
            {
                mylist.Add(lst_triples[i]);
            }
            for (int i = 0; i < lst_quads.Count; i++)
            {
                mylist.Add(lst_quads[i]);
            }
            Hand ret_hand = new Hand(mylist);

            // change this hand's card list to the new sorted cards list
            this.RemoveCards();
            for (int i = 0; i < mylist.Count; i++)
            {
                this.AddCard(mylist[i]);
            }
            this.is_sorted = true;
        }