Exemplo n.º 1
0
        /// <summary>
        /// Returns an AI decision where the gameCache is already populated.
        /// </summary>
        /// <param name="handId">Current Hand Id</param>
        /// <param name="playerId">Player for which decision is required.</param>
        /// <param name="gameCache">The current gamecache</param>
        /// <returns></returns>
        protected override Play GetDecision()
        {
            //Initialise playDecision as fold which is returned if it is not modified anywhere
            botAction    = PokerAction.Fold;
            betAmount    = 0;
            decisionTime = 0;

            botPlayWRThreshold  = getPlayWR(currentDecision.AiConfigStr);
            botRaiseWRThreshold = getRaiseWR(currentDecision.AiConfigStr);
            botAlwaysPlayLB     = true;

            winRatioDifference            = (botPlayWRThreshold / 2);
            bettingRound                  = currentDecision.Cache.getBettingRound();
            currentRoundMinimumPlayAmount = currentDecision.Cache.getMinimumPlayAmount();
            currentRoundLastRaiseAmount   = currentDecision.Cache.getCurrentRoundLastRaiseAmount();

            currentRoundPlayerBetAmount = currentDecision.Cache.getPlayerCurrentRoundBetAmount(currentDecision.PlayerId);

            currentWinPercentage = infoStore.GetInfoValue(InfoType.WR_CardsOnlyWinPercentage);
            currentWinRatio      = infoStore.GetInfoValue(InfoType.WR_CardsOnlyWinRatio);

            GetAIDecision();

            return(new Play(botAction, betAmount, decisionTime, currentDecision.Cache.getCurrentHandId(), currentDecision.PlayerId, currentWinRatio.ToString(), 2));
        }
Exemplo n.º 2
0
            public PlayerActionPrediction(double probFoldCheck, double probCall, double probRaise, decimal accuracy)
            {
                this.probFoldCheck = probFoldCheck;
                this.probCall      = probCall;
                this.probRaise     = probRaise;

                double[] probabilities = new double[] { probFoldCheck, probCall, probRaise };

                probabilities = (from
                                 predictions in probabilities
                                 orderby predictions descending
                                 select predictions).ToArray();

                this.accuracy = accuracy;

                double maxProbability = probFoldCheck;

                predictedAction = PokerAction.Check;

                if (probCall > maxProbability)
                {
                    maxProbability  = probCall;
                    predictedAction = PokerAction.Call;
                }

                if (probRaise > maxProbability)
                {
                    predictedAction = PokerAction.Raise;
                }
            }
Exemplo n.º 3
0
        public void Test_GameString_FromGameDef_Over()
        {
            GameDefinition gameDef = LoadGameDef();

            GameState gs = new GameState(gameDef, 2);

            VerifyGameState(gs, "", false, -1, 1.5, 1, 1, GameState.InvalidPosition, true, 0, 0, 0, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { Ak.d });
            VerifyPlayerState(gs.Players[0], "", -0.5, "", 0.5, 0.5, 0, false, false, false, true);
            VerifyPlayerState(gs.Players[1], "", -1, "", 1, 1, 0, false, false, false, true);

            gs.UpdateByAction(PokerAction.d(0, "Ac Ad"), gameDef);
            gs.UpdateByAction(PokerAction.d(1, "2c 3d"), gameDef);

            VerifyPlayerState(gs.Players[0], "", -0.5, "Ac Ad", 0.5, 0.5, 0, false, false, true, true);
            VerifyPlayerState(gs.Players[1], "", -1, "2c 3d", 1, 1, 0, false, false, true, true);

            gs.UpdateByAction(PokerAction.c(0), gameDef);
            gs.UpdateByAction(PokerAction.c(1), gameDef);
            gs.UpdateByAction(PokerAction.d("Ah As Qc"), gameDef);
            gs.UpdateByAction(PokerAction.c(1), gameDef);
            gs.UpdateByAction(PokerAction.c(0), gameDef);
            gs.UpdateByAction(PokerAction.d("Jh"), gameDef);
            gs.UpdateByAction(PokerAction.c(1), gameDef);
            gs.UpdateByAction(PokerAction.c(0), gameDef);
            gs.UpdateByAction(PokerAction.d("Ts"), gameDef);
            gs.UpdateByAction(PokerAction.c(1), gameDef);
            gs.UpdateByAction(PokerAction.c(0), gameDef);
            UInt32[] ranks = new UInt32[] { 2, 1 };
            gs.UpdateByShowdown(ranks, gameDef);
            VerifyGameState(gs, "", true, 3, 2, 0, 0, 0, false, GameState.InvalidPosition, 0, 0, true, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { });
            VerifyPlayerState(gs.Players[0], "", 1, "Ac Ad Ah As Qc Jh Ts", 1, 0, 1, false, false, false, true);
            VerifyPlayerState(gs.Players[1], "", -1, "2c 3d Ah As Qc Jh Ts", 1, 0, -1, false, false, false, true);
        }
