Esempio n. 1
0
            public AIInstance(InstanceSelector instanceSelector, int instanceNumber, Queue decisionRequestQueue, AIRandomControl aiRandomControl)
            {
                taskTrees = new Dictionary <RequestedInfoKey, InfoProviderTaskTree>();

                this.instanceSelector     = instanceSelector;
                this.instanceNumber       = instanceNumber;
                this.decisionRequestQueue = decisionRequestQueue;
                this.decisionInProgress   = new object();

                //Setup the AI's and providers here
                infoStore = new InfoCollection();

                infoProviderDictList = new Dictionary <InfoProviderType, InfoProviderBase>();
                aiDictList           = new Dictionary <AIGeneration, AIBase>();

                //Setup the 1st infostore instance
                var GP   = new GameProvider(infoStore, infoProviderDictList, aiRandomControl);
                var WRP  = new ProviderWinRatio.WinRatioProvider(infoStore, infoProviderDictList, aiRandomControl);
                var BP   = new BetsProvider(infoStore, infoProviderDictList, aiRandomControl);
                var CP   = new CardsProvider(infoStore, infoProviderDictList, aiRandomControl);
                var AP   = new AggressionProvider(infoStore, infoProviderDictList, aiRandomControl);
                var PAPP = new PlayerActionPredictionProvider(infoStore, infoProviderDictList, aiRandomControl);

                //Hard lock the infostore collection preventing any further changes.
                infoStore.HardLockInfoList();

                //Setup the AI list
                //We are going to lock the AI's into random mode.
                aiDictList.Add(AIGeneration.SimpleV1, new SimpleAIV1(aiRandomControl));
                aiDictList.Add(AIGeneration.SimpleV2, new SimpleAIV2(aiRandomControl));
                aiDictList.Add(AIGeneration.NeuralV1, new NeuralAIv1(aiRandomControl));
                aiDictList.Add(AIGeneration.SimpleV3, new SimpleAIV3(aiRandomControl));
                aiDictList.Add(AIGeneration.NeuralV2, new NeuralAIv2(aiRandomControl));
                aiDictList.Add(AIGeneration.SimpleV4AggressionTrack, new SimpleAIV4AggTrack(aiRandomControl));
                aiDictList.Add(AIGeneration.NeuralV3, new NeuralAIv3(aiRandomControl));
                aiDictList.Add(AIGeneration.NeuralV4, new NeuralAIv4(aiRandomControl));
                aiDictList.Add(AIGeneration.SimpleV5, new SimpleAIv5(aiRandomControl));
                aiDictList.Add(AIGeneration.SimpleV6, new SimpleAIv6(aiRandomControl));
                aiDictList.Add(AIGeneration.NeuralV5, new NeuralAIv5(aiRandomControl));
                aiDictList.Add(AIGeneration.NeuralV6, new NeuralAIv6(aiRandomControl));
                aiDictList.Add(AIGeneration.SimpleV7, new SimpleAIv7(aiRandomControl));
                aiDictList.Add(AIGeneration.CheatV1, new CheatV1(aiRandomControl));
                aiDictList.Add(AIGeneration.NeuralV7, new NeuralAIv7(aiRandomControl));

                if (ConcurrencyMode.Concurrency == ConcurrencyMode.ConcurencyModel.MultiCore)
                {
                    providerTasks = new Dictionary <InfoProviderType, Task>();
                }
                else
                {
                    providerActions = new Dictionary <InfoProviderType, Action>();
                }
            }
