Exemple #1
0
        private static string[] GetWordsInternal(int ruleSeed)
        {
            if (ruleSeed == 1)
            {
                return((string[])vanillaPasswords.Clone());
            }

            var random = new MonoRandom(ruleSeed);

            // Start with 17 random words from the list.
            var words1 = new string[passwords.Length];

            Array.Copy(passwords, words1, passwords.Length);
            words1 = random.Shuffle(words1);

            var words = new string[35];

            Array.Copy(words1, words, 17);

            // Add more words that are similar to the base words.
            int count = 17;

            for (var i = 0; i < 17 && count < 35; i++)
            {
                var toAdd = (from w in passwords where !words.Contains(w)
                             select(word: w, pref: random.NextDouble(), dist: HammingDistance(w, words[i]))).ToArray();
                Array.Sort(toAdd, (a, b) => {
                    var r = a.dist - b.dist;
                    return(r == 0 ? a.pref.CompareTo(b.pref) : r);
                });

                var numberToAdd = Math.Min(random.Next(1, 5), 35 - count);
                for (int j = 0; j < numberToAdd; ++j)
                {
                    words[count] = toAdd[j].word;
                    ++count;
                }
            }
            Array.Sort(words);
            return(words);
        }
Exemple #2
0
        private static Dictionary <string, string> GetRulesInternal(int ruleSeed)
        {
            if (ruleSeed == 1)
            {
                return new Dictionary <string, string>(StringComparer.CurrentCultureIgnoreCase)
                       {
                           { "shell", "3.505" },
                           { "halls", "3.515" },
                           { "slick", "3.522" },
                           { "trick", "3.532" },
                           { "boxes", "3.535" },
                           { "leaks", "3.542" },
                           { "strobe", "3.545" },
                           { "bistro", "3.552" },
                           { "flick", "3.555" },
                           { "bombs", "3.565" },
                           { "break", "3.572" },
                           { "brick", "3.575" },
                           { "steak", "3.582" },
                           { "sting", "3.592" },
                           { "vector", "3.595" },
                           { "beats", "3.600" }
                       }
            }
            ;

            var random      = new MonoRandom(ruleSeed);
            var frequencies = random.Shuffle((string[])MorseCodeSolver.frequencies.Clone()).Take(FrequenciesUsed).ToArray();

            var words = new string[FrequenciesUsed];

            Array.Copy(random.Shuffle((string[])MorseCodeSolver.words.Clone()), words, FrequenciesUsed / 2);

            int i = FrequenciesUsed / 2;

            for (int j = 0; j < FrequenciesUsed / 2; ++j)
            {
                var s     = words[j].Substring(1);
                var toAdd = (from w in MorseCodeSolver.words where !words.Contains(w) && !w.EndsWith(s)
                             select(word: w, pref: random.NextDouble(), dist: CyclingLevenshteinDistance(w, words[j]))).ToArray();
                Array.Sort(toAdd, (a, b) => {
                    var r = a.dist - b.dist;
                    return(r != 0 ? r : a.pref.CompareTo(b.pref));
                });

                var numberToAdd = Math.Min(random.Next(1, 4), Math.Min(FrequenciesUsed - i, toAdd.Length));
                for (int k = 0; k < numberToAdd; ++k)
                {
                    words[i] = toAdd[k].word;
                    ++i;
                }
            }

            var dictionary = new Dictionary <string, string>(StringComparer.CurrentCultureIgnoreCase);

            for (i = 0; i < FrequenciesUsed; ++i)
            {
                dictionary.Add(words[i], frequencies[i]);
            }

            return(dictionary);
        }