Exemplo n.º 4
0
 public void SetPlayerAction(PokerAction action, float amount)
 {
     remainingChipsValue += this.amount - amount;
     this.action          = action;
     this.amount          = amount;
     actionEntered        = true;
 }
Exemplo n.º 5
0
 public void Test_IsDealerAction_Static()
 {
     Assert.IsFalse(PokerAction.IsDealerAction(Ak.b));
     Assert.IsFalse(PokerAction.IsDealerAction(Ak.f));
     Assert.IsFalse(PokerAction.IsDealerAction(Ak.c));
     Assert.IsFalse(PokerAction.IsDealerAction(Ak.r));
     Assert.IsTrue(PokerAction.IsDealerAction(Ak.d));
 }
Exemplo n.º 6
0
        protected override Definitions.Play GetDecision()
        {
            PokerAction action       = (PokerAction)(infoStore.GetInfoValue(InfoProviders.InfoType.WR_ModelAction));
            decimal     amount       = (decimal)infoStore.GetInfoValue(InfoProviders.InfoType.WR_ModelActionAmount);
            float       decisionTime = 0;

            return(new Play(action, amount, decisionTime, currentDecision.Cache.getCurrentHandId(), currentDecision.PlayerId));
        }
Exemplo n.º 7
0
 public Play(long handId, long playerId)
 {
     this.action       = PokerAction.CatastrophicError;
     this.amount       = 0;
     this.decisionTime = 0;
     this.handId       = handId;
     this.playerId     = playerId;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Contructor for Play struct
 /// </summary>
 /// <param name="action">The action to be performed</param>
 /// <param name="amount">The amount to raise by if that is the desired action</param>
 /// <param name="decisionTime">The elapsed time to allow before implementing the decision</param>
 /// <param name="handId">The handId for which this decision applies</param>
 /// <param name="playerId">The playerId for which this decision applies</param>
 public Play(PokerAction action, decimal amount, float decisionTime, long handId, long playerId)
 {
     this.action       = action;
     this.amount       = amount;
     this.decisionTime = decisionTime;
     this.handId       = handId;
     this.playerId     = playerId;
 }
Exemplo n.º 9
0
        public virtual PokerAction OnActionRequired(string gameString)
        {
            log.InfoFormat("{0} OnActionRequired", _name);
            _gameRecord = new GameRecord(gameString);
            ProcessActions();

            int chBegin, movesCount;

            _strIndexes[_pos].GetChildrenBeginIdxAndCount(_curStrNodeIdx, out chBegin, out movesCount);
            double[] probabs   = new double[movesCount];
            double   sumProbab = 0;

            for (int c = 0; c < movesCount; ++c)
            {
                int stNodeIdx           = _strIndexes[_pos].GetChildIdx(chBegin + c);
                StrategyTreeNode stNode = new StrategyTreeNode();
                _strategies[_pos].GetNode(stNodeIdx, &stNode);
                // Verify we are in the correct position.
                // This is proven to be very helpful in testing.
                if (!stNode.IsPlayerAction(_pos))
                {
                    throw new ApplicationException(String.Format("{0}: expected strategy child: player action for pos {1}, but was: '{2}'",
                                                                 GetBotStateDiagText(),
                                                                 _pos,
                                                                 stNode.ToStrategicString(null)));
                }

                probabs[c] = stNode.Probab;
                sumProbab += probabs[c];
            }
            try
            {
                // Convert to relative probability and ignore if necessary
                for (int c = 0; c < probabs.Length; ++c)
                {
                    probabs[c] /= sumProbab;
                    if (probabs[c] < _relProbabIgnoreLevel)
                    {
                        probabs[c] = 0;
                    }
                }
                _moveSelector.SetWeights(probabs);
            }
            catch (Exception e)
            {
                // If there are problems with 0-probablities, add more info to it.
                throw new ApplicationException(String.Format("{0} : see inner exception", GetBotStateDiagText()), e);
            }

            int moveIdx = _moveSelector.Next();

            Debug.Assert(probabs[moveIdx] > 0, "0-probabs must not occur");
            int         nextStrNode = _strIndexes[_pos].GetChildIdx(chBegin + moveIdx);
            PokerAction move        = ConvertStrActionToPokerAction(nextStrNode);

            log.InfoFormat("{0} OnActionRequired() returns {1}", _name, move);
            return(move);
        }
Exemplo n.º 10
0
        public void Test_RemoteClient()
        {
            SocketServer socketServer = new SocketServer("127.0.0.1", 9001);

            Console.WriteLine("Waiting for client to connect");
            SocketServerPlayer socketPlayer = socketServer.Listen(60000);

            Assert.IsNotNull(socketPlayer);
            Console.WriteLine("Socket client connected");

            PlayerInfo pi = socketPlayer.OnServerConnect();

            Console.WriteLine("Player connected");
            Assert.AreEqual("SocketClientTest", pi.Name);

            GameDefinition gameDef = new GameDefinition();

            gameDef.Name = "Test game";

            string[]  cardNames1 = new string[] { "Q", "K", "A" };
            CardSet[] cardSets1  = new CardSet[]
            {
                new CardSet {
                    bits = 0x01
                },
                new CardSet {
                    bits = 0x02
                },
                new CardSet {
                    bits = 0x10
                }
            };

            gameDef.DeckDescr = new metagame.DeckDescriptor("TestDeck", cardNames1, cardSets1);


            socketPlayer.OnSessionBegin("Test session", gameDef, new Dictionary <string, string> {
                { "p1", "v1" },
                { "p2", "v2" }
            });

            socketPlayer.OnGameBegin("gamestring OnGameBegin");

            socketPlayer.OnGameUpdate("gamestring OnGameUpdate");

            PokerAction action = socketPlayer.OnActionRequired("gamestring OnActionRequired");

            Assert.AreEqual(Ak.r, action.Kind);
            Assert.AreEqual(100, action.Amount);
            Console.WriteLine("Action received");

            socketPlayer.OnGameEnd("gamestring OnGameEnd");

            socketPlayer.OnSessionEnd();

            socketPlayer.OnServerDisconnect("End of test");
            socketPlayer.Disconnect();
        }
Exemplo n.º 11
0
        public string OnServerMessage(string textMessage)
        {
            if (textMessage.StartsWith("#") || textMessage.StartsWith(";"))
            {
                // Ignore comments
                return(null);
            }

            ServerMessage msg         = new ServerMessage(textMessage);
            int           ourPosition = 1 - msg.AcpcPosition;

            int nextActor = (msg.Betting[msg.Round].Length) % 2;

            if (msg.Round > 0)
            {
                // reversed blinds
                nextActor = 1 - nextActor;
            }

            GameRecord gr = new GameRecord();

            // For now fill only fields that are necessary for Patience.

            gr.Id = msg.HandNumber;
            for (int p = 0; p < 2; ++p)
            {
                gr.Players.Add(new GameRecord.Player(OPPONENT_NAME, 0, p == 0 ? 0.5 : 1.0, 0));
            }

            gr.Players[ourPosition].Name = PlayerName;

            if (msg.Betting[0].Length == 0)
            {
                // Empty action string for round 0 - game started.
                GameCount++;
                Player.OnGameBegin(gr.ToGameString());
            }

            // Add actions to the game record after the call to OnGameBegin().
            ParseActionsForHe(msg, gr);

            if (nextActor != ourPosition)
            {
                // If we are not acting, do not update the bot.
                return(null);
            }

            if (msg.IsGameOver())
            {
                return(null);
            }

            PokerAction response = Player.OnActionRequired(gr.ToGameString());

            string responseText = textMessage + ":" + response.Kind.ToString();

            return(responseText);
        }
Exemplo n.º 12
0
        private static void ProcessGameContext(GameContext context)
        {
            int            nodeId = context.Global.NodeId++;
            GameDefinition gd     = context.Global.GameDef;
            ActionTree     tree   = context.Global.Tree;

            // Store it before we possible change the state to skip dealer actions.
            int lastActor = context.GameState.LastActor;
            int round     = context.GameState.Round;

            while (!context.GameState.IsGameOver && context.GameState.IsDealerActing)
            {
                List <Ak> kinds = context.GameState.GetAllowedActions(gd);
                foreach (Ak kind in kinds)
                {
                    PokerAction action = new PokerAction
                    {
                        Kind     = kind,
                        Position = context.GameState.CurrentActor
                    };
                    context.GameState.UpdateByAction(action, gd);
                }
            }

            if (tree != null)
            {
                tree.SetDepth(nodeId, (byte)context.Depth);
                tree.Nodes[nodeId].Position      = lastActor;
                tree.Nodes[nodeId].Amount        = context.Amount;
                tree.Nodes[nodeId].ActivePlayers = context.GameState.GetActivePlayers();
                tree.Nodes[nodeId].Round         = round;
            }

            if (context.GameState.IsGameOver)
            {
                return;
            }

            // Deal next cards.
            List <Ak> actions = context.GameState.GetAllowedActions(gd);

            foreach (Ak actionKind in actions)
            {
                GameContext childContext = new GameContext(context);
                childContext.Depth++;
                int         position = context.GameState.CurrentActor;
                PokerAction a        = new PokerAction(actionKind, position, 0, "");
                if (a.Kind == Ak.r)
                {
                    a.Amount = gd.BetStructure[context.GameState.Round];
                }
                childContext.GameState.UpdateByAction(a, gd);
                childContext.Amount = childContext.GameState.Players[position].InPot -
                                      context.GameState.Players[position].InPot;
                ProcessGameContext(childContext);
                context.ChildCount += childContext.ChildCount + 1;
            }
        }
Exemplo n.º 13
0
 public override PokerAction OnActionRequired(string gameString)
 {
     base.OnActionRequired(gameString);
     if (CurGameState.BetCount < GameDefinition.BetsCountLimits[CurGameState.Round])
     {
         return(PokerAction.r(0, 0));
     }
     return(PokerAction.c(0));
 }
Exemplo n.º 14
0
        public override PokerAction OnActionRequired(string gameString)
        {
            base.OnActionRequired(gameString);
            List <Ak>   possibleActions = CurGameState.GetAllowedActions(GameDefinition);
            int         i      = _rng.Next(possibleActions.Count);
            PokerAction action = new PokerAction(possibleActions[i], 0, 0, "");

            return(action);
        }
        static IConvertedPokerAction ConvertedActionFrom(string sqlAction)
        {
            ActionTypes theWhat = PokerAction.GetActionWhatFromSql(sqlAction.Substring(0, 1));

            double parsedRatio;
            double theRatio = double.TryParse(sqlAction.Substring(1), out parsedRatio) ? parsedRatio : 1.0;

            return(new ConvertedPokerAction(theWhat, theRatio));
        }
Exemplo n.º 16
0
 public Play(PokerAction action, decimal amount, float decisionTime, long handId, long playerId, string aiDecisionStr, short aiDecisionStrType)
 {
     this.action            = action;
     this.amount            = amount;
     this.decisionTime      = decisionTime;
     this.handId            = handId;
     this.playerId          = playerId;
     this.aiDecisionStrType = aiDecisionStrType;
     this.aiDecisionStr     = aiDecisionStr;
 }
Exemplo n.º 17
0
        void CalculateGameResult()
        {
            if (_state.IsShowdownRequired)
            {
                UInt32[] ranks = new UInt32[_state.Players.Length];
                int [][] hands = new int[_state.Players.Length][];
                for (int p = 0; p < _state.Players.Length; ++p)
                {
                    if (!_state.Players[p].IsFolded)
                    {
                        hands[p] = _gameDef.DeckDescr.GetIndexes(_state.Players[p].Hand);
                    }
                }
                _gameDef.GameRules.Showdown(_gameDef, hands, ranks);
                long ranksSum = 0;
                for (int p = 0; p < ranks.Length; ++p)
                {
                    if (ranks[p] < 0)
                    {
                        throw new ApplicationException(String.Format("Negative rank {0} for player # {1}", ranks[p], p));
                    }
                    ranksSum += ranks[p];
                }
                if (ranksSum == 0)
                {
                    throw new ApplicationException("At least one rank must be non-negative");
                }
                _state.UpdateByShowdown(ranks, _gameDef);
            }

            // Update the main game record and players' game records.
            // Make private cards of non-folders visible for other players.
            // Update stacks.
            for (int p = 0; p < _players.Count; ++p)
            {
                _gameRecord.Players[p].Result     = _state.Players[p].Result;
                _gameRecord.IsGameOver            = _state.IsGameOver;
                _players[p].gameRecord.IsGameOver = _state.IsGameOver;
                _players[p].stack = _state.Players[p].Stack;
                for (int p1 = 0; p1 < _players.Count; ++p1)
                {
                    _players[p].gameRecord.Players[p1].Result = _state.Players[p1].Result;
                }
                for (int a = 0; a < _players[p].gameRecord.Actions.Count; ++a)
                {
                    PokerAction action = _players[p].gameRecord.Actions[a];
                    if (action.Kind == Ak.d &&
                        (action.Position == -1 || !_state.Players[action.Position].IsFolded))
                    {
                        action.Cards = _gameRecord.Actions[a].Cards;
                    }
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Deals cards for the next game. Is used if not replaying from game log.
        /// </summary>
        GameRecord DealCards()
        {
            GameRecord dealRecord = new GameRecord();

            int cardsToDealCount = 0;

            for (int r = 0; r < _gameDef.RoundsCount; ++r)
            {
                cardsToDealCount +=
                    (_gameDef.PrivateCardsCount[r] + _gameDef.PublicCardsCount[r]) * _sessionPlayers.Count
                    + _gameDef.SharedCardsCount[r];
            }

            if (cardsToDealCount > 0)
            {
                _dealer.Shuffle(cardsToDealCount);

                int dealt = 0;
                for (int r = 0; r < _gameDef.RoundsCount; ++r)
                {
                    if (_gameDef.PrivateCardsCount[r] > 0)
                    {
                        for (int p = 0; p < _sessionPlayers.Count; ++p)
                        {
                            dealRecord.Actions.Add(PokerAction.d(p, _gameDef.DeckDescr.GetCardNames(
                                                                     _dealer.Sequence, dealt,
                                                                     _gameDef.PrivateCardsCount[r])));
                            dealt += _gameDef.PrivateCardsCount[r];
                        }
                    }

                    if (_gameDef.PublicCardsCount[r] > 0)
                    {
                        for (int p = 0; p < _sessionPlayers.Count; ++p)
                        {
                            dealRecord.Actions.Add(PokerAction.d(p, _gameDef.DeckDescr.GetCardNames(
                                                                     _dealer.Sequence, dealt,
                                                                     _gameDef.PublicCardsCount[r])));
                            dealt += _gameDef.PublicCardsCount[r];
                        }
                    }

                    if (_gameDef.SharedCardsCount[r] > 0)
                    {
                        dealRecord.Actions.Add(PokerAction.d(_gameDef.DeckDescr.GetCardNames(
                                                                 _dealer.Sequence, dealt, _gameDef.SharedCardsCount[r])));
                        dealt += _gameDef.SharedCardsCount[r];
                    }
                }
            }

            return(dealRecord);
        }
Exemplo n.º 19
0
        public DealRecord(GameRecord cfg, DeckDescriptor deckDescr, SequenceRng randomDealer)
        {
            _cfg          = cfg;
            _deckDescr    = deckDescr;
            _randomDealer = randomDealer;

            // Loop through actions and
            // - find the fixed cards
            // - count random cards
            // - count enumerated cards

            for (int a = 0; a < _cfg.Actions.Count; ++a)
            {
                PokerAction action = _cfg.Actions[a];
                if (!action.IsDealerAction())
                {
                    continue;
                }
                string[] cards = action.Cards.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
                foreach (string card in cards)
                {
                    if (card == "?")
                    {
                        _randomCount++;
                    }
                    else if (card.Length > 0 && card.Substring(0, 1) == "#")
                    {
                        int idx = int.Parse(card.Substring(1));
                        while (_enumCounts.Count <= idx)
                        {
                            _enumCounts.Add(0);
                            _enumCombosCounts.Add(0);
                            _enumCombos.Add(new List <CardSet>());
                        }
                        _enumCounts[idx]++;
                    }
                    else
                    {
                        _fixedCards.UnionWith(_deckDescr.GetCardSet(card));
                    }
                }
            }

            // Count enumerated combinations.
            int deadCards = _fixedCards.CountCards();

            for (int i = 0; i < _enumCounts.Count; ++i)
            {
                _enumCombosCounts[i] = EnumAlgos.CountCombin(_deckDescr.Size - deadCards, _enumCounts[i]);
                deadCards           += _enumCounts[i];
            }
        }
Exemplo n.º 20
0
 private static string ActionToClearText(PokerAction response)
 {
     switch (response.Kind)
     {
         case Ak.f:
             return "F";
         case Ak.c:
             return "C";
         case Ak.r:
             return "R";
     }
     return "";
 }
Exemplo n.º 21
0
        /// <summary>
        /// Contructor for Player
        /// </summary>
        /// <param name="action">The type of action that the player performed</param>
        /// <param name="amount">The amount the player bet</param>
        /// <param name="decisionTime">The time it took for the player to make their decision</param>
        /// <param name="remainingChipsValue">The remaining value of the player's chips</param>
        public Player(string name, float remainingChipsValue)
        {
            this.name = name;
            this.remainingChipsValue = remainingChipsValue;
            actionEntered            = false;
            action     = PokerAction.Check;
            amount     = 0;
            sittingOut = false;
            holeCard1  = Card.NoCard;
            holeCard2  = Card.NoCard;

            playerID = 0;
        }
Exemplo n.º 22
0
 private void ProcessPlayerActions()
 {
     for (int a = _strategyPath.Count - 1; a < _gameRecord.Actions.Count; ++a)
     {
         PokerAction pa = _gameRecord.Actions[a];
         log.InfoFormat("{0} process {1} of pos {2}", _name, pa.Kind, pa.Position);
         ActionTreeNode nextNode = CurStrategyNode.FindChildByAction(pa.Kind);
         Debug.Assert(nextNode.State.LastActor == pa.Position);
         _strategyPath.Add(nextNode);
         if (pa.Kind == Ak.d && pa.Position == _pos)
         {
             OnDeal(pa.Cards);
         }
     }
 }
Exemplo n.º 23
0
        public void Test_IsDealerAction()
        {
            PokerAction action = new PokerAction();

            action.Kind = Ak.b;
            Assert.IsFalse(action.IsDealerAction());
            action.Kind = Ak.f;
            Assert.IsFalse(action.IsDealerAction());
            action.Kind = Ak.c;
            Assert.IsFalse(action.IsDealerAction());
            action.Kind = Ak.r;
            Assert.IsFalse(action.IsDealerAction());
            action.Kind = Ak.d;
            Assert.IsTrue(action.IsDealerAction());
        }
Exemplo n.º 24
0
 /// <summary>
 /// Process new poker actions received from the server.
 /// </summary>
 private void ProcessActions()
 {
     for (int a = _processedActionsCount; a < _gameRecord.Actions.Count; ++a, _processedActionsCount++)
     {
         PokerAction pa = _gameRecord.Actions[a];
         log.InfoFormat("{0} process {1} of pos {2}", _name, pa.Kind, pa.Position);
         ProcessAction(pa);
         StrategyTreeNode stNode = new StrategyTreeNode();
         _strategies[_pos].GetNode(_curStrNodeIdx, &stNode);
         if (stNode.IsPlayerAction(_pos))
         {
             _lastAbsStrProbab = stNode.Probab;
         }
     }
 }
Exemplo n.º 25
0
        void ParseActionsForHe(ServerMessage msg, GameRecord gr)
        {
            string[] privateCards = msg.GetPrivateCards();
            // Reverse positions for our format
            for (int p = 1; p >= 0; --p)
            {
                string cards = privateCards[p];
                if (cards == "")
                {
                    cards = "? ?";
                }
                else
                {
                    cards = CardsFromAcpc(cards);
                }
                PokerAction a = PokerAction.d(1 - p, cards);
                gr.Actions.Add(a);
            }

            for (int r = 0; r <= msg.Round; ++r)
            {
                if (r > 0)
                {
                    PokerAction a = PokerAction.d(CardsFromAcpc(msg.Cards[r]));
                    gr.Actions.Add(a);
                }
                for (int move = 0; move < msg.Betting[r].Length; ++move)
                {
                    PokerAction a        = null;
                    int         position = r == 0 ? move % 2 : 1 - (move % 2);
                    switch (msg.Betting[r][move])
                    {
                    case 'r':
                        a = PokerAction.r(position, r < 2 ? 1 : 2);
                        break;

                    case 'c':
                        a = PokerAction.c(position);
                        break;

                    case 'f':
                        a = PokerAction.f(position);
                        break;
                    }
                    gr.Actions.Add(a);
                }
            }
        }
        private void UpdateProbability(PokerAction[] actions, double probab)
        {
            StringBuilder strategicString = new StringBuilder();
            GameState     gs         = new GameState(GameDef);
            int           raiseCount = 0;

            for (int a = 1; a < actions.Length; ++a)
            {
                PokerAction pa = actions[a];
                if (pa.Kind == Ak.d)
                {
                    // Skip private deals to opponents
                    if (pa.Position > 0)
                    {
                        continue;
                    }
                    gs.UpdateByAction(pa, GameDef);
                    strategicString.Append('0');
                    strategicString.Append('d');
                    strategicString.Append(pa.Cards);
                    raiseCount = 0;
                }
                else
                {
                    double curInPot = gs.Players[pa.Position].InPot;
                    gs.UpdateByAction(pa, GameDef);
                    strategicString.Append(pa.Position.ToString());
                    if (pa.Kind == Ak.r)
                    {
                        raiseCount++;
                    }
                    strategicString.Append('p');
                    double newInPot = gs.Players[pa.Position].InPot;
                    double amount   = newInPot - curInPot;
                    strategicString.Append(amount.ToString());
                }
                strategicString.Append(' ');
            }
            int node = (int)Strategy.FindNode(strategicString.ToString(), null);

            // Just set the value.
            // It is obviously correct for non-abstract games.
            // For abstract games the cards corresponding to the same abstract cards will have the same
            // probability anyway provided that the OCFR strategy uses the same abstraction.
            Strategy.Nodes[node].Probab = probab;
        }
Exemplo n.º 27
0
        void AdjustAction(ref PokerAction action)
        {
            if (action == null || !action.IsPlayerAction())
            {
                log.WarnFormat("Player returned null action, Action replaced by fold.");
                action = new PokerAction {
                    Kind = Ak.f
                };
            }
            if (!action.IsPlayerAction())
            {
                log.WarnFormat("Player returned a non-player action: {0}. Action replaced by fold.", action);
                action = new PokerAction {
                    Kind = Ak.f
                };
            }

            action.Position = _state.CurrentActor;

            if (action.Kind == Ak.r)
            {
                if (_state.BetCount >= _gameDef.BetsCountLimits[_state.Round])
                {
                    // No more raises allowed.
                    action.Kind = Ak.c;
                }
            }

            if (action.Kind != Ak.r)
            {
                action.Amount = 0;
            }
            else
            {
                double minBet = _state.GetMinBet(_gameDef);
                double maxBet = _state.GetMaxBet(_gameDef);
                if (action.Amount < minBet)
                {
                    action.Amount = minBet;
                }
                if (action.Amount > maxBet)
                {
                    action.Amount = maxBet;
                }
            }
        }
Exemplo n.º 28
0
    private void SetOptions(Stage gameStage)
    {
        int c = 0;

        foreach (var button in Buttons)
        {
            button.GetComponentInChildren <Text>().text = gameStage.Actions[c].Name;

            int thisC = c;
            button.onClick.AddListener(() =>
            {
                option    = gameStage.Actions[thisC];
                isClicked = true;
            });

            c++;
        }
    }
Exemplo n.º 29
0
        private PokerAction GetAgentResponse()
        {
            // Check first if we have to call OnGameBegin().
            // We do it as late as possible to enable undo.
            // Only OnGameBegin() and OnActionRequired() are used
            // to interact with the bot during the game,
            // all interaction is currently done from this function.

            Cursor.Current = Cursors.WaitCursor;
            if (!HaveAgentActed())
            {
                GameRecord startGameRecord = new GameRecord(_gameRecord.ToGameString());
                startGameRecord.Actions.Clear();
                Player.OnGameBegin(startGameRecord.ToGameString());
            }
            PokerAction response = Player.OnActionRequired(_gameRecord.ToGameString());
            Cursor.Current = Cursors.Default;
            return response;
        }
Exemplo n.º 30
0
        public void Test_GameString_GameDef_NotOver()
        {
            GameDefinition gameDef = LoadGameDef();

            string gameString = "14; P1{100 .5 0} P2{200 1 0}; 0d{Ac Ad} 1d{Kc Kd};";

            GameState gs = new GameState(gameString, gameDef);

            VerifyGameState(gs, "14", false, 0, 1.5, 1, 1, 1, false, 0, 2, 0, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { Ak.f, Ak.c, Ak.r });
            VerifyPlayerState(gs.Players[0], "P1", 99.5, "Ac Ad", 0.5, 0.5, 0, false, false, true, true);
            VerifyPlayerState(gs.Players[1], "P2", 199, "Kc Kd", 1, 1, 0, false, false, true, true);

            gs.UpdateByAction(PokerAction.c(0), gameDef);
            VerifyGameState(gs, "14", false, 0, 2, 1, 1, 0, false, 1, 0, 0, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { Ak.c, Ak.r });
            VerifyPlayerState(gs.Players[0], "P1", 99, "Ac Ad", 1, 1, 0, false, false, false, true);
            VerifyPlayerState(gs.Players[1], "P2", 199, "Kc Kd", 1, 1, 0, false, false, true, true);

            gs.UpdateByAction(PokerAction.c(1), gameDef);
            VerifyGameState(gs, "14", false, 0, 2, 1, 1, 1, true, GameState.DealerPosition, 0, 0, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { Ak.d });
            VerifyPlayerState(gs.Players[0], "P1", 99, "Ac Ad", 1, 1, 0, false, false, false, true);
            VerifyPlayerState(gs.Players[1], "P2", 199, "Kc Kd", 1, 1, 0, false, false, false, true);

            gs.UpdateByAction(PokerAction.d("As 2d 4d"), gameDef);
            VerifyGameState(gs, "14", false, 1, 2, 0, 0, GameState.DealerPosition, false, 1, 1, 0, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { Ak.c, Ak.r });
            VerifyPlayerState(gs.Players[0], "P1", 99, "Ac Ad As 2d 4d", 1, 0, 0, false, false, true, true);
            VerifyPlayerState(gs.Players[1], "P2", 199, "Kc Kd As 2d 4d", 1, 0, 0, false, false, true, true);

            gs.UpdateByAction(PokerAction.r(1, gameDef.BetStructure[1]), gameDef);
            VerifyGameState(gs, "14", false, 1, 3, 1, 1, 1, false, 0, 0, 0, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { Ak.f, Ak.c, Ak.r });
            VerifyPlayerState(gs.Players[0], "P1", 99, "Ac Ad As 2d 4d", 1, 0, 0, false, false, true, true);
            VerifyPlayerState(gs.Players[1], "P2", 198, "Kc Kd As 2d 4d", 2, 1, 0, false, false, false, true);

            gs.UpdateByAction(PokerAction.f(0), gameDef);
            VerifyGameState(gs, "14", true, 1, 3, 1, 1, 0, false, GameState.InvalidPosition, 0, 1, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] {});
            VerifyPlayerState(gs.Players[0], "P1", 99, "Ac Ad As 2d 4d", 1, 0, -1, true, false, false, false);
            VerifyPlayerState(gs.Players[1], "P2", 201, "Kc Kd As 2d 4d", 2, 1, 1, false, false, false, true);
        }
Exemplo n.º 31
0
		public void ActionTaken(PokerPlayer player, PokerAction action)
		{
			ActionTaken(player, action, 0);
		}
Exemplo n.º 32
0
		public void ActionTaken(PokerPlayer player, PokerAction action, bool forced)
		{
			ActionTaken(player, action, 0, forced);
		}
Exemplo n.º 33
0
		public void ActionTaken(PokerPlayer player, PokerAction action, int val)
		{
			ActionTaken(player, action, val, false);
		}
Exemplo n.º 34
0
 private void InstanceStartPoker(PCPokerAction pcAction, GameObject npc, bool withMoney)
 {
     this.withMoney = withMoney;
     players = new ArrayList();
     this.pcAction = pcAction;
     players.Add(pcAction);
     npcAction = new PokerAction(npc, "Poker Chair: Ed", withMoney);
     ActionRunner npcActionRunner = (ActionRunner)npc.GetComponent("ActionRunner");
     npcActionRunner.ResetRoutine(npcAction, false);
     players.Add(npcAction);
     deck = new Deck();
     pot = new Pot(players, table.GetPotHook());
     board = new Board(table.GetBoardHooks());
     InitStages();
     running = true;
     playAgain = false;
     enabled=true;
 }
Exemplo n.º 35
0
		public void ActionTaken(PokerPlayer player, PokerAction action, int val, bool forced)
		{
			if (!forced)
				player.EndAction();

			if (GameProgress == PokerProgress.None || GameProgress == PokerProgress.End || Players[m_PlayerTurn] != player && !forced)
				return;

			bool done = false;
			switch (action)
			{
				case PokerAction.Check:
					{
						done = Check(player);
						break;
					}
				case PokerAction.Fold:
					{
						done = Fold(player);
						break;
					}
				case PokerAction.Raise:
					{
						done = Raise(player, val);
						break;
					}
				case PokerAction.Call:
					{
						done = Call(player);
						break;
					}
				default:
					{
						player.Mobile.SendMessage(33, "Invalid action.");
						SendBettingGump(Players[m_PlayerTurn], false);
						return;
					}
			}
			if (done)
				CalculateAction();
		}