Esempio n. 1
0
 private void SetWinner()
 {
     WinningPlayers = new List <IPlayer>();
     WinningHand    = Hands.HighestCard;
     foreach (var player in Players.Where(p => !p.Folded))
     {
         var x = Players.Where(p => !p.Folded);
         //De current hand setten bij de activePlayer
         if (player.GetType() == typeof(ActivePlayer))
         {
             ActivePlayer p = player as ActivePlayer;
             p.SetCurrentHand();
         }
         if (player.CurrentHand > WinningHand)
         {
             WinningHand = player.CurrentHand;
         }
     }
     foreach (var player in Players.Where(p => p.CurrentHand == WinningHand && !p.Folded).ToList())
     {
         if (WinningPlayers.Count != 0)
         {
             if (player.WinningCards.OrderBy(c => c.FaceValue).LastOrDefault().FaceValue >
                 WinningPlayers[0].WinningCards.OrderBy(c => c.FaceValue).LastOrDefault().FaceValue)
             {
                 foreach (var p in WinningPlayers)
                 {
                     p.Winner = false;
                 }
                 WinningPlayers = new List <IPlayer>();
                 player.Winner  = true;
                 WinningPlayers.Add(player);
             }
             else if (player.WinningCards.OrderBy(c => c.FaceValue).LastOrDefault().FaceValue ==
                      WinningPlayers[0].WinningCards.OrderBy(c => c.FaceValue).LastOrDefault().FaceValue)
             {
                 player.Winner = true;
                 WinningPlayers.Add(player);
             }
         }
         else
         {
             player.Winner = true;
             WinningPlayers.Add(player);
         }
     }
 }
Esempio n. 2
0
        //creates winnerList
        //TODO: can this be written more cleanly?
        public void ShowdownSinglePot()
        {
            foreach (var p in this.PlayersInHand)
            {
                p.HandForShowdown = new HandForEval(this.BoardCards.Concat(p.HoleCards).ToArray());
            }

            int result, topPlayerIdx;

            topPlayerIdx = 0;
            bool checkTies = false;

            //find the player with the best hand
            for (int i = 1; i < PlayersInHand.Count; i++)
            {
                result = PlayersInHand[i].HandForShowdown.CompareTo(
                    PlayersInHand[topPlayerIdx].HandForShowdown);
                switch (result)
                {
                case 1:
                    topPlayerIdx = i; break;

                //TODO: Test these
                case 0:
                    checkTies = true; break;

                case -1:
                    break;
                }
            }
            this.WinningPlayers.Add(PlayersInHand[topPlayerIdx]);
            this.PlayersInHand.Remove(PlayersInHand[topPlayerIdx]);

            if (checkTies)
            {
                foreach (var p in PlayersInHand)
                {
                    if (WinningPlayers[0].HandForShowdown.CompareTo(p.HandForShowdown) == 0)
                    {
                        WinningPlayers.Add(p);
                    }
                }
            }
        }