Beispiel #1
0
        public void StraightFlush_vs_StraightFlush()
        {
            var detector = new WinnerDetector();

            detector.AddPlayer("me1", new List <Card>()
            {
                new Card(Suit.Spades, Rank.Two),
                new Card(Suit.Spades, Rank.Three),

                new Card(Suit.Spades, Rank.Four),
                new Card(Suit.Spades, Rank.Five),
                new Card(Suit.Spades, Rank.Six),
                new Card(Suit.Diamonds, Rank.Jack),
                new Card(Suit.Hearts, Rank.Queen)
            });

            detector.AddPlayer("me2", new List <Card>()
            {
                new Card(Suit.Spades, Rank.Seven),
                new Card(Suit.Spades, Rank.Eight),

                new Card(Suit.Spades, Rank.Four),
                new Card(Suit.Spades, Rank.Five),
                new Card(Suit.Spades, Rank.Six),
                new Card(Suit.Diamonds, Rank.Jack),
                new Card(Suit.Hearts, Rank.Queen)
            });

            var winner = detector.GetWinners().Single();

            Assert.AreEqual("me2", winner.UserId);
            Assert.AreEqual((int)PokerScores.StraightFlush, winner.PokerHand.Score);
        }
Beispiel #2
0
        public void Quads_vs_Quads_Kicker()
        {
            var detector = new WinnerDetector();

            detector.AddPlayer("me1", new List <Card>()
            {
                new Card(Suit.Spades, Rank.Jack),
                new Card(Suit.Hearts, Rank.Ten),

                new Card(Suit.Hearts, Rank.Queen),
                new Card(Suit.Spades, Rank.Queen),
                new Card(Suit.Clubs, Rank.Queen),
                new Card(Suit.Diamonds, Rank.Queen),
                new Card(Suit.Clubs, Rank.Two)
            });

            detector.AddPlayer("me2", new List <Card>()
            {
                new Card(Suit.Clubs, Rank.King),
                new Card(Suit.Diamonds, Rank.Nine),

                new Card(Suit.Hearts, Rank.Queen),
                new Card(Suit.Spades, Rank.Queen),
                new Card(Suit.Clubs, Rank.Queen),
                new Card(Suit.Diamonds, Rank.Queen),
                new Card(Suit.Clubs, Rank.Two)
            });
            var winner = detector.GetWinners().Single();

            Assert.AreEqual("me2", winner.UserId);
            Assert.AreEqual((int)PokerScores.Quads, winner.PokerHand.Score);
        }
Beispiel #3
0
        public void Quads_vs_Quads_SplitPot()
        {
            var detector = new WinnerDetector();

            detector.AddPlayer("me1", new List <Card>()
            {
                new Card(Suit.Spades, Rank.King),
                new Card(Suit.Hearts, Rank.Ten),

                new Card(Suit.Hearts, Rank.Queen),
                new Card(Suit.Spades, Rank.Queen),
                new Card(Suit.Clubs, Rank.Queen),
                new Card(Suit.Diamonds, Rank.Queen),
                new Card(Suit.Clubs, Rank.Two)
            });

            detector.AddPlayer("me2", new List <Card>()
            {
                new Card(Suit.Clubs, Rank.King),
                new Card(Suit.Diamonds, Rank.Nine),

                new Card(Suit.Hearts, Rank.Queen),
                new Card(Suit.Spades, Rank.Queen),
                new Card(Suit.Clubs, Rank.Queen),
                new Card(Suit.Diamonds, Rank.Queen),
                new Card(Suit.Clubs, Rank.Two)
            });


            var winners = detector.GetWinners().ToList();

            Assert.AreEqual(2, winners.Count);
            Assert.AreEqual((int)PokerScores.Quads, winners[0].PokerHand.Score);
            Assert.AreEqual((int)PokerScores.Quads, winners[1].PokerHand.Score);
        }
Beispiel #4
0
        public void TwoPairs_vs_Pair()
        {
            var detector = new WinnerDetector();

            detector.AddPlayer("me1", new List <Card>()
            {
                new Card(Suit.Clubs, Rank.King),
                new Card(Suit.Diamonds, Rank.Ten),
                new Card(Suit.Hearts, Rank.Queen),
                new Card(Suit.Clubs, Rank.Ten),
                new Card(Suit.Clubs, Rank.Queen),
            });
            detector.AddPlayer("me2", new List <Card>()
            {
                new Card(Suit.Clubs, Rank.Three),
                new Card(Suit.Diamonds, Rank.Seven),
                new Card(Suit.Hearts, Rank.Ten),
                new Card(Suit.Clubs, Rank.Ten),
                new Card(Suit.Clubs, Rank.Two),
            });
            var winner = detector.GetWinners().Single();

            Assert.AreEqual("me1", winner.UserId);
            Assert.AreEqual((int)PokerScores.TwoPairs, winner.PokerHand.Score);
        }
