Exemple #1
0
        protected static void LogPAPError(Exception ex, databaseCache cache)
        {
            //Save the cache for later checking and try again
            string fileName = LogError.Log(ex, "AIError_PAP");

            cache.SaveToDisk("", fileName);
        }
        /// <summary>
        /// Initiaties a decision but overrides the player config using the specified serverType and configStr
        /// </summary>
        /// <param name="handId"></param>
        /// <param name="playerId"></param>
        /// <param name="genericGameCache"></param>
        /// <returns></returns>
        public Play GetDecision(long playerId, databaseCache genericGameCache, AIGeneration serverType, string aiConfigStr)
        {
            try
            {
                //Sort out the cacheTracker
                CacheTracker.Instance.Update(playerId, genericGameCache);
                if (serverType == AIGeneration.Undefined || aiConfigStr == null)
                {
                    CacheTracker.Instance.PlayerAiConfig(playerId, genericGameCache.TableId, out serverType, out aiConfigStr);
                }

                DecisionRequest newRequest = new DecisionRequest(playerId, genericGameCache, serverType, aiConfigStr, AIManager.RunInSafeMode);
                PreDecisionErrorChecking(newRequest.PlayerId, newRequest.Cache);

                //For now we will just use the old method
                //Determine an available AIInstance
                int selectedInstanceIndex = DetermineAvailableInstance(newRequest);

                //This could be done in a seperate thread
                if (selectedInstanceIndex == -1)
                {
                    //There were no available instances so we join the queue and wait
                    newRequest.WaitForDecision();
                }
                else
                {
                    if (ConcurrencyMode.Concurrency == ConcurrencyMode.ConcurencyModel.MultiCore)
                    {
                        Task t = Task.Factory.StartNew(aiInstanceList[selectedInstanceIndex].HandleDecisionRequest, newRequest);
                        t.Wait();
                    }
                    else
                    {
                        aiInstanceList[selectedInstanceIndex].HandleDecisionRequest(newRequest);
                    }
                }

                Play aiAction = newRequest.DecisionPlay;
                aiAction = SetDecisionTime(ValidatePlayerDecision(aiAction, newRequest.Cache));

                return(aiAction);
            }
            catch (Exception ex)
            {
                instanceSelector.instancesIdle = 0;

                for (int i = 0; i < aiInstanceList.Count; i++)
                {
                    instanceSelector.instancesIdle = instanceSelector.instancesIdle | (1 << i);
                }

                genericGameCache.readLockCounter = 0;

                string fileName = LogError.Log(ex, "PokerAIError");
                genericGameCache.SaveToDisk("", fileName);

                return(new Play(PokerAction.GeneralAIError, 0, 0, genericGameCache.getCurrentHandId(), playerId, ex.ToString(), 3));
            }

            throw new Exception("This point should never be reached.");
        }