Exemple #1
0
        /// <summary>
        /// Queries the Dictionary according to the specified criteria and returns a random match.
        /// </summary>
        /// <param name="rng">The random number generator to randomize the match with.</param>
        /// <param name="query">The search criteria to use.</param>
        /// <param name="syncState">The state object to use for carrier synchronization.</param>
        /// <returns></returns>
        public string Query(RNG rng, Query query, QueryState syncState)
        {
            RantDictionaryTable table;

            return(!_tables.TryGetValue(query.Name, out table)
                ? "[Missing Table]"
                : table.Query(rng, query, syncState));
        }
Exemple #2
0
        internal string Query(RantDictionary dictionary, RNG rng, Query query, QueryState syncState)
        {
            var index = String.IsNullOrEmpty(query.Subtype) ? 0 : GetSubtypeIndex(query.Subtype);

            if (index == -1)
            {
                return("[Bad Subtype]");
            }

            var pool = query.ClassFilter.IsEmpty
                                ? _entries
                                : _entries.Where(e => query.ClassFilter.Test(e, query.Exclusive));

            if (_hidden.Any())
            {
                var hide = _hidden.Where(hc => !query.ClassFilter.AllowsClass(hc))
                           .Except(dictionary.IncludedHiddenClasses);
                pool = pool.Where(e => !hide.Any(e.ContainsClass));
            }

            if (query.RegexFilters.Any())
            {
                pool = query.RegexFilters.Aggregate(pool, (current, regex) => current.Where(e => regex.Item1 == regex.Item2.IsMatch(e.Terms[index].Value)));
            }

            if (query.SyllablePredicate != null)
            {
                pool = pool.Where(e => query.SyllablePredicate.Test(e.Terms[index].SyllableCount));
            }

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

            return(syncState.GetEntry(query.Carrier, index, pool, rng)?[index] ?? MissingTerm);
        }
        internal string Query(RantDictionary dictionary, RNG rng, Query query, QueryState syncState)
        {
            var index = String.IsNullOrEmpty(query.Subtype) ? 0 : GetSubtypeIndex(query.Subtype);
            if (index == -1) return "[Bad Subtype]";

            var pool = query.ClassFilter.IsEmpty
                ? _entries 
                : _entries.Where(e => query.ClassFilter.Test(e, query.Exclusive));

            if (_hidden.Any())
            {
                var hide = _hidden.Where(hc => !query.ClassFilter.AllowsClass(hc))
                    .Except(dictionary.IncludedHiddenClasses);
                pool = pool.Where(e => !hide.Any(e.ContainsClass));
            }

            if (query.RegexFilters.Any())
                pool = query.RegexFilters.Aggregate(pool, (current, regex) => current.Where(e => regex.Item1 == regex.Item2.IsMatch(e.Terms[index].Value)));

            if (query.SyllablePredicate != null)
                pool = pool.Where(e => query.SyllablePredicate.Test(e.Terms[index].SyllableCount));

            if (!pool.Any()) return MissingTerm;

            return syncState.GetEntry(query.Carrier, index, pool, rng)?[index] ?? MissingTerm;
        }
Exemple #4
0
 /// <summary>
 /// Queries the RantDictionary according to the specified criteria and returns a random match.
 /// </summary>
 /// <param name="rng">The random number generator to randomize the match with.</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 string Query(RNG rng, Query query, QueryState syncState)
 {
     RantDictionaryTable table;
     return !_tables.TryGetValue(query.Name, out table) 
         ? "[Missing Table]" 
         : table.Query(this, rng, query, syncState);
 }
Exemple #5
0
		public Sandbox(RantEngine engine, RantPattern pattern, RNG rng, int sizeLimit = 0)
		{
			_engine = engine;
			_format = engine.Format;
			_sizeLimit = new Limit(sizeLimit);
			_mainOutput = new ChannelWriter(_format, _sizeLimit);
			_outputs = new Stack<ChannelWriter>();
			_outputs.Push(_mainOutput);
			_rng = rng;
			_startingGen = rng.Generation;
			_pattern = pattern;
			_objects = new ObjectStack(engine.Objects);
			_blocks = new Stack<BlockState>();
			_matches = new Stack<Match>();
			_queryState = new QueryState();
			_subroutineArgs = new Stack<Dictionary<string, RantAction>>();
			_syncManager = new SyncManager(this);
            _blockManager = new BlockManager();
			_scriptObjectStack = new Stack<object>();
            _stopwatch = new Stopwatch();
		}