예제 #1
0
        PlayerList QuickSortBestHand(PlayerList myPlayers)
        {
            Player pivot;
            Random ran = new Random();

            if (myPlayers.Count() <= 1)
            {
                return(myPlayers);
            }
            pivot = myPlayers[ran.Next(myPlayers.Count())];
            myPlayers.Remove(pivot);

            var less    = new PlayerList();
            var greater = new PlayerList();

            // Assign values to less or greater list
            foreach (Player player in myPlayers)
            {
                if (HandCombination.getBestHand(new Hand(player.getHand())) > HandCombination.getBestHand(new Hand(pivot.getHand())))
                {
                    greater.Add(player);
                }
                else if (HandCombination.getBestHand(new Hand(player.getHand())) <= HandCombination.getBestHand(new Hand(pivot.getHand())))
                {
                    less.Add(player);
                }
            }
            // Recurse for less and greaterlists
            var list = new PlayerList();

            list.AddRange(QuickSortBestHand(greater));
            list.Add(pivot);
            list.AddRange(QuickSortBestHand(less));
            return(list);
        }
예제 #2
0
        //showdown code!
        public void ShowDown()
        {
            //creating sidepots
            if (CreateSidePots())
            {
                mainPot.getPlayersInPot().Sort();

                for (int i = 0; i < mainPot.getPlayersInPot().Count - 1; i++)
                {
                    if (mainPot.getPlayersInPot()[i].AmountInPot != mainPot.getPlayersInPot()[i + 1].AmountInPot)
                    {
                        PlayerList tempPlayers = new PlayerList();
                        for (int j = mainPot.getPlayersInPot().Count - 1; j > i; j--)
                        {
                            tempPlayers.Add(mainPot.getPlayersInPot()[j]);
                        }
                        int potSize = (mainPot.getPlayersInPot()[i + 1].AmountInPot - mainPot.getPlayersInPot()[i].AmountInPot) * tempPlayers.Count;
                        mainPot.Amount -= potSize;
                        sidePots.Add(new Pot(potSize, tempPlayers));
                    }
                }
            }
            //awarding mainpot
            PlayerList bestHandList = new PlayerList();
            List <int> Winners      = new List <int>();

            bestHandList = QuickSortBestHand(new PlayerList(mainPot.getPlayersInPot()));
            for (int i = 0; i < bestHandList.Count; i++)
            {
                for (int j = 0; j < this.getPlayers().Count; j++)
                {
                    if (players[j] == bestHandList[i])
                    {
                        Winners.Add(j);
                    }
                }
                if (HandCombination.getBestHand(new Hand(bestHandList[i].getHand())) != HandCombination.getBestHand(new Hand(bestHandList[i + 1].getHand())))
                {
                    break;
                }
            }
            mainPot.Amount /= Winners.Count;
            if (Winners.Count > 1)
            {
                for (int i = 0; i < this.getPlayers().Count; i++)
                {
                    if (Winners.Contains(i))
                    {
                        currentIndex = i;
                        players[i].CollectMoney(mainPot);
                        winnermessage += players[i].Name + ", ";
                    }
                }
                winnermessage += Environment.NewLine + " split the pot.";
            }
            else
            {
                currentIndex = Winners[0];
                players[currentIndex].CollectMoney(mainPot);
                winnermessage = players[currentIndex].Message;
            }
            //awarding sidepots
            for (int i = 0; i < sidePots.Count; i++)
            {
                List <int> sidePotWinners = new List <int>();
                for (int x = 0; x < bestHandList.Count; x++)
                {
                    for (int j = 0; j < this.getPlayers().Count; j++)
                    {
                        if (players[j] == bestHandList[x] && sidePots[i].getPlayersInPot().Contains(bestHandList[x]))
                        {
                            sidePotWinners.Add(j);
                        }
                    }
                    if (HandCombination.getBestHand(new Hand(bestHandList[x].getHand())) != HandCombination.getBestHand(new Hand(bestHandList[x + 1].getHand())) && sidePotWinners.Count != 0)
                    {
                        break;
                    }
                }
                sidePots[i].Amount /= sidePotWinners.Count;
                for (int j = 0; j < this.getPlayers().Count; j++)
                {
                    if (sidePotWinners.Contains(j))
                    {
                        currentIndex = j;
                        players[j].CollectMoney(sidePots[i]);
                    }
                }
            }
        }