Exemple #1
0
        public override void StartRound(StartRoundContext context)
        {
            this.UpdateCommonRow(context.CurrentPot);

            ConsoleHelper.WriteOnConsole(this.row + 1, this.width - 11, context.RoundType + "   ");
            base.StartRound(context);
        }
        public override PlayerAction GetTurn(GetTurnContext context)
        {
            this.UpdateCommonRow(context.CurrentPot);
            ConsoleHelper.WriteOnConsole(this.row + 1, 2, context.MoneyLeft + "   ");

            // HEREEEEEEEEEEeeee
            //System.Threading.Thread.Sleep(1000);
            var action = base.GetTurn(context);

            ConsoleHelper.WriteOnConsole(this.row + 2, 2, new string(' ', this.width - 3));

            var lastAction = action.Type + (action.Type == PlayerActionType.Fold
                ? string.Empty
                : "(" + (action.Money + ((context.MoneyToCall < 0) ? 0 : context.MoneyToCall) + ")"));

            ConsoleHelper.WriteOnConsole(this.row + 3, 2, "Last action: " + lastAction + "            ");

            var moneyAfterAction = action.Type == PlayerActionType.Fold
                ? context.MoneyLeft
                : context.MoneyLeft - action.Money - context.MoneyToCall;

            ConsoleHelper.WriteOnConsole(this.row + 1, 2, moneyAfterAction + "   ");

            return(action);
        }
Exemple #3
0
        private void DrawPlayerOptions(int moneyToCall)
        {
            var col = 2;

            ConsoleHelper.WriteOnConsole(this.row + 2, col, "Select action: [");
            col += 16;
            ConsoleHelper.WriteOnConsole(this.row + 2, col, "C", ConsoleColor.Yellow);
            col++;
            ConsoleHelper.WriteOnConsole(this.row + 2, col, "]heck/[");
            col += 7;
            ConsoleHelper.WriteOnConsole(this.row + 2, col, "C", ConsoleColor.Yellow);
            col++;

            var callString = moneyToCall <= 0 ? "]all, [" : "]all(" + moneyToCall + "), [";

            ConsoleHelper.WriteOnConsole(this.row + 2, col, callString);
            col += callString.Length;
            ConsoleHelper.WriteOnConsole(this.row + 2, col, "R", ConsoleColor.Yellow);
            col++;
            ConsoleHelper.WriteOnConsole(this.row + 2, col, "]aise, [");
            col += 8;
            ConsoleHelper.WriteOnConsole(this.row + 2, col, "F", ConsoleColor.Yellow);
            col++;
            ConsoleHelper.WriteOnConsole(this.row + 2, col, "]old, [");
            col += 7;
            ConsoleHelper.WriteOnConsole(this.row + 2, col, "A", ConsoleColor.Yellow);
            col++;
            ConsoleHelper.WriteOnConsole(this.row + 2, col, "]ll-in");
        }
Exemple #4
0
        private void UpdateCommonRows(int pot, int mainPot, IEnumerable <int> sidePots)
        {
            // Clear the first common row
            ConsoleHelper.WriteOnConsole(this.commonRow, 0, new string(' ', this.width - 1));

            this.DrawCommunityCards();

            var potAsString = "Pot: " + pot;

            ConsoleHelper.WriteOnConsole(this.commonRow, this.width - potAsString.Length - 2, potAsString);

            if (sidePots.Count() == 0)
            {
                // Clear the side pots
                ConsoleHelper.WriteOnConsole(this.commonRow + 1, 0, new string(' ', this.width - 1));
            }
            else
            {
                var mainPotAsString = "Main Pot: " + mainPot;
                ConsoleHelper.WriteOnConsole(this.commonRow, 2, mainPotAsString);

                var sidePotsAsString = "Side Pots: ";
                foreach (var item in sidePots)
                {
                    sidePotsAsString += item + " | ";
                }

                ConsoleHelper.WriteOnConsole(this.commonRow + 1, 2, sidePotsAsString.Remove(sidePotsAsString.Length - 2, 2));
            }
        }
        private void DrawSingleCard(int row, int col, Card card)
        {
            var cardColor = this.GetCardColor(card);

            ConsoleHelper.WriteOnConsole(row, col, " " + card + " ", cardColor, ConsoleColor.White);
            ConsoleHelper.WriteOnConsole(row, col + 2 + card.ToString().Length, " ");
        }
