Ejemplo n.º 1
0
        /**
         * {
         *   var progress = new Progress<int>(percent =>
         *    {
         *      textBox1.Text = percent + "%";
         *    });
         *
         *    // DoProcessing is run on the thread pool.
         *    await Task.Run(() => DoProcessing(progress));
         *    textBox1.Text = "Done!";
         *  }
         *
         *  public void DoProcessing(IProgress<int> progress)
         */
        public PlayerModel estimatePlayerModel(PlayerStats playerStats)
        {
            BaseModel baseModel = estimateBaseModel(playerStats);

            DifferencePair[] similarOppPreFlop  = getSimilarOpponents_PreFlop(baseModel.VPIP, baseModel.PFR);
            DifferencePair[] similarOppPostFlop = getSimilarOpponents_PostFlop(baseModel.Aggression, baseModel.WTP);

            var allPreFlopParams = PreFlopParams.getAllParams(TableType);
            var preFlopAD        = new EstimatedAD[allPreFlopParams.Count];

            for (int i = 0; i < allPreFlopParams.Count; i++)
            {
                preFlopAD[i] = estimateADPreFLop(playerStats, similarOppPreFlop, allPreFlopParams[i]);
            }

            var allPostFlopParams = PostFlopParams.getAllParams(TableType);
            var postFlopAD        = new EstimatedAD[allPostFlopParams.Count];

            for (int i = 0; i < allPostFlopParams.Count; i++)
            {
                postFlopAD[i] = estimateADPostFlop(playerStats, similarOppPostFlop, allPostFlopParams[i]);
            }

            return(new PlayerModel(TableType, baseModel.VPIP, baseModel.PFR, baseModel.WTP, baseModel.Aggression, preFlopAD, postFlopAD));
        }
Ejemplo n.º 2
0
        public PlayerStats(string playerName, PokerClient client, TableType tableType, int vpipPositive, int vpipTotal,
                           ActionStats[] preFlopAD, ActionStats[] postFlopAD)
        {
            PlayerName = playerName;
            Client     = client;
            _tableType = tableType;
            VPIP       = new StatValue(vpipPositive, vpipTotal);

            _allPreFlopParams  = PreFlopParams.getAllParams(tableType);
            _allPostFlopParams = PostFlopParams.getAllParams(tableType);

            PreFlopStats  = preFlopAD;
            PostFlopStats = postFlopAD;
        }
Ejemplo n.º 3
0
        public PlayerStats(string playerName, PokerClient client, TableType tableType)
        {
            PlayerName = playerName;
            Client     = client;
            _tableType = tableType;
            VPIP       = new StatValue();

            _allPreFlopParams  = PreFlopParams.getAllParams(_tableType);
            _allPostFlopParams = PostFlopParams.getAllParams(_tableType);

            PreFlopStats  = new ActionStats[_allPreFlopParams.Count];
            PostFlopStats = new ActionStats[_allPostFlopParams.Count];

            for (int i = 0; i < PreFlopStats.Length; i++)
            {
                PreFlopStats[i] = new ActionStats();
            }

            for (int i = 0; i < PostFlopStats.Length; i++)
            {
                PostFlopStats[i] = new ActionStats();
            }
        }