Esempio n. 2
0
        /// <summary>
        /// Build the local provider player cache copy so that references to the main cache are required only once.
        /// DealerIndex position is at the beginning
        /// </summary>
        private void BuildTempPlayerCache()
        {
            long    currentPlayerId;
            byte    currentPlayerPosition;
            decimal currentPlayerStack;
            decimal currentRoundBetAmount;
            decimal currentPlayerTotalMoneyInPot;

            byte[]             activePositions = decisionRequest.Cache.getActivePositions(decisionRequest.Cache.getCurrentHandDetails().dealerPosition);
            List <PokerAction> lastRoundPlayerActions;

            tempLocalPlayerCacheDict = new Dictionary <long, tempPlayerCache>();

            //Need access to the agression provider
            //This should never fail because the aggressionProvider has to be included in order to add PAP
            //AggressionProvider aggressionProvider = (AggressionProvider)allInformationProviders[InfoProviderType.AIAggression];

            //For each player we need to build the localcache
            for (int i = 0; i < activePositions.Length; i++)
            {
                currentPlayerPosition        = activePositions[i];
                currentPlayerId              = decisionRequest.Cache.getPlayerId(currentPlayerPosition);
                currentRoundBetAmount        = decisionRequest.Cache.getPlayerCurrentRoundBetAmount(currentPlayerId);
                currentPlayerTotalMoneyInPot = decisionRequest.Cache.getTotalPlayerMoneyInPot(currentPlayerId);
                currentPlayerStack           = decisionRequest.Cache.getPlayerStack(currentPlayerId);
                lastRoundPlayerActions       = decisionRequest.Cache.getPlayerLastRoundActions(currentPlayerId);

                decimal RFreq_PreFlop = 0, RFreq_PostFlop = 0, CFreq_PreFlop = 0, CFreq_PostFlop = 0, CheckFreq_PreFlop = 0, CheckFreq_PostFlop = 0, PreFlopPlayFreq = 0, PostFlopPlayFreq = 0;
                byte    aggressionDataLevel = AggressionProvider.PlayerAggressionMetricFromCache(currentPlayerId, ref RFreq_PreFlop, ref RFreq_PostFlop, ref CFreq_PreFlop, ref CFreq_PostFlop, ref CheckFreq_PreFlop, ref CheckFreq_PostFlop, ref PreFlopPlayFreq, ref PostFlopPlayFreq);

                tempLocalPlayerCacheDict.Add(currentPlayerId, new tempPlayerCache(currentPlayerId, decisionRequest.Cache.getCurrentHandId(), currentPlayerStack,
                                                                                  currentPlayerPosition, currentPlayerTotalMoneyInPot, currentRoundBetAmount,
                                                                                  lastRoundPlayerActions.Contains(PokerAction.Call), lastRoundPlayerActions.Contains(PokerAction.Raise), RFreq_PreFlop, RFreq_PostFlop, CFreq_PreFlop, CFreq_PostFlop, PreFlopPlayFreq));
                //AggressionProvider.DEFAULT_rFREQ_PREFLOP,
                //AggressionProvider.DEFAULT_rFREQ_POSTFLOP,
                //AggressionProvider.DEFAULT_cFREQ_PREFLOP,
                //AggressionProvider.DEFAULT_cFREQ_POSTFLOP,
                //AggressionProvider.DEFAULT_pFREQ_PREFLOP));
            }
        }
        /// <summary>
        /// Sets botAction and betAmount
        /// </summary>
        protected override void GetAIDecision()
        {
            botPlayWRThreshold = (decimal)AggressionProvider.ConvertPlayFreqToWinRatio((double)infoStore.GetInfoValue(InfoType.AP_AvgScaledOppPreFlopPlayFreq_Double)) * 1.10m;

            //We don't need this AI going absolutly nuts!!
            if (botPlayWRThreshold < 1.1m)
            {
                botPlayWRThreshold = 1.1m;
            }

            botRaiseWRThreshold = botPlayWRThreshold * 1.2m;

            decimal distanceToDealer = ((infoStore.GetInfoValue(InfoType.GP_DealerDistance_Byte) - 1) / (infoStore.GetInfoValue(InfoType.GP_NumActivePlayers_Byte) - 1));
            decimal currentPotValue  = infoStore.GetInfoValue(InfoType.BP_TotalPotAmount_Decimal);

            //Debug.Print("");
            //Debug.Print("AP_AvgScaledOppPreFlopPlayFreq=" + infoStore.GetInfoValue(InfoType.AP_AvgScaledOppPreFlopPlayFreq_Double).ToString());
            //Debug.Print("botPlayWRThreshold=" + botPlayWRThreshold.ToString());

            double randomNum = randomGen.NextDouble();

            if (currentWinRatio >= botRaiseWRThreshold)
            {
                //If WR is larger than raiseLevel then set action to raise 8xBigBlind
                //  If minimum call amount is larger than 8xBigBlind call
                #region code

                //Possibly consider a check raise here
                if (randomNum > 0.9 && currentRoundMinimumPlayAmount == 0 && bettingRound != 0 && distanceToDealer != 1)
                {
                    botAction = PokerAction.Check;
                }
                else if (randomNum > 0.2 || currentRoundMinimumPlayAmount == 0)
                {
                    betAmount = (decimal)infoStore.GetInfoValue(InfoType.PAP_RaiseToCallAmount_Amount);
                    botAction = PokerAction.Raise;
                }
                else
                {
                    botAction = PokerAction.Call;
                    betAmount = currentRoundMinimumPlayAmount - currentRoundPlayerBetAmount;
                }

                #endregion code
            }
            else if (currentWinRatio >= botPlayWRThreshold)
            {
                //If WR is larger than playLevel then set action to raise 4xBigBlind
                //  If minimum call amount is up to 8xbigblind call
                //  If minimum call amount is larger than 8xbigblind fold
                #region code

                if (randomNum > 0.2 && currentRoundMinimumPlayAmount > 0)
                {
                    botAction = PokerAction.Call;
                    betAmount = currentRoundMinimumPlayAmount - currentRoundPlayerBetAmount;
                }
                else
                {
                    betAmount = (decimal)infoStore.GetInfoValue(InfoType.PAP_RaiseToCallAmount_Amount);
                    botAction = PokerAction.Raise;
                }

                #endregion code
            }

            //Call if already raised pre flop
            if (bettingRound == 0 && botAction == PokerAction.Raise)
            {
                //Split down into seperate IF to make sure there is not too much of a performance hit
                if (currentDecision.Cache.getPlayerCurrentRoundActions(currentDecision.PlayerId).Contains(PokerAction.Raise))
                {
                    botAction = PokerAction.Call;
                    betAmount = currentRoundMinimumPlayAmount - currentRoundPlayerBetAmount;
                }
            }
        }