Exemple #6
0
 public override void StartHand(StartHandContext context)
 {
     this.UpdateCommonRow(0);
     ConsoleHelper.WriteOnConsole(this.row + 1, 2, context.MoneyLeft + "       ");
     ConsoleHelper.WriteOnConsole(this.row + 1, 10, context.FirstCard + "  ");
     ConsoleHelper.WriteOnConsole(this.row + 1, 15, context.SecondCard + "  ");
 }
        private static void Table(int gameHeight)
        {
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BufferHeight    = Console.WindowHeight = gameHeight;
            Console.BufferWidth     = Console.WindowWidth = GameWidth;

            ConsoleHelper.WriteOnConsole(gameHeight - 1, GameWidth - ProgramName.Length - 1, ProgramName, ConsoleColor.Green);
        }
        private void UpdateCommonRow(int pot)
        {
            // Clear the common row
            ConsoleHelper.WriteOnConsole(this.commonRow, 0, new string(' ', this.width - 1));

            this.DrawCommunityCards();

            var potAsString = "Pot: " + pot;

            ConsoleHelper.WriteOnConsole(this.commonRow, this.width - potAsString.Length - 2, potAsString);
        }
Exemple #9
0
        public override void StartRound(IStartRoundContext context)
        {
            this.CommunityCards = context.CommunityCards;
            this.UpdateCommonRows(
                context.CurrentPot,
                context.CurrentMainPot.AmountOfMoney,
                context.CurrentSidePots.Select(s => s.AmountOfMoney));

            ConsoleHelper.WriteOnConsole(this.row + 1, this.width - 11, context.RoundType + "   ");
            ConsoleHelper.WriteOnConsole(this.row + 3, 2, new string(' ', this.width - 3));
            base.StartRound(context);
        }
Exemple #10
0
        private void UpdateCommonRow(int pot)
        {
            // Clear the common row
            ConsoleHelper.WriteOnConsole(this.commonRow, 0, new string(' ', this.width - 1));

            var cardsAsString = this.CommunityCards.CardsToString();

            ConsoleHelper.WriteOnConsole(this.commonRow, (this.width / 2) - (cardsAsString.Length / 2), cardsAsString);

            var potAsString = pot.ToString();

            ConsoleHelper.WriteOnConsole(this.commonRow, this.width - potAsString.Length - 2, potAsString);
        }
        public override void StartHand(IStartHandContext context)
        {
            this.UpdateCommonRow(0);
            var dealerSymbol = context.FirstPlayerName == this.Player.Name ? "D" : " ";

            ConsoleHelper.WriteOnConsole(this.row + 1, 1, dealerSymbol, ConsoleColor.Green);
            ConsoleHelper.WriteOnConsole(this.row + 3, 2, "                            ");

            ConsoleHelper.WriteOnConsole(this.row + 1, 2, context.MoneyLeft.ToString());
            this.DrawSingleCard(this.row + 1, 10, context.FirstCard);
            this.DrawSingleCard(this.row + 1, 14, context.SecondCard);

            base.StartHand(context);
        }
 private void DrawGameBox()
 {
     ConsoleHelper.WriteOnConsole(this.row, 0, new string('═', this.width), PlayerBoxColor);
     ConsoleHelper.WriteOnConsole(this.row + 4, 0, new string('═', this.width), PlayerBoxColor);
     ConsoleHelper.WriteOnConsole(this.row, 0, "╔", PlayerBoxColor);
     ConsoleHelper.WriteOnConsole(this.row, this.width - 1, "╗", PlayerBoxColor);
     ConsoleHelper.WriteOnConsole(this.row + 4, 0, "╚", PlayerBoxColor);
     ConsoleHelper.WriteOnConsole(this.row + 4, this.width - 1, "╝", PlayerBoxColor);
     for (var i = 1; i < 4; i++)
     {
         ConsoleHelper.WriteOnConsole(this.row + i, 0, "║", PlayerBoxColor);
         ConsoleHelper.WriteOnConsole(this.row + i, this.width - 1, "║", PlayerBoxColor);
     }
 }
Exemple #13
0
        public override PlayerAction PostingBlind(IPostingBlindContext context)
        {
            this.UpdateCommonRows(context.CurrentPot, context.CurrentPot, new int[] { });

            var action = base.PostingBlind(context);

            ConsoleHelper.WriteOnConsole(this.row + 2, 2, new string(' ', this.width - 3));
            ConsoleHelper.WriteOnConsole(this.row + 3, 2, "Last action: " + action.Type + "(" + action.Money + ")");

            var moneyAfterAction = context.CurrentStackSize;

            ConsoleHelper.WriteOnConsole(this.row + 1, 2, moneyAfterAction + "   ");

            return(action);
        }