Ejemplo n.º 4
0
        public void increment(Hand hand)
        {
            Debug.Assert(hand.Client == Client);
            Debug.Assert(hand.PlayersNames.Count <= (int)_tableType);

            var allInList        = new List <string>();
            var activePlayerList = new List <string>(hand.PlayersNames);
            int playerIndex      = activePlayerList.FindIndex(name => name == PlayerName);

            if (playerIndex < 0)
            {
                return;
            }

            Position position            = getPlayerPosition(activePlayerList, PlayerName);
            var      lastPlayerAction    = ActionType.Fold;
            bool     playerPutMoneyInPot = false;
            bool     playerFoldedOrAllIn = false;

            // Pre-Flop
            {
                int numRaises  = 0;
                int numCallers = 0;

                foreach (Action a in hand.ActionList.Where(a => a.Street == Street.PreFlop && a.IsValidAction))
                {
                    if (playerFoldedOrAllIn || activePlayerList.Count <= 1)
                    {
                        break;
                    }

                    if (a.PlayerName == PlayerName)
                    {
                        int numPlayers = activePlayerList.Count + allInList.Count;

                        var preFlopParams = new PreFlopParams(_tableType,
                                                              position,
                                                              numCallers,
                                                              numRaises,
                                                              numPlayers,
                                                              lastPlayerAction,
                                                              inPosition(activePlayerList, a.PlayerName, numPlayers));

                        getPreFlopStats(preFlopParams).addSample(a.Type);

                        if (a.Type == ActionType.Fold || a.Type == ActionType.AllIn)
                        {
                            playerFoldedOrAllIn = true;
                        }

                        if (a.IsRaiseAction || a.Type == ActionType.Call)
                        {
                            playerPutMoneyInPot = true;
                        }

                        lastPlayerAction = a.Type;
                    }
                    else
                    {
                        if (a.Type == ActionType.Fold)
                        {
                            activePlayerList.Remove(a.PlayerName);
                        }
                        else if (a.Type == ActionType.AllIn)
                        {
                            activePlayerList.Remove(a.PlayerName);
                            allInList.Add(a.PlayerName);
                        }
                    }

                    if (a.IsRaiseAction)
                    {
                        numRaises++;
                        numCallers = 0;
                    }
                    else if (a.Type == ActionType.Call)
                    {
                        numCallers++;
                    }
                }
            }

            // VPIP
            VPIP.AddSample(playerPutMoneyInPot);

            // For each remaining streets
            for (var currentStreet = Street.Flop; currentStreet <= Street.River; currentStreet++)
            {
                if (playerFoldedOrAllIn || activePlayerList.Count <= 1)
                {
                    break;
                }

                int round     = 0;
                int numRaises = 0;

                // For each action on current street
                foreach (Action a in hand.ActionList.Where(a => (a.Street == currentStreet) && a.IsValidAction))
                {
                    if (a.PlayerName == PlayerName)
                    {
                        var numPlayers = activePlayerList.Count + allInList.Count;

                        var postFlopParams = new PostFlopParams(_tableType,
                                                                currentStreet,
                                                                round,
                                                                lastPlayerAction,
                                                                numRaises,
                                                                inPosition(activePlayerList, a.PlayerName, numPlayers),
                                                                numPlayers);

                        //round == 1 && lastPlayerAction == ActionType.Check && postFlopParams.InPosition == true
                        getPostFlopStats(postFlopParams).addSample(a.Type);

                        if (a.Type == ActionType.Fold || a.Type == ActionType.AllIn)
                        {
                            playerFoldedOrAllIn = true;
                            break;
                        }

                        lastPlayerAction = a.Type;
                        round++;
                    }
                    else
                    {
                        if (a.Type == ActionType.Fold)
                        {
                            activePlayerList.Remove(a.PlayerName);
                        }
                        else if (a.Type == ActionType.AllIn)
                        {
                            activePlayerList.Remove(a.PlayerName);
                            allInList.Add(a.PlayerName);
                        }
                    }

                    if (a.IsRaiseAction)
                    {
                        numRaises++;
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public ActionStats getPreFlopStats(PreFlopParams preFlopParams)
 {
     Debug.Assert(preFlopParams.TableType == _tableType);
     return(PreFlopStats[preFlopParams.ToIndex()]);
 }
Ejemplo n.º 6
0
 public EstimatedAD GetAD(PreFlopParams prms)
 {
     return(Model.GetPreFlopAD(prms.ToIndex()));
 }
Ejemplo n.º 7
0
        private EstimatedAD estimateADPreFLop(PlayerStats playerStats, DifferencePair[] sortedOpponents, PreFlopParams preFlopParams)
        {
            Debug.Assert(playerStats != null);

            var priorBetRaise  = new HistDistribution(_options.priorNumBins);
            var priorCheckCall = new HistDistribution(_options.priorNumBins);
            var priorFold      = new HistDistribution(_options.priorNumBins);

            var cumulativeActionStats = new ActionStats();
            int k = 0;

            for (int i = 0; (i < sortedOpponents.Length) &&
                 (k < _options.maxSimilarPlayers) &&
                 (k == 0 || sortedOpponents[i].Difference < _options.maxDifference); i++)
            {
                int playerInd = sortedOpponents[i].Index;

                if (_baseModels[playerInd].VPIP.Sigma < _options.maxBaseStatsSigma)
                {
                    ActionStats similarOponentStats = _fullStatsList[playerInd].getPreFlopStats(preFlopParams);

                    if (similarOponentStats.totalSamples() > _options.minSamples)
                    {
                        priorBetRaise.AddSample(similarOponentStats.betRaiseProbability());
                        priorCheckCall.AddSample(similarOponentStats.checkCallProbability());
                        priorFold.AddSample(similarOponentStats.foldProbability());

                        k++;
                    }
                    else
                    {
                        cumulativeActionStats.append(similarOponentStats);
                    }

                    if (cumulativeActionStats.totalSamples() > _options.minSamples)
                    {
                        priorBetRaise.AddSample(cumulativeActionStats.betRaiseProbability());
                        priorCheckCall.AddSample(cumulativeActionStats.checkCallProbability());
                        priorFold.AddSample(cumulativeActionStats.foldProbability());

                        cumulativeActionStats.clear();
                        k++;
                    }
                }
            }

            priorBetRaise.Normalize();
            priorCheckCall.Normalize();
            priorFold.Normalize();

            // Update prior
            ActionStats startStats = playerStats.getPreFlopStats(preFlopParams);

            var estBetRaise  = estimateGaussian(priorBetRaise, startStats.BetRaiseSamples, startStats.totalSamples());
            var estCheckCall = estimateGaussian(priorCheckCall, startStats.CheckCallSamples, startStats.totalSamples());
            var estFold      = estimateGaussian(priorFold, startStats.FoldSamples, startStats.totalSamples());

            if (preFlopParams.ForcedAction())
            {
                var totalMean = estBetRaise.Mean + estCheckCall.Mean + estFold.Mean;
                var scale     = 1.0f / totalMean;

                estBetRaise  = estBetRaise.Scale(scale);
                estCheckCall = estCheckCall.Scale(scale);
                estFold      = estFold.Scale(scale);
            }
            else
            {
                var totalMean = estBetRaise.Mean + estCheckCall.Mean;
                var scale     = 1.0f / totalMean;

                estBetRaise  = estBetRaise.Scale(scale);
                estCheckCall = estCheckCall.Scale(scale);
                estFold      = new GaussianDistribution(0.0f, 0.0f);
            }

            return(new EstimatedAD(estBetRaise, estCheckCall, estFold, k, startStats.totalSamples()));
        }