示例#1
0
        private void EndGame()
        {
            // Substract the players contributions to the pots from the gains
            foreach (var player in Players)
            {
                player.CurrentGains = 0 - PlayerBet(player);
            }

            // Check if game has multiple players left.
            if (ActivePlayers.Length > 0)
            {
                ProcessPlayerHands();

                ProcessPotWins();
            }
            else
            {
                // No players left. Game cancelled.
                CurrentPhase = Phase.Over;
                return;
            }

            // Update the dealer Id for the next round.
            TournmentLoader.UpdateDealerUserId(Players[CurrentDealerIndex].UserId);

            CurrentPhase = Phase.Over;
        }
示例#2
0
        public HoldemTournament(BotMessager messager) : base(messager)
        {
            CurrentPhase = Phase.Draw;
            Players      = new List <TournamentPlayer>();
            Deck         = new Deck();
            Table        = new List <Card>();
            CurrentBet   = 0;
            pots         = new List <GamePot>();
            pots.Add(new GamePot());

            var playerUserIds = Users.Scores(Score.Tournament).Select(x => x.UserId).Distinct();

            foreach (var playerUserId in playerUserIds)
            {
                Players.Add(new TournamentPlayer(playerUserId));
            }

            var currentDealerUserId = TournmentLoader.GetDealerUserId();

            // Get the current dealers index if userId != 0
            if (currentDealerUserId != 0)
            {
                for (int i = 0; i < Players.Count; i++)
                {
                    if (Players[i].UserId == currentDealerUserId)
                    {
                        CurrentDealerIndex = i;
                        break;
                    }
                }

                CurrentDealerIndex = NextActivePlayerIndex(CurrentDealerIndex, false);
            }
            else
            {
                // Pick a random dealer
                CurrentDealerIndex = new Random().Next(Players.Count);
            }

            // Get the current blind and the number of rounds played so far (plus the current new round).
            int blind       = TournmentLoader.BaseBlind;
            int rounds      = TournmentLoader.GetRoundsPlayed() + 1;
            int totalRounds = rounds;

            // Substract the BlindIncreaseRoundIncrement from the rounds
            rounds = rounds - BlindIncreaseRoundIncrement;

            // Number of times the blind should be raised.
            int increments = 0;

            while (rounds > 0)
            {
                increments++;
                rounds -= BlindIncreaseRoundIncrement;
            }

            // Multiply the blind for each passed increment.
            for (int i = 0; i < increments; i++)
            {
                blind = blind * BlindIncreaseMultiplier;
            }

            // Set the current small and big blinds.
            SmallBlind = blind;
            BigBlind   = SmallBlind * 2;

            // The player after the dealer has the Small Blind.
            int smallBlindIndex = NextActivePlayerIndex(CurrentDealerIndex, false);

            if (totalRounds > 1)
            {
                CurrentPlayerIndex = smallBlindIndex;
            }
            Players[smallBlindIndex].CurrentBet = SmallBlind;

            // The player after the Small Blind has the Big Blind.
            int bigBlindIndex = NextActivePlayerIndex(smallBlindIndex, false);

            Players[bigBlindIndex].CurrentBet = BigBlind;

            // Kirjataan pelaajat.
            string message = "Holdem Turnauksen pelaajat: ";

            for (int j = 0; j < Players.Count; j++)
            {
                var player = Players[j];

                if (player.Active)
                {
                    message += player.Username;

                    if (j == bigBlindIndex)
                    {
                        message += String.Format("(Big Blind - {0}), ", BigBlind);
                    }
                    else if (j == smallBlindIndex)
                    {
                        message += String.Format("(Small Blind - {0}), ", SmallBlind);
                    }
                    else if (j == CurrentDealerIndex)
                    {
                        message += "(Dealer), ";
                    }
                    else
                    {
                        message += ", ";
                    }
                }
            }

            message = message.Substring(0, message.Length - 2);
            Say(message);

            foreach (var player in ActivePlayers)
            {
                Pot.PlayerPots.Add(new PlayerPot(player.UserId, player.CurrentBet));

                player.Cards    = new Card[2];
                player.Cards[0] = Deck.Draw();
                player.Cards[1] = Deck.Draw();

                // Log games played
                var user = Users.Get(player.UserId);

                user.UpdateScore(
                    new Score(user.UserId, Score.Tournament).Started()
                    );

                // Report cards to the player as a private message
                message  = "------------------------------------------------";
                message += player.Cards[0].Name;
                message += " | ";
                message += player.Cards[1].Name;

                Bot.Say(player.Username, message);
            }

            InformOfPlayerTurn();

            // Set the current bet.
            CurrentBet = BigBlind;
        }