Esempio n. 1
0
        static float CalcCPUCT(int n)
        {
            float CPUCT_EXTRA = (CPUCT_FACTOR == 0) ? 0 : CPUCT_FACTOR *FastLog.Ln((n + CPUCT_BASE + 1.0f) / CPUCT_BASE); // ?? should parentN be min 1.0f as above

            float thisCPUCT = CPUCT + CPUCT_EXTRA;

            return(thisCPUCT);
        }
Esempio n. 2
0
		/// <summary>
		/// Release the buffer into the reusable pool.
		/// </summary>

		public bool Recycle (bool threadSafe = true)
		{
#if RECYCLE_BUFFERS
 #if UNITY_EDITOR
			if (mCounter == 0)
			{
  #if DEBUG_BUFFERS
				UnityEngine.Debug.LogWarning("Releasing a buffer that's already in the pool: " + mUniqueID);
  #else
				UnityEngine.Debug.LogWarning("Releasing a buffer that's already in the pool");
  #endif
				return false;
			}
 #endif
			if (Interlocked.Decrement(ref mCounter) > 0) return false;

			Clear();

			if (mPoolCount < 250)
			{
				if (threadSafe)
				{
					lock (mPool)
					{
						++mPoolCount;
						mPool.Enqueue(this);
#if DEBUG_BUFFERS
						FastLog.Log("Recycling " + mUniqueID + " (" + mPool.Count + ")");
#endif
					}
#endif
				}
				else
				{
					++mPoolCount;
					mPool.Enqueue(this);
#if DEBUG_BUFFERS
					FastLog.Log("Recycling " + mUniqueID + " (" + mPool.Count + ")");
#endif
				}
			}
			return true;
		}
Esempio n. 3
0
        /// <summary>
        /// Calculators CPUCT coefficient for a node with specified characteristics.
        /// </summary>
        /// <param name="parentIsRoot"></param>
        /// <param name="dualSelectorMode"></param>
        /// <param name="selectorID"></param>
        /// <param name="parentN"></param>
        /// <returns></returns>
        public float CalcCPUCT(bool parentIsRoot, bool dualSelectorMode, int selectorID, float parentN)
        {
            if (parentIsRoot)
            {
                float CPUCT_EXTRA = (CPUCTFactorAtRoot == 0) ? 0 : CPUCTFactorAtRoot *FastLog.Ln((parentN + CPUCTBaseAtRoot + 1.0f) / CPUCTBaseAtRoot);

                float thisCPUCT  = CPUCTAtRoot + CPUCT_EXTRA;
                float cpuctValue = CPUCTForSelector(dualSelectorMode, selectorID, thisCPUCT);
                return(cpuctValue);
            }
            else
            {
                float CPUCT_EXTRA = (CPUCTFactor == 0) ? 0 : CPUCTFactor *FastLog.Ln((parentN + CPUCTBase + 1.0f) / CPUCTBase);

                float thisCPUCT  = CPUCT + CPUCT_EXTRA;
                float cpuctValue = CPUCTForSelector(dualSelectorMode, selectorID, thisCPUCT);
                return(cpuctValue);
            }
        }
Esempio n. 4
0
        public static T GetObject <T>(string key, T defVal) where T : new()
        {
            T obj = defVal;

            try
            {
                string objData = stringTable.GetValue(key, "");
                obj = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(objData);
                if (obj == null)
                {
                    obj = defVal;
                }
            }
            catch (Exception ex)
            {
                FastLog.Log(ex);
            }

            return(obj);
        }
Esempio n. 5
0
		/// <summary>
		/// Create a new buffer, reusing an old one if possible.
		/// </summary>

		static public Buffer Create ()
		{
			Buffer b = null;

			if (mPool.Count == 0)
			{
				b = new Buffer();
#if DEBUG_BUFFERS
				FastLog.Log("New " + b.mUniqueID);
#endif
			}
			else
			{
				lock (mPool)
				{
					if (mPoolCount > 0)
					{
						--mPoolCount;
						b = mPool.Dequeue();
#if DEBUG_BUFFERS
						FastLog.Log("Existing " + b.mUniqueID + " (" + mPool.Count + ")");
#endif
					}
					else
					{
						b = new Buffer();
#if DEBUG_BUFFERS
						FastLog.Log("New " + b.mUniqueID);
#endif
					}
				}
			}
#if RECYCLE_BUFFERS
#if UNITY_EDITOR && DEBUG_BUFFERS
			if (b.mCounter != 0) UnityEngine.Debug.LogWarning("Acquiring a buffer that's potentially in use: " + b.mUniqueID);
#endif
			b.mCounter = 1;
#endif
			return b;
		}
Esempio n. 6
0
    /// <summary>
    /// 打开一个window
    /// </summary>
    /// <param name="prefabName"></param>
    public async void OpenWindow(string prefabName, UILayer layer = UILayer.Normal, OpenUiType type = OpenUiType.First, params object[] obj)
    {
        GameObject prefab = GetUiPrefab(prefabName);

        if (prefab == null)
        {
            prefab = await ResourceManager.LoadAsync <GameObject>(prefabName);

            if (prefab == null)
            {
                FastLog.Error(string.Format("Ui {0} not found!", prefabName));
                return;
            }
            else
            {
                prefab = Instantiate(prefab);
            }
        }

        BaseUI baseUi = prefab.GetComponent <BaseUI>();

        baseUi.openType = type;
        baseUi.obj      = obj;
        switch (layer)
        {
        case UILayer.Normal:
            m_NormalController.ShowWindow(baseUi);
            break;

        case UILayer.Middle:
            m_MiddleController.ShowWindow(baseUi);
            break;

        case UILayer.High:
            m_HighController.ShowWindow(baseUi);
            break;
        }
    }