コード例 #1
0
ファイル: RantEngine.cs プロジェクト: polytronicgr/Rant
 private RantOutput RunVM(Sandbox vm, double timeout)
 {
     if (_preserveCarrierState && _carrierState == null)
     {
         _carrierState = vm.CarrierState;
     }
     return(vm.Run(timeout));
 }
コード例 #2
0
ファイル: Sandbox.cs プロジェクト: polytronicgr/Rant
        public Sandbox(RantEngine engine, RantProgram pattern, RNG rng, int sizeLimit = 0, CarrierState carrierState = null,
                       RantProgramArgs args = null)
        {
            // Public members
            RNG         = rng;
            StartingGen = rng.Generation;
            Engine      = engine;
            Format      = engine.Format;
            SizeLimit   = new Limit(sizeLimit);
            Pattern     = pattern;
            PatternArgs = args;

            // Private members
            _blockManager = new BlockAttribManager();
            _stopwatch    = new Stopwatch();
            _carrierState = carrierState;

            // Output initialization
            BaseOutput = new OutputWriter(this);
            _outputs   = new Stack <OutputWriter>();
            _outputs.Push(BaseOutput);
        }
コード例 #3
0
        internal RantDictionaryTerm Query(RantDictionary dictionary, Sandbox sb, Query query, CarrierState syncState)
        {
            RebuildCache();

            int index = !String.IsNullOrEmpty(query.PluralSubtype) && sb.TakePlural()
                                ? GetSubtypeIndex(query.PluralSubtype)
                                : GetSubtypeIndex(query.Subtype);

            if (index == -1)
            {
                return(null);
            }

            var filtersEnumerable = query.GetNonClassFilters();
            var filters           = filtersEnumerable as Filter[] ?? filtersEnumerable.ToArray();

            IEnumerable <RantDictionaryEntry> pool
                = _cache.Filter(query.GetClassFilters().SelectMany(cf => cf.GenerateRequiredSet(sb.RNG)).Distinct(), dictionary, this)?.ToList();

            if (pool == null)
            {
                return(null);
            }

            if (filters.Length > 0)
            {
                pool = pool.Where((e, i) => filters.OrderBy(f => f.Priority).All(f => f.Test(dictionary, this, e, index, query)));
            }

            if (!pool.Any())
            {
                return(null);
            }

            return(query.HasCarrier
                                ? syncState.GetEntry(query.Carrier, index, pool, sb.RNG, dictionary.EnableWeighting && this.EnableWeighting)?[index]
                                : pool.ToList().PickEntry(sb.RNG, dictionary.EnableWeighting && this.EnableWeighting)?[index]);
        }
コード例 #4
0
ファイル: RantDictionary.cs プロジェクト: sizzles/Rant
 /// <summary>
 /// Queries the RantDictionary according to the specified criteria and returns a random match.
 /// </summary>
 /// <param name="sb">The sandbox the query is to be run under.</param>
 /// <param name="query">The search criteria to use.</param>
 /// <param name="syncState">The state object to use for carrier synchronization.</param>
 /// <returns></returns>
 internal RantDictionaryTerm Query(Sandbox sb, Query query, CarrierState syncState)
 {
     return(!_tables.TryGetValue(query.Name, out RantDictionaryTable table)
         ? null
         : table.Query(this, sb, query, syncState));
 }
コード例 #5
0
 public void SetUp()
 {
     pureDataFacadeMock_ = Substitute.For <IPureDataFacade>();
     carrierState_       = new CarrierState(pureDataFacadeMock_);
 }