예제 #1
0
        public List <SidePot> CalculateMainAndSidePots()
        {
            List <SidePot> finalPots = new List <SidePot>();

            int sidePotCounter = 0;

            while (getZeroPotsAmount() < 4)
            {
                int smallestDeck = getMinPotAmountGreaterThanZero();
                List <ApplicationUser> contestedBy = new List <ApplicationUser>();
                SidePot sidePot = new SidePot();

                // In that case, 5 is the max players occupied.
                for (int i = 0; i < 5; i++)
                {
                    if (getPotByIndex(i) >= smallestDeck)
                    {
                        // Saves the original pot of the user
                        if (sidePot.OriginalPotAmount == 0)
                        {
                            sidePot.OriginalPotAmount = getPotByIndex(i);
                        }

                        setPotByIndex(i, getPotByIndex(i) - smallestDeck);
                        contestedBy.Add(getUserByIndex(i));
                    }
                }

                string potName = sidePotCounter == 0 ? "Main Pot" : "Side Pot " + sidePotCounter;
                sidePot.Name        = potName;
                sidePot.PotAmount   = smallestDeck * contestedBy.Count();
                sidePot.ContestedBy = contestedBy;

                finalPots.Add(sidePot);

                sidePotCounter++;
            }


            // Edge case where there's still money in the room's sum pot, in that case we need to return the money to the user owned it.
            if (getZeroPotsAmount() == 4)
            {
                for (int i = 0; i < 5; i++)
                {
                    if (getPotByIndex(i) > 0)
                    {
                        ApplicationUser user = getUserByIndex(i);
                        user.Chips += getPotByIndex(i);
                        setPotByIndex(i, 0);

                        break;
                    }
                }
            }

            return(finalPots);
        }
예제 #2
0
 /// <summary>
 /// Plays the next game round.
 /// </summary>
 /// <returns>
 /// True - if can play another round, False - to end the game
 /// </returns>
 private bool PlayNextRound()
 {
     // In debug mode, check that the total amount of money remaind.
     Invariant.CheckMoneySum(this);
     // Get a new game for the current round.
     game = GetNewGame();
     // Create a new side pot
     pot = new SidePot(players);
     // Increase hand count
     RaiseHandCount();
     // Initialize the game for the current amount of players.
     game.BeginGame(players.Count);
     // Map the playing players and the round order, blind open & blind raise
     mapPlayersAndBlindOpen();
     // finish the blind raise round
     handleFirstRaise();
     // Call derived class to continue the game round
     OnPlayNextRound();
     // find the winner(s) and distribute the earnings
     handleEndGame(game.EndGame());
     // since derived classes and helpers may remove players, verify there are any...
     if (players.Count == 0)
     {
         return(false);
     }
     // In debug mode, check that the total amount of money remaind.
     Invariant.CheckMoneySum(this);
     // move the dealer chip one place
     ++dealer;
     dealer = dealer % players.Count;
     // Check if there are more players
     if (players.Count > 1)
     {
         // Use derive class to determine if another round should be played
         return(WaitForAnotherRound());
     }
     else // there are no more players.
     {
         // Notify the game is over and stop the game
         WaitGameOver(players[0]);
         return(false);
     }
 }