Ejemplo n.º 1
0
        public Table(Deck deck, TableStatus status, byte[] community)
        {
            Guards.ArgumentNotNull(deck, nameof(deck));
            Guards.ArgumentSuccess(status.IsValid(), nameof(status));
            Guards.ArgumentHasExactSize(community, 5, nameof(community));

            this.Deck   = deck;
            this.Status = status;
            this.First  = community[0] == 0 ? (Card?)null : new Card(community[0]);
            this.Second = community[1] == 0 ? (Card?)null : new Card(community[1]);
            this.Third  = community[2] == 0 ? (Card?)null : new Card(community[2]);
            this.Turn   = community[3] == 0 ? (Card?)null : new Card(community[3]);
            this.River  = community[4] == 0 ? (Card?)null : new Card(community[4]);

            var duplicate = community.Where(_ => _ != 0).GroupBy(_ => _).Any(_ => _.Count() > 1);

            Guards.ArgumentSuccess(!duplicate, nameof(community), "Duplicate card found");

            var mismatch = $"Community cards don't match table status: {status}, ";

            switch (status)
            {
            case TableStatus.BeforeFlop:
                Guards.ArgumentSuccess(First == null, nameof(community), mismatch + "First");
                Guards.ArgumentSuccess(Second == null, nameof(community), mismatch + "Second");
                Guards.ArgumentSuccess(Third == null, nameof(community), mismatch + "Third");
                Guards.ArgumentSuccess(Turn == null, nameof(community), mismatch + "Turn");
                Guards.ArgumentSuccess(River == null, nameof(community), mismatch + "River");
                break;

            case TableStatus.BeforeTurn:
                Guards.ArgumentSuccess(First != null, nameof(community), mismatch + "First");
                Guards.ArgumentSuccess(Second != null, nameof(community), mismatch + "Second");
                Guards.ArgumentSuccess(Third != null, nameof(community), mismatch + "Third");
                Guards.ArgumentSuccess(Turn == null, nameof(community), mismatch + "Turn");
                Guards.ArgumentSuccess(River == null, nameof(community), mismatch + "River");
                break;

            case TableStatus.BeforeRiver:
                Guards.ArgumentSuccess(First != null, nameof(community), mismatch + "First");
                Guards.ArgumentSuccess(Second != null, nameof(community), mismatch + "Second");
                Guards.ArgumentSuccess(Third != null, nameof(community), mismatch + "Third");
                Guards.ArgumentSuccess(Turn != null, nameof(community), mismatch + "Turn");
                Guards.ArgumentSuccess(River == null, nameof(community), mismatch + "River");
                break;

            case TableStatus.Complete:
                Guards.ArgumentSuccess(First != null, nameof(community), mismatch + "First");
                Guards.ArgumentSuccess(Second != null, nameof(community), mismatch + "Second");
                Guards.ArgumentSuccess(Third != null, nameof(community), mismatch + "Third");
                Guards.ArgumentSuccess(Turn != null, nameof(community), mismatch + "Turn");
                Guards.ArgumentSuccess(River != null, nameof(community), mismatch + "River");
                break;
            }
        }
Ejemplo n.º 2
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();
        }