コード例 #1
0
        /// <summary>
        /// Attempts to move existing Future syncAmount positions further.
        /// </summary>
        /// <returns>Updated future</returns>
        public virtual int SyncFuture(int syncAmount, IRNG rng, int offset = 0)
        {
            var state = rng.SaveState();

            //Check if cached future is still good to advance without searching again.
            if (hasCachedFuture && CachedFuture - syncAmount >= 0)
            {
                CachedState  = state;
                CachedOffset = offset;
                return(CachedFuture -= syncAmount);
            }
            else
            {
                hasCachedFuture = false;
                return(GetFuture(rng, offset));
            }
        }
コード例 #2
0
        /// <summary>
        /// Determines number of positions to advance RNG to get DesiredResult
        /// </summary>
        /// <returns>Number of positions to advance RNG, or -1 if desired result could not be found in search depth.</returns>
        public virtual int GetFuture(IRNG rng, int offset = 0)
        {
            var state = rng.SaveState();

            if (hasCachedFuture && offset == CachedOffset && state.mti == CachedState.mti && state.mt.SequenceEqual(CachedState.mt))
            {
                return(CachedFuture);
            }

            hasCachedFuture = true;
            CachedState     = state;
            CachedOffset    = offset;

            for (int i = 0; i < SearchDepth; i++)
            {
                if (GenerateAndCheckResult(rng, i + offset))
                {
                    return(CachedFuture = i);
                }
            }

            return(CachedFuture = -1);
        }