Beispiel #5
0
        public void Flush_vs_Flush()
        {
            var detector = new WinnerDetector();

            detector.AddPlayer("me1", new List <Card>()
            {
                new Card(Suit.Hearts, Rank.Five),
                new Card(Suit.Hearts, Rank.Queen),

                new Card(Suit.Hearts, Rank.Eight),
                new Card(Suit.Hearts, Rank.Three),
                new Card(Suit.Hearts, Rank.Jack),
                new Card(Suit.Hearts, Rank.Ten),
                new Card(Suit.Hearts, Rank.Two)
            });

            detector.AddPlayer("me2", new List <Card>()
            {
                new Card(Suit.Hearts, Rank.Nine),
                new Card(Suit.Hearts, Rank.King),

                new Card(Suit.Hearts, Rank.Eight),
                new Card(Suit.Hearts, Rank.Three),
                new Card(Suit.Hearts, Rank.Jack),
                new Card(Suit.Hearts, Rank.Ten),
                new Card(Suit.Hearts, Rank.Two)
            });


            var winner = detector.GetWinners().Single();

            Assert.AreEqual("me2", winner.UserId);
            Assert.AreEqual((int)PokerScores.Flush, winner.PokerHand.Score);
        }
Beispiel #6
0
        public void FullHouse_vs_Flush()
        {
            var detector = new WinnerDetector();

            detector.AddPlayer("me1", new List <Card>()
            {
                new Card(Suit.Clubs, Rank.Ace),
                new Card(Suit.Diamonds, Rank.Ace),
                new Card(Suit.Spades, Rank.Ace),
                new Card(Suit.Clubs, Rank.Ten),
                new Card(Suit.Spades, Rank.Ten),
                new Card(Suit.Spades, Rank.King)
            });
            detector.AddPlayer("me2", new List <Card>()
            {
                new Card(Suit.Clubs, Rank.Ace),
                new Card(Suit.Clubs, Rank.Seven),
                new Card(Suit.Clubs, Rank.King),
                new Card(Suit.Clubs, Rank.Ten),
                new Card(Suit.Clubs, Rank.Seven)
            });
            var winner = detector.GetWinners().Single();

            Assert.AreEqual("me1", winner.UserId);
            Assert.AreEqual((int)PokerScores.FullHouse, winner.PokerHand.Score);
        }
Beispiel #7
0
        public void Set_vs_Set_when_hand_has_various_sets()
        {
            var detector = new WinnerDetector();

            detector.AddPlayer("me1", new List <Card>()
            {
                new Card(Suit.Spades, Rank.Three),
                new Card(Suit.Hearts, Rank.Three),

                new Card(Suit.Spades, Rank.Three),
                new Card(Suit.Spades, Rank.Two),
                new Card(Suit.Spades, Rank.Five),
                new Card(Suit.Diamonds, Rank.Five),
                new Card(Suit.Clubs, Rank.Five)
            });

            detector.AddPlayer("me2", new List <Card>()
            {
                new Card(Suit.Clubs, Rank.Two),
                new Card(Suit.Diamonds, Rank.Two),

                new Card(Suit.Spades, Rank.Three),
                new Card(Suit.Spades, Rank.Two),
                new Card(Suit.Spades, Rank.Five),
                new Card(Suit.Diamonds, Rank.Five),
                new Card(Suit.Clubs, Rank.Five)
            });
            var winner = detector.GetWinners().Single();

            Assert.AreEqual("me1", winner.UserId);
            Assert.AreEqual((int)PokerScores.Set, winner.PokerHand.Score);
        }
        public void test()
        {
            var detector = new WinnerDetector();

            detector.AddPlayer("me1", Cards.TwoPairsJacksFives());
            detector.AddPlayer("me2", Cards.TwoPairsJacksSixes());
            var winners = detector.GetWinners(100).ToList();

            Assert.AreEqual(1, winners.Count);
            Assert.AreEqual("me2", winners[0].UserId);
            Assert.AreEqual(100, winners[0].Prize);
            Assert.AreEqual(typeof(TwoPairs), winners[0].PokerHand.GetType());
        }
