public override string ToString()
        {
            string toString = this.GetType().ToString() + "{ ";

            #region Players
            toString += "Players{ ";
            for (int i = 0; i < this.Players.Length; i++)
            {
                toString +=
                    ((this.Players[i] == null) ?
                     "EMPTY" :
                     this.Players[i].Name);
                if (i != this.Players.Length - 1)
                {
                    toString += ", ";
                }
            }
            toString += " }";
            #endregion

            toString +=
                Deck.ToString() +
                TableCards.ToString() +
                BurnCards.ToString() +
                "Pot{ " + Pot.ToString() + " }" +
                "Minimum Denomination{ " + MinimumDenomination.ToString() + "  }" +
                "Low Blind{ " + LowBlind.ToString() + "  }" +
                "High Blind{ " + HighBlind.ToString() + " }";

            toString += " }";
            return(toString);
        }
Ejemplo n.º 2
0
 public void Reset()
 {
     Deck.Restore();
     Player1.Muck();
     Player2.Muck();
     TableCards.Clear();
     Winner = null;
 }
Ejemplo n.º 3
0
 protected RoundBase(int smallBlind, int bigBlind, Deck deck, TableCards cards, INotifier notifier)
 {
     SmallBlind = smallBlind;
     BigBlind   = bigBlind;
     Deck       = deck;
     Cards      = cards;
     _notifier  = notifier;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 发牌桌的牌
 /// </summary>
 private void DealToTable()
 {
     TableCards.Clear();
     for (int i = 1; i <= GameConfig.Table_Cards_Count; i++)
     {
         var card = PickCardFromPile();
         TableCards.Add(i, card);
     }
 }
Ejemplo n.º 5
0
        private void River()
        {
            // На стол добавляется 1 карты
            TableCards.Add(Deck.GetCard());

            // Круг торгов
            BettingRound();
            CollectMoney();
        }
Ejemplo n.º 6
0
        public GameResult GetResult(List <PlayerWithCards> playersWithCards, TableCards tableCards)
        {
            if (!IsGameFinished)
            {
                throw ExceptionFactory.GameIsNotFinishedYet;
            }

            return(CalculateResult(playersWithCards, tableCards));
        }
Ejemplo n.º 7
0
        //Gets the distance one player is from another.
        public int GetDistanceAway(Player[] players, Player otherPlayer)
        {
            int thisIndex = -1, otherIndex = -1;

            for (int i = 0; i < players.Length; i++) //Identify indexes of both players.
            {
                if (players[i] == this)
                {
                    thisIndex = i;
                }
                else if (players[i] == otherPlayer)
                {
                    otherIndex = i;
                }
            }

            if (thisIndex == -1 || otherIndex == -1)
            {
                return(-1);
            }

            int distanceRight = 0, distanceLeft = 0, helper = thisIndex; //Identify the closest distance to the player.

            while (helper != otherIndex)
            {
                helper++;
                if (helper >= players.Length)
                {
                    helper = 0;
                }
                distanceRight++;
            }
            helper = thisIndex;
            while (helper != otherIndex)
            {
                helper--;
                if (helper < 0)
                {
                    helper = players.Length - 1;
                }
                distanceLeft++;
            }
            int distance = distanceLeft > distanceRight ? distanceRight : distanceLeft;

            if (otherPlayer.TableCards.Contains(CardType.Mustang))
            {
                distance++;
            }
            if (TableCards.Contains(CardType.Scope) && distance > 1)
            {
                distance--;
            }

            return(distance);
        }
Ejemplo n.º 8
0
        private void Flop()
        {
            // На столе 3 карты
            TableCards.Add(Deck.GetCard());
            TableCards.Add(Deck.GetCard());
            TableCards.Add(Deck.GetCard());

            // Круг торгов
            BettingRound();
            CollectMoney();
        }
Ejemplo n.º 9
0
        public void InitCardPile()
        {
            TableCards.Clear();

            // CleanPlayerCards();

            if (RemainCards.Count < 52)
            {
                _RemainCards = InitNewCards();
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Deals the table cards (flop, turn, river) according to the current tablestate
        /// </summary>
        private void DealTableCards()
        {
            switch (State)
            {
            case TableState.Flop:
                TableCards.AddRange(deck.Deal(3));
                break;

            case TableState.Turn:
            case TableState.River:
                TableCards.AddRange(deck.Deal());
                break;
            }
        }
Ejemplo n.º 11
0
        public void Start()
        {
            Func <Action, bool> conductBettingRoungAndReportIfRoundIsOver = currentRound =>
            {
                currentRound();
                return(Ready.Count(x => x) < 2);
            };
            Action setReadyPlayers = () =>
            {
                for (int i = 0; i < 10; i++)
                {
                    Ready[i] = PlayerBySeat.ContainsKey(i);
                }
            };

            setReadyPlayers();
            SetInitialRoles();
            while (true)
            {
                CheckWinner();
                if (Count < 2)
                {
                    break;
                }
                Deck.Shuffle();
                TableCards.Clear();
                setReadyPlayers();
                // Цикл раундов пока есть хотя бы 2 игрока
                if (conductBettingRoungAndReportIfRoundIsOver(PreFlop))
                {
                    continue;
                }
                if (conductBettingRoungAndReportIfRoundIsOver(Flop))
                {
                    continue;
                }
                if (conductBettingRoungAndReportIfRoundIsOver(Turn))
                {
                    continue;
                }
                if (conductBettingRoungAndReportIfRoundIsOver(River))
                {
                    continue;
                }
                ShowDown();
                Update();
            }
        }
Ejemplo n.º 12
0
        private void loadAllPossibleHands(Player Player)
        {
            Card[] current = new Card[5];
            int    index   = 0;

            Player.AllPossibleHands.Add(new PokerHand(TableCards.ToArray())); // 1 Hand with 5 table cards

            for (int c = 0; c < Player.Hand.Count; c++)                       // 10 Hands with 4 table cards
            {
                current[index++] = Player.Hand[c];
                for (int c2 = 0; c2 < TableCards.Count; c2++)
                {
                    for (int c3 = 0; c3 < TableCards.Count; c3++)
                    {
                        if (c3 != c2)
                        {
                            current[index++] = TableCards[c3];
                        }
                    }
                    index = 1;
                    Player.AllPossibleHands.Add(new PokerHand(current));
                }
                index = 0;
            }

            current[0] = Player.Hand[0]; // 10 Hands with 3 table cards)
            current[1] = Player.Hand[1];

            for (int c = 0; c < TableCards.Count; c++)
            {
                current[2] = TableCards[c];
                for (int c2 = c + 1; c2 < TableCards.Count; c2++)
                {
                    current[3] = TableCards[c2];
                    for (int c3 = c2 + 1; c3 < TableCards.Count; c3++)
                    {
                        current[4] = TableCards[c3];
                        Player.AllPossibleHands.Add(new PokerHand(current));
                        current[4] = null;
                    }
                    current[3] = null;
                }
                current[2] = null;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Get the winner
        /// </summary>
        /// <returns>The player who won</returns>
        private Player FindWinner()
        {
            CardHand.Worth?worth  = null;
            Player         winner = null;

            foreach (Player p in GetActivePlayers)
            {
                p.AddCards(TableCards);
                CardHand.Worth nextWorth = p.GetHandsWorth();
                if (null == worth || worth < nextWorth)
                {
                    worth  = nextWorth;
                    winner = p;
                }
            }

            TableCards.Clear();

            return(winner);
        }
Ejemplo n.º 14
0
 private DbManager()
 {
     TableCards = new TableCards();
     TableUsers = new TableUsers();
 }
Ejemplo n.º 15
0
 public HandsRound(int smallBlind, int bigBlind, Deck deck, TableCards cards, INotifier notifier) : base(smallBlind, bigBlind, deck, cards, notifier)
 {
 }
        private GameResult CalculateResult(List <PlayerWithCards> playersWithCards, TableCards tableCards)
        {
            var playersInGame = _players.Where(x => !x.Folded()).ToList();
            var bank          = _allActions.Sum(x => x.Value.BetSize.GetValueOrDefault());

            if (playersInGame.Count == 1)
            {
                throw new Exception();
            }

            var players = playersInGame
                          .Select(x => new
            {
                x.NickName,
                SpendChips = x.SpentChips(),
                playersWithCards.First(y => y.NickName == x.NickName).PockerCards
            })
                          .Select(x => new
            {
                x.NickName,
                x.SpendChips,
                MaxBank             = _players.Sum(y => y.ChipsOnStart - y.Chips > x.SpendChips ? x.SpendChips : y.ChipsOnStart - y.Chips),
                CombinationStrength = StrengthOperations.GetStrength(new List <Card>
                {
                    tableCards.FlopCard1,
                    tableCards.FlopCard2,
                    tableCards.FlopCard3,
                    tableCards.TurnCard,
                    tableCards.RiverCard,
                    x.PockerCards.Card1,
                    x.PockerCards.Card2
                })
            })
                          .OrderByDescending(x => x.CombinationStrength)
                          .ToList();


            // If we don't have equals strength of combinations.
            //
            //var alreadyPaid = 0;
            //foreach (var p in players)
            //{
            //    if (p.MaxBank <= alreadyPaid)
            //    {
            //        continue;
            //    }

            //    var player = FindPlayer(p.NickName);
            //    player.Chips += p.MaxBank - alreadyPaid;
            //    alreadyPaid = p.MaxBank;

            //    if (alreadyPaid == bank)
            //    {
            //        break;
            //    }
            //}


            // We need divide chips if have equals strength of combinations.
            //
            // 28 24
            // 2  2  2 1  3
            // 18 20 5 10 30 // 83
            // 12 16 0 45 10

            var alreadyPaid = 0;

            foreach (var group in players.GroupBy(x => x.CombinationStrength).OrderByDescending(x => x.Key).ToList())
            {
                var orderedGroup = group.ToList();
                while (orderedGroup.Any())
                {
                    var minMaxBank = orderedGroup.Min(x => x.MaxBank);
                    if (minMaxBank <= alreadyPaid)
                    {
                        orderedGroup.RemoveAll(x => x.MaxBank <= minMaxBank);
                        continue;
                    }

                    var toPay = (minMaxBank - alreadyPaid) / orderedGroup.Count; // accuracy may be lost here

                    orderedGroup.ForEach(x =>
                    {
                        var player    = FindPlayer(x.NickName);
                        player.Chips += toPay;
                    });

                    orderedGroup.RemoveAll(x => x.MaxBank <= minMaxBank);

                    alreadyPaid = minMaxBank;
                }

                if (alreadyPaid == bank)
                {
                    break;
                }
            }

            return(new GameResult
            {
                Players = _players.ToValueList()
            });
        }
Ejemplo n.º 17
0
        public void SetUpGameInPlay()
        {
            var flag = false;

            PokerForm[] Forms = new PokerForm[3];
            TurnPlayerForm.CopyTo(Forms);
            if (!Folded)
            {
                TurnPlayerForm.RemoveAt(0);
            }
            Folded = false;
            if (Forms[0] != null)
            {
                Forms[0].LockControls();
            }
            // Forms[0].ShowMin();
            if (TurnPlayerForm.Count > 0)
            {
                foreach (PokerForm form in TurnPlayerForm)
                {
                    if (!flag)
                    {
                        form.ShowMin();
                        form.SetUpNewGame();
                        flag = true;
                    }
                    else
                    {
                        form.LockControls();
                    }
                }
            }
            else
            {
                gameState++;
                MinBetAmount = 0;
                foreach (Player p in players)
                {
                    p.ClearBet();
                }
                // FormTurn = 0;
                TurnPlayerForm = new List <PokerForm>(PlayerForms);
                //if(gameState == PokerGame.GameState.TURN)// in order to add another gambling round you need to this
                //TurnPlayerForm.AddRange(PlayerForms);
                var first = TurnPlayerForm[0];
                int j     = 0;
                foreach (PokerForm form in TurnPlayerForm)
                {
                    form.FormIndex = j;
                    j++;
                    form.SetTextBox(gameState.ToString());
                    form.ShowBankValue();
                    if (first == form)
                    {
                        form.SetUpNewGame();
                    }
                    else
                    {
                        form.LockControls();
                    }
                }
                switch (gameState)
                {
                case PokerGame.GameState.FLOP:
                    // gameOverTextBox.Text = "Flop";
                    for (int i = 0; i < 3; i++)
                    {
                        Card flopCard = CurrentDeck.Draw();
                        TableCards.Add(flopCard);
                    }


                    break;

                case PokerGame.GameState.TURN:
                    // gameOverTextBox.Text = "Turn";
                    Card turnCard = CurrentDeck.Draw();
                    TableCards.Add(turnCard);

                    break;

                case PokerGame.GameState.RIVER:
                    // gameOverTextBox.Text = "River";
                    Card riverCard = CurrentDeck.Draw();
                    TableCards.Add(riverCard);


                    break;

                case PokerGame.GameState.ENDGAME:
                    GameOver();
                    break;

                    //case PokerGame.GameState.NewStage: // To Add another level of the game you need to add another enum on gamestate & to the above switch case
                    //    Card newStage = CurrentDeck.Draw();
                    //    TableCards.Add(newStage);
                    //    break;
                }
                foreach (PokerForm form in PlayerForms)
                {
                    switch (gameState)
                    {
                    case PokerGame.GameState.FLOP:

                        form.updateTableCards();
                        break;

                    case PokerGame.GameState.TURN:


                        form.updateTableCards();
                        break;

                    case PokerGame.GameState.RIVER:


                        form.updateTableCards();

                        break;
                        // To Add another level of the game you need to add another enum on gamestate & to the above switch case
                    }
                }
            }
        }
Ejemplo n.º 18
0
 public FourStraightRound(int smallBlind, int bigBlind, Deck deck, TableCards cards, INotifier notifier) : base(smallBlind, bigBlind, deck, cards, notifier)
 {
 }