Beispiel #1
0
 public void DealTheFlop()
 {
     AssertStatus(TableStatus.BeforeFlop);
     Guards.Assert(Deck.Size >= 9, "There are not enough cards left in the deck to deal a table");
     _preFlopDeckSize = Deck.Size;
     Deck.DrawCard();
     First  = Deck.DrawCard();
     Second = Deck.DrawCard();
     Third  = Deck.DrawCard();
     Status = TableStatus.BeforeTurn;
 }
Beispiel #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");
        }
Beispiel #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));
 }
Beispiel #4
0
 private void AssertDeckSize(int plus)
 {
     Guards.Assert(Deck.Size + plus == _preFlopDeckSize, "Deck has unexpectedly changed");
 }
Beispiel #5
0
 private void AssertStatus(TableStatus status)
 {
     Guards.Assert(Status == status, $"Unexpected dealing order. Expected {status} but actual is {Status}");
 }