예제 #1
0
 public override void update(ref IDictionary <string, int> playerBets, ref Card[] cards, ref IDictionary <string, PlayerHand> playerHands)
 {
     playerHands = this.playerHands;
     if (cards != null) //this happens when all fold before flop
     {
         ca.setCardArray(cards);
         if (HandRanks.Count == 0)
         {
             foreach (string player in playerHands.Keys)
             {
                 ca.setHand(playerHands[player]);
                 HandRanks.Add(player, ca.analyze());
             }
         }
     }
 }
예제 #2
0
파일: Game.cs 프로젝트: Nivlipetz1/WSEP
        private List <PlayingUser> DetermineWinner()
        {
            Dictionary <PlayingUser, CardAnalyzer.HandRank> playerScores = new Dictionary <PlayingUser, CardAnalyzer.HandRank>();

            ca.setCardArray(cards);
            foreach (PlayingUser player in players)
            {
                if (player.GetStatus() != "Fold")
                {
                    ca.setHand(player.GetHand());
                    playerScores.Add(player, ca.analyze());
                    if (playerScores[player] < player.GetBestHand())
                    {
                        player.SetBestHand(playerScores[player]);
                    }
                }
            }

            CardAnalyzer.HandRank minValue = CardAnalyzer.HandRank.HighCard;
            foreach (CardAnalyzer.HandRank rank in playerScores.Values)
            {
                if (rank < minValue)
                {
                    minValue = rank;
                }
            }

            Dictionary <PlayingUser, CardAnalyzer.HandRank> bestPlayerScores = new Dictionary <PlayingUser, CardAnalyzer.HandRank>();

            foreach (PlayingUser player in playerScores.Keys)
            {
                if (playerScores[player] == minValue)
                {
                    bestPlayerScores.Add(player, playerScores[player]);
                }
            }



            List <PlayingUser> winners = new List <PlayingUser>();

            foreach (PlayingUser player in bestPlayerScores.Keys)
            {
                if (winners.Count == 0)
                {
                    winners.Add(player);
                }
                else
                {
                    PlayerHand winner = ca.tieBreaker(minValue, winners.First().GetHand(), player.GetHand());
                    if (winner == null)
                    {
                        winners.Add(player);
                    }
                    else if (winner == player.GetHand())
                    {
                        winners.Clear();
                        winners.Add(player);
                    }
                }
            }
            return(winners);
        }