Пример #1
0
        public void HighestInRankWinsOnTiedRank()
        {
            var player1 = new PokerScore(new Rank(RankType.Straight, Value.Six), Value.A);
            var player2 = new PokerScore(new Rank(RankType.Straight, Value.T), Value.J);

            Assert.IsTrue(player1.CompareTo(player2) < 0);
        }
Пример #2
0
        public void HighestInHandBreaksTie()
        {
            var player1 = new PokerScore(new Rank(RankType.FourOfAKind, Value.Five), Value.A);
            var player2 = new PokerScore(new Rank(RankType.FourOfAKind, Value.Five), Value.K);

            Assert.IsTrue(player1.CompareTo(player2) > 0);
        }
Пример #3
0
        public void IdenticalHandsAreADraw()
        {
            var player1 = new PokerScore(new Rank(RankType.Flush, Value.T), Value.Three);
            var player2 = new PokerScore(new Rank(RankType.Flush, Value.T), Value.Three);

            Assert.AreEqual(0, player1.CompareTo(player2));
        }
Пример #4
0
        public void StrongerRankWins()
        {
            var player1 = new PokerScore(new Rank(RankType.Straight, Value.Six), Value.Six);
            var player2 = new PokerScore(new Rank(RankType.HighCard, Value.A), Value.A);

            Assert.IsTrue(player1.CompareTo(player2) > 0);
        }
Пример #5
0
        public void TestStrightFlush()
        {
            PokerScore score = new PokerScore(new List <int> {
                5, 9, 13, 17, 21
            });

            Assert.AreEqual(8, score.score);
            Assert.AreEqual("Straight Flush", score.kind);
        }
Пример #6
0
        public void TestStright()
        {
            PokerScore score = new PokerScore(new List <int> {
                5, 10, 15, 20, 22
            });

            Assert.AreEqual(4, score.score);
            Assert.AreEqual("Straight", score.kind);
        }
Пример #7
0
        public void TestFlush()
        {
            PokerScore score = new PokerScore(new List <int> {
                5, 13, 21, 29, 37
            });

            Assert.AreEqual(5, score.score);
            Assert.AreEqual("Flush", score.kind);
        }
Пример #8
0
        public void TestFull()
        {
            PokerScore score = new PokerScore(new List <int> {
                5, 6, 7, 1, 2
            });

            Assert.AreEqual(6, score.score);
            Assert.AreEqual("Full House", score.kind);
        }
Пример #9
0
        public void TestFour()
        {
            PokerScore score = new PokerScore(new List <int> {
                5, 6, 7, 8, 30
            });

            Assert.AreEqual(7, score.score);
            Assert.AreEqual("Four of a Kind", score.kind);
        }
Пример #10
0
        public void TestThree()
        {
            PokerScore score = new PokerScore(new List <int> {
                1, 2, 3, 6, 30
            });

            Assert.AreEqual(3, score.score);
            Assert.AreEqual("Three of a Kind", score.kind);
        }
Пример #11
0
        public void TestTwoPair()
        {
            PokerScore score = new PokerScore(new List <int> {
                1, 2, 5, 6, 30
            });

            Assert.AreEqual(2, score.score);
            Assert.AreEqual("Two Pairs", score.kind);
        }
Пример #12
0
        public void TestPair()
        {
            PokerScore score = new PokerScore(new List <int> {
                1, 2, 14, 20, 30
            });

            Assert.AreEqual(1, score.score);
            Assert.AreEqual("Pair", score.kind);
        }
Пример #13
0
    /// <summary>
    /// Calculates the winner and returns the index. (-1 = draw, 0 = first player, 1 = second player etc.)
    /// </summary>
    /// <returns>Array index of the winning player, or -1 if draw</returns>
    public int Winner()
    {
        int[] scores = new int[Players.Length];

        for (int p = 0; p < Players.Length; p++)
        {
            Hand hand = Players[p];

            // Check each possible poker set, if it returns a score instead of 0 then finish and
            // continue to the next player.
            if (PokerJudge.ScoreGoed)
            {
                scores[p] = PokerScore.RoyalFlush(hand);
                if (scores[p] > 0)
                {
                    continue;
                }

                scores[p] = PokerScore.StraightFlush(hand);
                if (scores[p] > 0)
                {
                    continue;
                }

                scores[p] = PokerScore.FourOfAKind(hand);
                if (scores[p] > 0)
                {
                    continue;
                }

                scores[p] = PokerScore.FullHouse(hand);
                if (scores[p] > 0)
                {
                    continue;
                }

                scores[p] = PokerScore.Flush(hand);
                if (scores[p] > 0)
                {
                    continue;
                }

                scores[p] = PokerScore.Straight(hand);
                if (scores[p] > 0)
                {
                    continue;
                }
            }

            scores[p] = PokerScore.ThreeOfAKind(hand);
            if (scores[p] > 0)
            {
                continue;
            }

            scores[p] = PokerScore.TwoPair(hand);
            if (scores[p] > 0)
            {
                continue;
            }

            scores[p] = PokerScore.OnePair(hand);
            if (scores[p] > 0)
            {
                continue;
            }

            scores[p] = PokerScore.HighestCard(hand);
        }


        // Now find the player with the highest score.
        if (scores[0] == scores[1])
        {
            return(-1);            // draw
        }
        else if (scores[0] > scores[1])
        {
            return(0);            // player 1 wins
        }
        else
        {
            return(1);            // player 2 wins
        }
    }