Exemple #14
0
        public static void Main()
        {
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BufferHeight    = Console.WindowHeight = GameHeight;
            Console.BufferWidth     = Console.WindowWidth = GameWidth;

            ConsoleHelper.WriteOnConsole(GameHeight - 1, GameWidth - ProgramName.Length - 1, ProgramName, ConsoleColor.Green);

            var consolePlayer1    = new ConsoleUiDecorator(new ConsolePlayer(0), 0, GameWidth, 5);
            var consolePlayer2    = new ConsoleUiDecorator(new SmartPlayer(), 6, GameWidth, 5);
            ITexasHoldemGame game = new TwoPlayersTexasHoldemGame(consolePlayer1, consolePlayer2);

            game.Start();
        }
Exemple #15
0
        public override PlayerAction GetTurn(IGetTurnContext context)
        {
            this.UpdateCommonRows(
                context.CurrentPot,
                context.MainPot.AmountOfMoney,
                context.SidePots.Select(s => s.AmountOfMoney));

            ConsoleHelper.WriteOnConsole(this.row + 1, 2, context.MoneyLeft + "   ");

            var action = base.GetTurn(context);

            if (action.Type == PlayerActionType.Fold)
            {
                this.Muck(context.MoneyLeft);
            }

            ConsoleHelper.WriteOnConsole(this.row + 2, 2, new string(' ', this.width - 3));

            var lastAction = action.Type.ToString();

            if (action.Type == PlayerActionType.CheckCall)
            {
                lastAction += $"({context.MoneyToCall})";
            }
            else if (action.Type == PlayerActionType.Raise)
            {
                lastAction += $"({action.Money + context.MyMoneyInTheRound + context.MoneyToCall})";
            }

            ConsoleHelper.WriteOnConsole(this.row + 3, 2, new string(' ', this.width - 3));
            ConsoleHelper.WriteOnConsole(this.row + 3, 2, "Last action: " + lastAction);

            var moneyAfterAction = action.Type == PlayerActionType.Fold
                ? context.MoneyLeft
                : context.MoneyLeft - action.Money - context.MoneyToCall;

            ConsoleHelper.WriteOnConsole(this.row + 1, 2, moneyAfterAction + "   ");

            return(action);
        }
Exemple #16
0
        public override PlayerAction GetTurn(GetTurnContext context)
        {
            this.UpdateCommonRow(context.CurrentPot);

            ConsoleHelper.WriteOnConsole(this.row + 2, 2, "Select action [C]heck/[C]all, [R]aise, [F]old, [A]ll-in");
            while (true)
            {
                var          key    = Console.ReadKey(true);
                PlayerAction action = null;
                switch (key.Key)
                {
                case ConsoleKey.C:
                    action = PlayerAction.CheckOrCall();
                    break;

                case ConsoleKey.R:
                    // TODO: Ask for the raise amount!
                    action = PlayerAction.Raise(10);
                    break;

                case ConsoleKey.F:
                    action = PlayerAction.Fold();
                    break;

                case ConsoleKey.A:
                    action = PlayerAction.Raise(context.MoneyLeft);
                    break;
                }

                // TODO: Check if the action is valid
                if (action != null)
                {
                    ConsoleHelper.WriteOnConsole(this.row + 2, 2, new string(' ', this.width - 3));
                    ConsoleHelper.WriteOnConsole(this.row + 3, 2, action + "    ");
                    return(action);
                }
            }
        }
Exemple #17
0
        private int RaiseAmount(int moneyLeft, int minRaise, int moneyToCall, int myMoneyInTheRound)
        {
            var wholeMinRaise = minRaise + myMoneyInTheRound + moneyToCall;

            if (wholeMinRaise >= moneyLeft + myMoneyInTheRound)
            {
                // Instant All-In
                return(moneyLeft - moneyToCall);
            }

            var perfix = $"Raise amount [{wholeMinRaise}-{moneyLeft + myMoneyInTheRound}]:";

            do
            {
                ConsoleHelper.WriteOnConsole(this.row + 2, 2, new string(' ', Console.WindowWidth - 3));
                ConsoleHelper.WriteOnConsole(this.row + 2, 2, perfix);

                var text = ConsoleHelper.UserInput(this.row + 2, perfix.Length + 3);
                int result;

                if (int.TryParse(text, out result))
                {
                    if (result < wholeMinRaise)
                    {
                        return(minRaise);
                    }
                    else if (result >= moneyLeft + myMoneyInTheRound)
                    {
                        // Raise All-in
                        return(moneyLeft - moneyToCall);
                    }

                    return(result - (myMoneyInTheRound + moneyToCall));
                }
            }while (true);
        }
Exemple #18
0
 private void DrawMuckedSingleCard(int row, int col, Card card)
 {
     ConsoleHelper.WriteOnConsole(row, col, " " + card + " ", ConsoleColor.Gray, ConsoleColor.DarkGray);
 }