Beispiel #1
0
 public void CheckHandSetType()
 {
     foreach (var handtype in HandType.Hands(this))
     {
         if (handtype.CheckCards())
         {
             HandType = handtype;
             break;
         }
     }
 }
        public int CompareHands(IHand firstHand, IHand secondHand)
        {
            HandType firstHandType  = GetHandType(firstHand);
            HandType secondHandType = GetHandType(secondHand);

            if (firstHandType > secondHandType)
            {
                return(1);
            }

            if (firstHandType < secondHandType)
            {
                return(-1);
            }

            switch (firstHandType)
            {
            case HandType.HighCard:
                return(CompareHighCardHands(firstHand, secondHand));

            case HandType.OnePair:
                return(CompareOnePairHands(firstHand, secondHand));

            case HandType.TwoPair:
                break;

            case HandType.ThreeOfAKind:
                break;

            case HandType.Straight:
                break;

            case HandType.Flush:
                break;

            case HandType.FullHouse:
                break;

            case HandType.FourOfAKind:
                break;

            case HandType.StraightFlush:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(0);
        }
Beispiel #3
0
        //public string Winner { get; set; }

        public GameResults(List <PokerPlayer> players)
        {
            PlayerNames   = new string[players.Count];
            HandTypes     = new HandType[players.Count];
            HighCardValue = new int[players.Count];

            for (int i = 0; i < players.Count; i++)
            {
                PlayerNames[i] = players[i].Name;
                var handValue = players[i].GetHandValue();
                HighCardValue[i] = handValue.HighCard;
                HandTypes[i]     = handValue.HandType;
            }
        }
Beispiel #4
0
        public GameResults(List <PokerPlayer> players)
        {
            players.Sort((a, b) => a.GetHandValue().HandType.CompareTo(b.GetHandValue().HandType));



            PlayerNames   = new string[players.Count];
            HandTypes     = new HandType[players.Count];
            HighCardValue = new int[players.Count];

            for (int i = 0; i < players.Count; i++)
            {
                PlayerNames[i] = players[i].Name;
                var handValue = players[i].GetHandValue();
                HighCardValue[i] = handValue.HighCard;
                HandTypes[i]     = handValue.HandType;
            }
            Winner = $"the winner is {players[players.Count - 1].Name} with hand {players[players.Count - 1].GetHandValue().HandType}";
        }
Beispiel #5
0
        static string TieBreak(HandType type, Hand hand1, Hand hand2)
        {
            switch (type)
            {
            case HandType.StraightFlush:
            case HandType.Flush:
            case HandType.Straight:
            case HandType.HighCard:
                return(GetHighest(hand1.cards.Last().rank, hand2.cards.Last().rank));

            case HandType.FourOfAKind:
                return(CompareNOfAKind(4, hand1, hand2));

            case HandType.FullHouse:
            case HandType.ThreeOfAKind:
                return(CompareNOfAKind(3, hand1, hand2));

            case HandType.TwoPair:
                int handOneLowPair;
                int handOneHighPair;
                int handTwoLowPair;
                int handTwoHighPair;
                FindPairs(hand1.cards, out handOneLowPair, out handOneHighPair);
                FindPairs(hand2.cards, out handTwoLowPair, out handTwoHighPair);
                var winner = GetHighest(handOneHighPair, handTwoHighPair);
                if (winner == null)
                {
                    winner = GetHighest(handOneLowPair, handTwoLowPair);
                }
                return(winner);

            case HandType.Pair:
                winner = CompareNOfAKind(2, hand1, hand2);
                if (winner == null)
                {
                    winner = GetHighest(hand1.cards.Last().rank, hand2.cards.Last().rank);
                }
                return(winner);

            default:
                return(null);
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            // Get 5 cards
            Hand hand = Get5Cards();
            // Evaluate what kind of hand
            HandType ht1      = hand.Evaluate();
            int      highest1 = hand.cards.Max().rank;

            // Get 5 other cards
            Hand hand2 = Get5Cards();
            // Evaluate type
            HandType ht2      = hand2.Evaluate();
            int      highest2 = hand2.cards.Max().rank;

            // If types are different, better one wins
            if (ht1 > ht2)
            {
                Console.WriteLine("Hand 1 (" + ht1 + (") is better than hand 2 (" + ht2 + ")."));
            }
            else if (ht1 < ht2)
            {
                Console.WriteLine("Hand 2 (" + ht2 + (") is better than hand 1 (" + ht1 + ")."));
            }
            // If types are same, evaluate with a tie breaker

            //Hand winner = TieBreaker(Hand ht1, Hand ht2, int highest1, int highest2);

            /*
             * else if (highest1 > highest2)
             * {
             *  Console.WriteLine("Hand 1 wins with " + hand.cards.Max() + ".");
             *  Console.ReadLine();
             * }
             * else
             * {
             *  Console.WriteLine("Hand 2 wins with highest " + hand2.cards.Max() + ".");
             *  Console.ReadLine();
             * }  */
            Console.ReadLine();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Hand     hand = Get5Cards();
            HandType ht1  = hand.Evaluate();

            Hand     hand2 = Get5Cards();
            HandType ht2   = hand2.Evaluate();

            // If types are different, better one wins
            if (ht1 > ht2)
            {
                Console.WriteLine("Hand 1 is better");
            }
            else if (ht1 < ht2)
            {
                Console.WriteLine("Hand 2 is better");
            }
            else
            // If types are same, evaluate with a tie breaker
            {
                TieBreak(ht1, hand, hand2);
            }
            Console.ReadLine();
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter t for test mode, otherwise use computer generated hands.");
            string input = Console.ReadLine().ToUpper();

            Hand hand;
            Hand hand2;

            if (input == "T")
            {
                hand  = new Hand();
                hand2 = new Hand();
                Console.WriteLine("Enter 5 cards for hand 1");
                for (int i = 0; i < hand.cards.Length; i++)
                {
                    hand.cards[i] = new Card(i + 2, SuitType.Diamonds);
                }
                Console.WriteLine("Enter 5 cards for hand 2");
                for (int i = 0; i < hand2.cards.Length - 1; i++)
                {
                    hand2.cards[i] = new Card(i + 2, SuitType.Hearts);
                }
                hand2.cards[hand2.cards.Length - 1] = new Card(14, SuitType.Hearts);
            }
            else
            {
                // Get 5 cards
                hand  = Get5Cards();
                hand2 = Get5Cards();
            }
            // Evaluate what kind of hand
            HandType ht1 = hand.Evaluate();

            Console.WriteLine("Hand 1 is a: " + ht1);

            // Evaluate type
            HandType ht2 = hand2.Evaluate();

            Console.WriteLine("Hand 2 is a: " + ht2);

            Console.ReadLine();

            // If types are different, better one wins
            if (ht1 > ht2)
            {
                Console.WriteLine("Hand 1 is better: " + ht1);
            }
            else if (ht1 < ht2)
            {
                Console.WriteLine("Hand 2 is better: " + ht2);
            }
            // If types are same, evaluate with a tie breaker
            else
            {
                var winner = TieBreak(ht1, hand, hand2);
                if (winner == null)
                {
                    Console.WriteLine("Tie!");
                }
                else
                {
                    Console.WriteLine("Winner is: " + winner);
                }
            }
        }
Beispiel #9
0
        public int CompareHands(IHand firstHand, IHand secondHand)
        {
            if (this.IsValidHand(firstHand) == false ||
                this.IsValidHand(secondHand) == false)
            {
                throw new InvalidOperationException("Invalid hand given as argument");
            }

            int      result         = 0;
            HandType firstHandType  = this.CheckHandType(firstHand);
            HandType secondHandType = this.CheckHandType(secondHand);

            if (firstHandType > secondHandType)
            {
                result = 1;
            }
            else if (firstHandType < secondHandType)
            {
                result = -1;
            }
            else
            {
                if (firstHandType == HandType.HighCard)
                {
                    result = this.CompareHighCardHands(firstHand, secondHand);
                }
                else if (firstHandType == HandType.OnePair)
                {
                    result = this.CompareOnePairHands(firstHand, secondHand);
                }
                else if (firstHandType == HandType.TwoPair)
                {
                    result = this.CompareTwoPairHands(firstHand, secondHand);
                }
                else if (firstHandType == HandType.ThreeOfAKind)
                {
                    result = this.CompareThreeOfAKindHands(firstHand, secondHand);
                }
                else if (firstHandType == HandType.Straight)
                {
                    result = this.CompareStraightHands(firstHand, secondHand);
                }
                else if (firstHandType == HandType.Flush)
                {
                    result = this.CompareFlushHands(firstHand, secondHand);
                }
                else if (firstHandType == HandType.FullHouse)
                {
                    result = this.CompareFullHouseHands(firstHand, secondHand);
                }
                else if (firstHandType == HandType.FourOfAKind)
                {
                    result = this.CompareFourOfAKindHands(firstHand, secondHand);
                }
                else if (firstHandType == HandType.StraightFlush)
                {
                    result = this.CompareStraightFlushHands(firstHand, secondHand);
                }
            }

            return(result);
        }
Beispiel #10
0
 private static void TieBreak(HandType ht1, Hand hand, Hand hand2)
 {
     throw new NotImplementedException();
 }