コード例 #1
0
        public MadeHand(byte[] binary)
        {
            Guards.ArgumentHasExactSize(binary, 21, nameof(binary));

            Type       = (HandTypes)binary[0];
            Played     = new Card[5];
            Alternates = null;

            // For each card played
            var alternates = new Dictionary <Card, List <Card> >();

            for (int iPlayed = 0; iPlayed < 5; iPlayed++)
            {
                var iBinaryAtCard = 1 + iPlayed * 4;

                // Add this card
                Played[iPlayed] = new Card(binary[iBinaryAtCard]);

                // Add all three alternates
                var alt = new List <Card>();
                for (int iAlt = 0; iAlt < 3; iAlt++)
                {
                    var altCard = binary[iBinaryAtCard + 1 + iAlt];
                    if (altCard != 0)
                    {
                        alt.Add(new Card(altCard));
                    }
                }
                if (alt.Count > 0)
                {
                    alternates.Add(Played[iPlayed], alt);
                }
            }

            // If we have any alternates, set the dictionary
            if (alternates.Count > 0)
            {
                Alternates = alternates;
            }

            ScoreHand();
        }
コード例 #2
0
        public static MadeHand MakeHand(Card[] cards)
        {
            Guards.Assert(cards.Length >= 5 && cards.Length <= 7, $"Can't make a hand with {cards.Length} cards");

            // Ensure they are sorted
            cards = cards.SortByFace();

            // Group them all by face
            var groups = new HandGrouping(cards);

            var straightFlush = TryMakeStraightFlush(cards);

            if (straightFlush != null)
            {
                return(straightFlush);
            }

            var fourOfAKind = TryMakeFourOfAKind(cards, groups);

            if (fourOfAKind != null)
            {
                return(fourOfAKind);
            }

            var fullHouse = TryMakeFullHouse(cards, groups);

            if (fullHouse != null)
            {
                return(fullHouse);
            }

            var flush = TryMakeFlush(cards);

            if (flush != null)
            {
                return(flush);
            }

            var straight = TryMakeStraight(cards);

            if (straight != null)
            {
                return(straight);
            }

            var threeOfAKind = TryMakeThreeOfAKind(groups);

            if (threeOfAKind != null)
            {
                return(threeOfAKind);
            }

            var twoPair = TryMakeTwoPair(cards, groups);

            if (twoPair != null)
            {
                return(twoPair);
            }

            var pair = TryMakePair(groups);

            if (pair != null)
            {
                return(pair);
            }

            var highCard = TryMakeHighCard(cards);

            if (highCard != null)
            {
                return(highCard);
            }

            throw new InvalidOperationException("Impossible poker hand");
        }
コード例 #3
0
 public TableFinal ToFinal()
 {
     Guards.Assert(Status == TableStatus.Complete, "Table is not complete");
     return(new TableFinal(First.Value, Second.Value, Third.Value, Turn.Value, River.Value));
 }
コード例 #4
0
 private void AssertDeckSize(int plus)
 {
     Guards.Assert(Deck.Size + plus == _preFlopDeckSize, "Deck has unexpectedly changed");
 }
コード例 #5
0
 private void AssertStatus(TableStatus status)
 {
     Guards.Assert(Status == status, $"Unexpected dealing order. Expected {status} but actual is {Status}");
 }
コード例 #6
0
ファイル: Deck.cs プロジェクト: gravical/Gravical.Poker
        public Deck(byte[] binary)
        {
            Guards.ArgumentNotNull(binary, nameof(binary));

            _cards = new Stack <Card>(binary.Select(_ => new Card(_)));
        }