Beispiel #9
0
        public void two()
        {
            var detector = new WinnerDetector();

            detector.AddPlayer("me1", new List <Card>()
            {
                new Card(Suit.Spades, Rank.King),
                new Card(Suit.Hearts, Rank.Queen),

                new Card(Suit.Spades, Rank.King),
                new Card(Suit.Spades, Rank.Queen),
                new Card(Suit.Spades, Rank.Five),
                new Card(Suit.Diamonds, Rank.Six),
                new Card(Suit.Clubs, Rank.Two)
            });
            detector.AddPlayer("me2", new List <Card>()
            {
                new Card(Suit.Clubs, Rank.King),
                new Card(Suit.Diamonds, Rank.Queen),

                new Card(Suit.Spades, Rank.King),
                new Card(Suit.Spades, Rank.Queen),
                new Card(Suit.Spades, Rank.Five),
                new Card(Suit.Diamonds, Rank.Six),
                new Card(Suit.Clubs, Rank.Two)
            });
            var winners = detector.GetWinners(100).ToList();

            Assert.AreEqual(2, winners.Count);
            Assert.AreEqual(winners[0].Prize, 50);
            Assert.AreEqual(winners[0].PokerHand.GetType(), typeof(TwoPairs));
            Assert.AreEqual(winners[1].Prize, 50);
            Assert.AreEqual(winners[1].PokerHand.GetType(), typeof(TwoPairs));
            var ids = winners.Select(x => x.UserId).ToList();

            Assert.Contains("me1", ids);
            Assert.Contains("me2", ids);
        }
Beispiel #10
0
        public void HighCard_vs_HighCard()
        {
            var detector = new WinnerDetector();

            detector.AddPlayer("me1", new List <Card>()
            {
                new Card(Suit.Clubs, Rank.King),
                new Card(Suit.Diamonds, Rank.Seven),
                new Card(Suit.Hearts, Rank.Queen),
                new Card(Suit.Clubs, Rank.Ten),
                new Card(Suit.Clubs, Rank.Two),
            });
            detector.AddPlayer("me2", new List <Card>()
            {
                new Card(Suit.Clubs, Rank.Three),
                new Card(Suit.Diamonds, Rank.Seven),
                new Card(Suit.Hearts, Rank.Queen),
                new Card(Suit.Clubs, Rank.Ten),
                new Card(Suit.Clubs, Rank.Two),
            });
            var winner = detector.GetWinners().Single();

            Assert.AreEqual("me1", winner.UserId);
        }
Beispiel #11
0
 private void NextTurn(int currentPosition)
 {
     if (State.IsAllExceptOneAreFold())
     {
         var winner = State.Players.Values.Single(x => !x.Fold);
         Apply(new GameFinished
         {
             Id      = State.TableId,
             GameId  = State.GameId,
             Winners = new List <WinnerInfo> {
                 new WinnerInfo(winner, State.CurrentBidding.GetBank())
             },
         });
         CreateGame(GenerateGameId());
     }
     else
     {
         if (CheckBiddingFinished())
         {
             Apply(new BiddingFinished
             {
                 Id     = State.TableId,
                 GameId = State.GameId,
                 Bank   = State.CurrentBidding.GetBank()
             });
             if (State.Deck.Count == 5)
             {
                 var detector = new WinnerDetector();
                 foreach (var player in State.Players.Values)
                 {
                     var cards = new List <Card>(player.Cards);
                     cards.AddRange(State.Deck);
                     detector.AddPlayer(player.UserId, cards);
                 }
                 var bank    = State.CurrentBidding.GetBank();
                 var winners = detector.GetWinners(bank);
                 Apply(new GameFinished
                 {
                     Id      = State.TableId,
                     Winners = winners.Select(
                         winner =>
                         new WinnerInfo(winner.UserId, State.JoinedPlayers[winner.UserId].Position,
                                        winner.Prize, winner.PokerHand.Score)).ToList(),
                     GameId = State.GameId
                 });
                 //TODO: check for players with not enough money and dissconnect them
                 CreateGame(GenerateGameId());
                 return;
             }
             else
             {
                 var cards = new List <Card>
                 {
                     State.Pack.TakeRandom()
                 };
                 if (!State.Deck.Any())
                 {
                     cards.Add(State.Pack.TakeRandom());
                     cards.Add(State.Pack.TakeRandom());
                 }
                 Apply(new DeckDealed
                 {
                     Id     = State.TableId,
                     GameId = State.GameId,
                     Cards  = cards
                 });
                 currentPosition = State.Dealer.Value;
             }
         }
         Apply(new NextPlayerTurned
         {
             Id             = State.TableId,
             GameId         = State.GameId,
             Player         = State.GetPlayerInfo(State.GetNextNotFoldPlayer(currentPosition)),
             MinBet         = State.GetMinBet(),
             MaxRaisedValue = State.MaxRaisedValue
         });
     }
 }
Beispiel #12
0
 public static IEnumerable <WinnerResult> GetWinners(this WinnerDetector source)
 {
     return(source.GetWinners(100));
 }