Beispiel #1
0
        public Hand(GameState gameState)
        {
            if (gameState == null)
                return;

            _gameState = gameState;
        }
        public static void CreateGameState(IntPtr hPokerTable)
        {
            if (!_gamesStates.Contains(hPokerTable))
            {
                GameState gameState = new GameState(hPokerTable);
                gameState.pokerVenue = ConfigReader.GAMESTATE_FACTORY_POKER_VENUE;
                gameState.heroName = ConfigReader.GAMESTATE_FACTORY_HERO_NAME;

                _gamesStates.Add(hPokerTable, gameState);
                logger.Info("======================= New GameState " + hPokerTable + " ======================");
            }
            else
            {
                logger.Error("attemped to create existing gameState : " + hPokerTable);
            }
        }
 public abstract bool ParseLogMessage(GameState currentGame, string text);
        public override bool ParseLogMessage(GameState currentGame, string text)
        {
            logger.Debug("parses : " + text);
            // quitamos el comienzo de los mensajes si es "> "
            if (text.StartsWith("> "))
                text = text.Substring(2);

            // lo añadimos al log
            currentGame.tableLog.Add(text);

            // We have a winner and a new hand is about to start
            Match m = regWinner.Match(text);
            if (m.Success)
            {
                String previousHandId = currentGame.currentHand.handNumber;
                // first disable the gamestate
                currentGame.ready = false;
                currentGame.NewHand();

                return false;
            }

            // Small Blind is Payed
            m = regSmallBlind.Match(text);
            if (m.Success)
            {
                if (currentGame.heroName.Equals(m.Groups[1].ToString()))
                {
                    currentGame.currentHand.heroSeat = Hand.SEAT_SMALL_BLIND;
                    currentGame.currentHand.heroPreflopPosition = Hand.POSITION_LATE;
                }
                currentGame.smallBlindAmmount = double.Parse(m.Groups[2].ToString());
                currentGame.currentHand.PlayerPosts(m.Groups[1].ToString(), double.Parse(m.Groups[2].ToString()));
                // HACK - ASSIGNACION ASIENTOS
                currentGame.currentHand.AssingSeat(m.Groups[1].ToString(), Hand.SEAT_SMALL_BLIND);
                return false;
            }

            // Big Blind is Payed
            m = regBigBlind.Match(text);
            if (m.Success)
            {
                if (currentGame.heroName.Equals(m.Groups[1].ToString()))
                {
                    currentGame.currentHand.heroSeat = Hand.SEAT_BIG_BLIND;
                    currentGame.currentHand.heroPreflopPosition = Hand.POSITION_LATE;
                }
                currentGame.bigBlindAmmount = double.Parse(m.Groups[2].ToString());
                currentGame.currentHand.PlayerPosts(m.Groups[1].ToString(), double.Parse(m.Groups[2].ToString()));
                // HACK - ASSIGNACION ASIENTOS
                currentGame.currentHand.AssingSeat(m.Groups[1].ToString(), Hand.SEAT_BIG_BLIND);
                return false;
            }

            // Forced Bet to Play is Payed
            m = regPostedToPlay.Match(text);
            if (m.Success)
            {
                // al ser un post el jugador se añade pero inactivo
                // se le pone active con su primera apuesta voluntaria
                currentGame.currentHand.PlayerPosts(m.Groups[1].ToString(), double.Parse(m.Groups[2].ToString()));
                return false;
            }

            // Hand Starts
            m = regGameStart.Match(text);
            if (m.Success)
            {
                currentGame.currentHand.handNumber = m.Groups[1].ToString();

                //TODO: Integrar aqui el acceso a SQLite.
                // Buscamos la ultima mano con _currentHand antes de cambiarla.
                //SQLitePreviousHandReader reader = new SQLitePreviousHandReader();
                //if (!reader.Read(currentGame.previousHand.handNumber, currentGame))
                //{
                //    logger.Fatal("no previous hand available!");
                //}
                // parseamos y guardamos los datos de stacks y jugadores justo en la mano anterior.
                // Se pueden dar casos en los que no haya habido mano anterior. ¿Fallback a AssignSeat? Mejor otra cosa. ¿O no?

                currentGame.currentHand.NewStreet(Hand.STREET_PREFLOP);
                return false;
            }

            // hole cards dealed
            m = regHoleCards.Match(text);
            if (m.Success)
            {
                // if we get cards, we are playing!!
                // enable the gamestate
                String holeCards = m.Groups[1].ToString() + m.Groups[2].ToString();
                if (!String.IsNullOrEmpty(holeCards))
                {
                    currentGame.currentHand.holeCards = holeCards;
                    currentGame.ready = true;
                }
                return false;
            }

            // a player has checked
            m = regCheck.Match(text);
            if (m.Success)
            {
                // es un check, asi que apuesta 0
                currentGame.currentHand.PlayerChecks(m.Groups[1].ToString());
                return false;
            }

            // a player has betted
            m = regBet.Match(text);
            if (m.Success)
            {
                currentGame.currentHand.PlayerBets(m.Groups[1].ToString(), double.Parse(m.Groups[2].ToString()));
                return false;
            }

            // a player has called
            m = regCall.Match(text);
            if (m.Success)
            {
                currentGame.currentHand.PlayerCalls(m.Groups[1].ToString(), double.Parse(m.Groups[2].ToString()));
                return false;
            }

            // a player has raised
            m = regRaise.Match(text);
            if (m.Success)
            {
                currentGame.currentHand.PlayerRaises(m.Groups[1].ToString(), double.Parse(m.Groups[2].ToString()));
                return false;
            }

            // a player has gone all-in
            m = regAllin.Match(text);
            if (m.Success)
            {
                currentGame.currentHand.PlayerRaises(m.Groups[1].ToString(), double.Parse(m.Groups[2].ToString()));
                return false;
            }

            // a player has folded
            m = regFold.Match(text);
            if (m.Success)
            {
                // diferentes mensajes de fold que si no se cruzan
                Match auxM = regForcedFold.Match(text);
                if (auxM.Success)
                    m = auxM;

                // if a player acts more than once preflop AddPlayer only adds it the first time, so no problemo...
                currentGame.currentHand.PlayerFolds(m.Groups[1].ToString());
                // if its the hero who folds we disable the gamestate
                if (m.Groups[1].ToString().Equals(currentGame.heroName))
                    currentGame.ready = false;
                return false;
            }

            // Pasa 1 calle y salen nuevas cartas comunales
            m = regTableCards.Match(text);
            if (m.Success)
            {
                if (MATCH_STREET_FLOP.Equals(m.Groups[1].ToString()))
                {
                    currentGame.currentHand.tableCards = m.Groups[2].ToString() + m.Groups[3].ToString() + m.Groups[4].ToString();
                    currentGame.currentHand.NewStreet(Hand.STREET_FLOP);
                }
                else
                {
                    currentGame.currentHand.tableCards = currentGame.currentHand.tableCards + m.Groups[2].ToString();
                    if (MATCH_STREET_TURN.Equals(m.Groups[1].ToString()))
                        currentGame.currentHand.NewStreet(Hand.STREET_TURN);
                    else if (MATCH_STREET_RIVER.Equals(m.Groups[1].ToString()))
                        currentGame.currentHand.NewStreet(Hand.STREET_RIVER);
                }
                return false;
            }

            // Debemos actuar!!
            m = regInstaWakeUp.Match(text);
            if (m.Success)
            {
                currentGame.currentHand.PlayerThinks(currentGame.heroName);
                return true;
            }

            // No deberiamos llegar aqui pero esta claro que debemos actuar!!
            m = regTimeWarnning.Match(text);
            if (m.Success)
            {
                bool readyForDecision = false;
                currentGame.currentHand.PlayerThinks(m.Groups[1].ToString());
                if (currentGame.heroName.Equals(m.Groups[1].ToString()))
                {
                    // el mensaje WAKE UP!!! no ha funcionado o la decision se retrasa
                    logger.Error("the decision is not comming through in time. Let's request it again!" );
                    readyForDecision = true;
                }

                return readyForDecision;
            }

            // Comprobamos si nos hemos quedado sitout. No debería  pasar nunca!
            m = regSitsOut.Match(text);
            if (m.Success)
            {
                if (currentGame.heroName.Equals(m.Groups[1].ToString()))
                {
                    // la leche, debemos avisar de que estamos sitout para que se pueda hacer algo.
                    logger.Fatal("has been seated out of the game. Implement Situp and IAmBack actions!" );
                }

                return false;
            }

            // Mensajes de log reconocidos como inocuos
            foreach( Regex regEx in unusedRegex )
            {
                m = regEx.Match(text);
                if (m.Success)
                   return false;
            }

            // Mensajes de log peligrosos por ser desconocidos
            logger.Fatal("UNSUPPORTED MESSAGE, UPDATE PARSER VERSION PLEASE! (" + text + ")" );
            // Mensajes no parseados se gusrdan en el log con flag UNSUPPORTED
            currentGame.tableLog[currentGame.tableLog.Count - 1] = "UNSUPPORTED : " + currentGame.tableLog[currentGame.tableLog.Count - 1];

            return false;
        }