Esempio n. 1
0
        private Player AddOrUpdatePlayer(UserGameInfoNet userGameInfo, int seat, HandHistory handHistory, long heroId)
        {
            var player = handHistory.Players[userGameInfo.UserInfo.ShowID];

            if (player == null)
            {
                player = new Player(userGameInfo.UserInfo.ShowID, 0, seat)
                {
                    PlayerNick = userGameInfo.UserInfo.Nick
                };

                handHistory.Players.Add(player);

                if (heroId == userGameInfo.UserInfo.Uuid)
                {
                    handHistory.Hero = player;
                }
            }

            if (userGameInfo.CurrentHands == null || player.hasHoleCards)
            {
                return(player);
            }

            handHistory.Players[userGameInfo.UserInfo.ShowID].HoleCards = HoleCards.FromCards(userGameInfo.UserInfo.ShowID,
                                                                                              userGameInfo.CurrentHands.Select(c => Card.GetPMCardFromIntValue(c)).ToArray());

            return(player);
        }
Esempio n. 2
0
        private HandActionType ParseHandActionType(UserGameInfoNet userGameInfoNet)
        {
            switch (userGameInfoNet.GameState)
            {
            case UserGameStates.USER_GAME_STATE_CALL:
                return(HandActionType.CALL);

            case UserGameStates.USER_GAME_STATE_CHECK:
                return(HandActionType.CHECK);

            case UserGameStates.USER_GAME_STATE_FOLD:
                return(HandActionType.FOLD);

            case UserGameStates.USER_GAME_STATE_RAISE:
                return(HandActionType.RAISE);
            }

            return(HandActionType.UNKNOWN);
        }
Esempio n. 3
0
        private HandAction ParseHandAction(UserGameInfoNet userGameInfoNet, UserGameInfoNet previousUserGameInfo, HandHistory handHistory)
        {
            if (previousUserGameInfo == null)
            {
                return(null);
            }

            // ante
            if (previousUserGameInfo.RoomGameState == GameRoomGameState.ROOM_GAME_STATE_GameStart &&
                userGameInfoNet.RoomGameState == GameRoomGameState.ROOM_GAME_STATE_Ante)
            {
                return(new HandAction(userGameInfoNet.UserInfo.ShowID,
                                      HandActionType.ANTE,
                                      userGameInfoNet.BetStacks,
                                      Street.Preflop));
            }

            // Small blind
            if (IsPrePreflopAction(previousUserGameInfo.RoomGameState) &&
                userGameInfoNet.GameRole == UserGameRoles.USER_GAME_ROLE_SMALL_BLIND &&
                (userGameInfoNet.GameState == UserGameStates.USER_GAME_STATE_BETTING || userGameInfoNet.GameState == UserGameStates.USER_GAME_STATE_BLIND) &&
                userGameInfoNet.BetStacks > 0)
            {
                return(new HandAction(userGameInfoNet.UserInfo.ShowID,
                                      HandActionType.SMALL_BLIND,
                                      userGameInfoNet.BetStacks,
                                      Street.Preflop));
            }

            // Big blind
            if (IsPrePreflopAction(previousUserGameInfo.RoomGameState) &&
                userGameInfoNet.GameRole == UserGameRoles.USER_GAME_ROLE_BIG_BLIND &&
                (userGameInfoNet.GameState == UserGameStates.USER_GAME_STATE_BETTING || userGameInfoNet.GameState == UserGameStates.USER_GAME_STATE_BLIND) &&
                userGameInfoNet.BetStacks > 0)
            {
                return(new HandAction(userGameInfoNet.UserInfo.ShowID,
                                      HandActionType.BIG_BLIND,
                                      userGameInfoNet.BetStacks,
                                      Street.Preflop));
            }

            // Straddle
            if (IsPrePreflopAction(previousUserGameInfo.RoomGameState) &&
                userGameInfoNet.GameRole == UserGameRoles.USER_GAME_ROLE_STRADDLE &&
                (userGameInfoNet.GameState == UserGameStates.USER_GAME_STATE_BETTING || userGameInfoNet.GameState == UserGameStates.USER_GAME_STATE_BLIND) &&
                userGameInfoNet.BetStacks > 0)
            {
                return(new HandAction(userGameInfoNet.UserInfo.ShowID,
                                      HandActionType.STRADDLE,
                                      userGameInfoNet.BetStacks,
                                      Street.Preflop));
            }

            var handActionType = ParseHandActionType(userGameInfoNet);

            if (handActionType == HandActionType.UNKNOWN ||
                userGameInfoNet.GameState == previousUserGameInfo.GameState &&
                previousUserGameInfo.BettingID == userGameInfoNet.BettingID)
            {
                return(null);
            }

            var street = ParseRoomGameState(userGameInfoNet.RoomGameState);

            if (street == Street.Null)
            {
                if (userGameInfoNet.RoomGameState == GameRoomGameState.ROOM_GAME_STATE_Result)
                {
                    street = ParseRoomGameState(previousUserGameInfo.RoomGameState);
                }

                if (street == Street.Null)
                {
                    throw new HandBuilderException(handHistory.HandId, $"UserGameInfo.RoomGameState has unexpected value: {userGameInfoNet.RoomGameState}");
                }
            }

            var amount = userGameInfoNet.BetStacks - previousUserGameInfo.BetStacks;

            if (amount < 0)
            {
                if (handActionType != HandActionType.FOLD)
                {
                    throw new HandBuilderException(handHistory.HandId, $"Incorrect hand data: action = {handActionType}, amount = {amount}");
                }

                amount = 0;
            }

            var handAction = userGameInfoNet.RemainStacks == 0 ?
                             new AllInAction(userGameInfoNet.UserInfo.ShowID, amount, street,
                                             handActionType == HandActionType.BET || handActionType == HandActionType.RAISE,
                                             handActionType) :
                             new HandAction(userGameInfoNet.UserInfo.ShowID, handActionType, amount, street);

            return(handAction);
        }