コード例 #1
0
ファイル: Vocabulary.cs プロジェクト: dandrews/Manhood
 /// <summary>
 /// Queries the vocabulary 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>
 /// <returns></returns>
 public string Query(RNG rng, Query query)
 {
     Dictionary wordList;
     return !_wordLists.TryGetValue(query.Name, out wordList) 
         ? "MISSINGDIC" 
         : wordList.Query(rng, query);
 }
コード例 #2
0
ファイル: Synchronizer.cs プロジェクト: dandrews/Manhood
 public Synchronizer(SyncType type, long seed)
 {
     _type = type;
     _rng = new RNG(seed);
     _index = 0;
     _state = null;
     _pinned = false;
 }
コード例 #3
0
ファイル: Dictionary.cs プロジェクト: dandrews/Manhood
        internal string Query(RNG rng, Query query)
        {
            var index = String.IsNullOrEmpty(query.Subtype) ? 0 : GetSubtypeIndex(query.Subtype);
            if (index == -1)
            {
                return "BAD_SUBTYPE";
            }

            IEnumerable<DictionaryEntry> pool = _words;

            pool = query.Exclusive
                ? pool.Where(e => e.Classes.Any() && e.Classes.All(c => query.ClassFilters.Any(set => set.Any(t => t.Item2 == c))))
                : pool.Where(e => query.ClassFilters.All(set => set.Any(t => t.Item1 == (e.Classes.Contains(t.Item2)))));

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

            if (!pool.Any())
            {
                return "NOT_FOUND";
            }

            int number = String.IsNullOrEmpty(query.Carrier) ? rng.Next(pool.Sum(e => e.Weight)) + 1
                : rng.PeekAt(query.Carrier.Hash(), pool.Sum(e => e.Weight));

            foreach (var e in pool)
            {
                if (number <= e.Weight) return e.Values[index];
                number -= e.Weight;
            }

            return "NOT_FOUND";
        }
コード例 #4
0
ファイル: Hell.cs プロジェクト: Tyler-Darby/Manbox
 private static string StringRequested(RNG rng, string requestName)
 {
     var args = requestName.Split(new[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries);
     if (args.Length != 2) return "";
     switch (args[0].ToLower().Trim())
     {
         case "img":
             {
                 var results = _google.Search(args[1], 1);
                 return results.Any() ? results[0].Url : "";
             }
         case "img-small":
             {
                 var results = _google.Search(args[1], 1);
                 return results.Any() ? results[0].TbImage.Url : "";
             }
     }
     return "";
 }
コード例 #5
0
ファイル: Engine.cs プロジェクト: dandrews/Manhood
 /// <summary>
 /// Executes the specified source using a custom random number generator and returns the resulting output.
 /// </summary>
 /// <param name="input">The source to execute.</param>
 /// <param name="rng">The random number generator to use when generating output.</param>
 /// <param name="charLimit">The maximum number of characters that can be printed. An exception will be thrown if the limit is exceeded. Set to zero or below for unlimited characters.</param>
 /// <returns></returns>
 public Output Do(Source input, RNG rng, int charLimit = 0)
 {
     return new Interpreter(this, input, rng, charLimit).Run();
 }
コード例 #6
0
ファイル: Engine.cs プロジェクト: dandrews/Manhood
 /// <summary>
 /// Loads the file located at the specified path and executes it using a custom seed, returning the resulting output.
 /// </summary>
 /// <param name="path">The path to the file to execute.</param>
 /// <param name="rng">The random number generator to use when generating output.</param>
 /// <param name="charLimit">The maximum number of characters that can be printed. An exception will be thrown if the limit is exceeded. Set to zero or below for unlimited characters.</param>
 /// <returns></returns>
 public Output DoFile(string path, RNG rng, int charLimit = 0)
 {
     return new Interpreter(this, Source.FromFile(path), rng, charLimit).Run();
 }
コード例 #7
0
ファイル: Engine.cs プロジェクト: dandrews/Manhood
 /// <summary>
 /// Executes the specified string using a custom random number generator and returns the resulting output.
 /// </summary>
 /// <param name="input">The input string to execute.</param>
 /// <param name="rng">The random number generator to use when generating output.</param>
 /// <param name="charLimit">The maximum number of characters that can be printed. An exception will be thrown if the limit is exceeded. Set to zero or below for unlimited characters.</param>
 /// <returns></returns>
 public Output Do(string input, RNG rng, int charLimit = 0)
 {
     return new Interpreter(this, Source.FromString(input), rng, charLimit).Run();
 }
コード例 #8
0
ファイル: Util.cs プロジェクト: dandrews/Manhood
 public static string Unescape(string sequence, RNG rng = null)
 {
     var match = Lexer.EscapeRegex.Match(sequence);
     var count = Int32.Parse(Alt(match.Groups["count"].Value, "1"));
     bool unicode = match.Groups["unicode"].Success;
     var code = Alt(match.Groups["code"].Value, match.Groups["unicode"].Value);
     var sb = new StringBuilder();
     if (unicode)
     {
             sb.Append((char)Convert.ToUInt16(code, 16), count);
     }
     else if (code[0] == 'N') // The only escape sequence that returns more than 1 character without a quantifier
     {
         for (int i = 0; i < count; i++)
             sb.Append(Environment.NewLine);
     }
     else
     {
         Func<RNG, char> func;
         if (_escapeChars.TryGetValue(code[0], out func))
         {
             for (int i = 0; i < count; i++)
                 sb.Append(func(rng));
         }
         else
         {
             for (int i = 0; i < count; i++)
                 sb.Append(code[0]);
         }
     }
     return sb.ToString();
 }