예제 #1
0
파일: Game.cs 프로젝트: wiz0u/PokerBot
        private async Task StartTurn()
        {
            ShuffleCards();
            Board.Clear();
            StartingBet = 0;
            foreach (var player in Players)
            {
                player.Cards.Clear();
                player.Bet    = 0;
                player.Status = Player.PlayerStatus.DidNotTalk;
            }
            foreach (var player in Players)
            {
                player.Cards.Add(Deck.Dequeue());
            }
            foreach (var player in Players)
            {
                player.Cards.Add(Deck.Dequeue());
            }
            int smallIdx = (ButtonIdx + 1) % Players.Count;
            int bigIdx   = (smallIdx + 1) % Players.Count;

            Players[smallIdx].SetBet(BigBlind / 2);
            Players[bigIdx].SetBet(BigBlind);
            CurrentBet    = BigBlind;
            BigBet        = BigBlind;
            CurrentPlayer = Players[(bigIdx + 1) % Players.Count];
            TraceStatus();
            LastPlayerToRaise = CurrentPlayer;
            lastMsg           = await Telegram.SendMsg(Chat,
                                                       lastMsgText = "Nouveau tour, nouvelles cartes!\n" +
                                                       $"{Players[smallIdx]}: petite blind. {Players[bigIdx]}: grosse blind.\n" +
                                                       $"C'est à {CurrentPlayer.MarkDown()} de parler",
                                                       GetChoices());
        }
예제 #2
0
파일: Game.cs 프로젝트: wiz0u/PokerBot
 private async Task OnCommandRaise(Message msg, string arguments)
 {
     if (status != Status.WaitForBets)
     {
         await Telegram.SendMsg(Chat, "Commande valide seulement pendant les enchères");
     }
     else if (msg.From.Id != CurrentPlayer.User.Id)
     {
         await Telegram.SendMsg(Chat, $"Ce n'est pas votre tour, c'est à {CurrentPlayer.MarkDown()} de parler");
     }
     else
     {
         if (!msg.Text.StartsWith("/allin"))
         {
             await DoChoice(CallbackWord.allin);
         }
         else
         {
             if (!double.TryParse(arguments, out double relanceBB))
             {
                 await Telegram.SendMsg(Chat, "Montant de relance invalide");
             }
             else
             {
                 int relance = (int)(relanceBB * BigBlind);
                 if (relance < CurrentBet + BigBet - CurrentPlayer.Bet)
                 {
                     await Telegram.SendMsg(Chat, $"Vous devez relancer de +{BB(CurrentBet + BigBet - CurrentPlayer.Bet)} au minimum");
                 }
                 else if (!CurrentPlayer.CanBet(CurrentPlayer.Bet + relance))
                 {
                     await Telegram.SendMsg(Chat, "Vous n'avez pas assez pour relancer d'autant");
                 }
                 else
                 {
                     BigBet = CurrentPlayer.Bet + relance - CurrentBet;
                     await DoChoice(CallbackWord.raise);
                 }
             }
         }
     }
 }
예제 #3
0
파일: Game.cs 프로젝트: wiz0u/PokerBot
        private async Task DoChoice(CallbackWord choice)
        {
            string text = CurrentPlayer.ToString();

            switch (choice)
            {
            case CallbackWord.call:
                text += " *suit*.";
                CurrentPlayer.SetBet(CurrentBet);
                break;

            case CallbackWord.raise:
                LastPlayerToRaise = CurrentPlayer;
                CurrentBet       += BigBet;
                text += $" *relance de {BB(CurrentBet - CurrentPlayer.Bet)}* !";
                CurrentPlayer.SetBet(CurrentBet);
                break;

            case CallbackWord.allin:
                int playerBet = CurrentPlayer.Bet + CurrentPlayer.Stack;
                //todo
                if (playerBet > CurrentBet)
                {
                    LastPlayerToRaise = CurrentPlayer;
                    CurrentBet        = playerBet;
                }
                text += $" *allin de {BB(CurrentBet - CurrentPlayer.Bet)}* !";
                CurrentPlayer.SetBet(playerBet);
                break;

            case CallbackWord.fold:
                text += " *passe*.";
                CurrentPlayer.Status = Player.PlayerStatus.Folded;
                break;

            case CallbackWord.check:
                text += " *parle*.";
                break;

            default:
                break;
            }
            await RemoveLastMessageButtons();

            var pot = Players.Sum(p => p.Bet);

            if (PlayersInTurn.Count() == 1)
            {
                var winner = PlayersInTurn.Single();
                winner.Stack += pot;
                foreach (var player in Players)
                {
                    player.Bet = 0;
                }
                await Telegram.SendMsg(Chat, $"{text}\n{winner.MarkDown()} remporte le pot de {BB(pot)}");

                ButtonIdx   = (ButtonIdx + 1) % Players.Count;
                runNextTurn = Task.Delay(7000).ContinueWith(_ => StartTurn());
            }
            else
            {
                var stillBetting = NextPlayer();
#if ABATTAGE_IMMEDIAT
                DistributeBoard(); DistributeBoard(); DistributeBoard(); stillBetting = false;
#endif
                if (stillBetting)
                {
                    text   += $" La mise est à {BB(CurrentBet - StartingBet)}\nC'est au tour de {CurrentPlayer.MarkDown()} de parler";
                    lastMsg = await Telegram.SendMsg(Chat, lastMsgText = text, GetChoices());
                }
                else if (Board.Count == 5)
                {
                    text += $" Abattage des cartes !\nBoard: ";
                    text += string.Join("  ", Board);
                    var hands = PlayersInTurn.Select(player => (player, hand: Card.BestHand(Board.Concat(player.Cards)))).ToList();
                    foreach (var(player, hand) in hands)
                    {
                        text += $"\n{string.Join("  ", player.Cards)} : {hand.descr} pour {player}";
                    }
                    var winners = DetermineWinners(hands);
                    if (winners.Count > 1)
                    {
                        text += $"\nEgalité entre {string.Join(" et ", winners)} ! Partage du pot: {BB(pot)}";
                        foreach (var player in winners)
                        {
                            player.Stack += pot / winners.Count;
                        }
                    }
                    else
                    {
                        text             += $"\n{winners[0].MarkDown()} remporte le pot de {BB(pot)} !";
                        winners[0].Stack += pot;
                    }
                    await Telegram.SendMsg(Chat, text);

                    ButtonIdx   = (ButtonIdx + 1) % Players.Count;
                    runNextTurn = Task.Delay(10000).ContinueWith(_ => StartTurn());
                }
                else
                {
                    text             += $" Le tour d'enchères est terminé. Pot: {BB(pot)}\n{DistributeBoard()}: ";
                    text             += string.Join("  ", Board);
                    StartingBet       = CurrentBet;
                    BigBet            = BigBlind;
                    LastPlayerToRaise = null;
                    CurrentPlayer     = Players[ButtonIdx];
                    NextPlayer();
                    LastPlayerToRaise = CurrentPlayer;
                    text   += $"\nC'est au tour de {CurrentPlayer.MarkDown()} de parler";
                    lastMsg = await Telegram.SendMsg(Chat, lastMsgText = text, GetChoices());
                }
                TraceStatus();
            }
        }