Exemplo n.º 1
0
        private GameGeneral CreateGameGeneral(HandHistories.Objects.Hand.HandHistory history)
        {
            var result = new GameGeneral
            {
                StartDate = history.DateOfHandUtc,
                Players   = CreateGameGeneralPlayers(history),
            };

            return(result);
        }
Exemplo n.º 2
0
        private GameGeneral BuildGameGeneral(IEnumerable <Round> rounds)
        {
            if (rounds == null)
            {
                throw new ArgumentNullException("rounds");
            }

            var players = new List <Player>();

            var winners = rounds.GetWinners(handModel.GameType);

            foreach (var seat in handModel.SeatsDealt.OrderBy(x => x))
            {
                if (!tableModel.PlayersOnTable.ContainsKey(seat))
                {
                    throw new Exception(string.Format("Couldn't find player's name on #{0} seat [HandNumber = {1}]", seat, handModel.HandNumber));
                }

                if (!handModel.StacksBeforeHand.ContainsKey(seat))
                {
                    throw new Exception(string.Format("Couldn't find player's stack before hand on #{0} seat [HandNumber = {1}]", seat, handModel.HandNumber));
                }

                var playerActions = rounds.SelectMany(x => x.Actions).Where(x => x.SeatNumber == seat).ToArray();

                var playerBet = playerActions.Sum(x => x.Sum);

                // if no stacks after the hand, then player was removed
                var stacksAfterHand = handModel.StacksAfterHand.ContainsKey(seat) ? handModel.StacksAfterHand[seat] : 0;

                var playerFolded = handModel.Commands.FilterCommands <PlayerAction>(CommandCodeEnum.PlayerAction)
                                   .Any(x => x.SeatNumber == seat &&
                                        (x.PlayerActionEnum == PlayerActionEnum.Fold || x.PlayerActionEnum == PlayerActionEnum.FoldShow));

                var win = !playerFolded ? stacksAfterHand - handModel.StacksBeforeHand[seat] + playerBet : 0;

                if (playerFolded)
                {
                    winners.Remove(seat);
                }

                var player = new Player
                {
                    Seat   = seat,
                    Name   = tableModel.PlayersOnTable[seat],
                    Chips  = handModel.StacksBeforeHand[seat],
                    Dealer = handModel.DealerSeat == seat,
                    Win    = win > 0 ? win : 0,
                    Bet    = playerBet
                };

                players.Add(player);
            }

            int shift = AdjustPlayerSeats(players);

            var gameGeneral = new GameGeneral
            {
                StartDate        = GetCurrentTimeUTC(),
                Players          = players,
                PlayersSeatShift = shift,
            };

            return(gameGeneral);
        }