Ejemplo n.º 1
0
            /// <summary>
            /// Generates and returns a name using the base names as examples.
            /// </summary>
            public string GenerateName(int minLength = 3, int maxLength = 10, char first = 'a', char second = 'b')
            {
                if (baseNames.Count < 1)
                {
                    Debug.LogError("Markov.NameGenerator: No base names supplied!");
                    return("Nameless");
                }
                bool   nameFinished = false;
                bool   chainOkay    = false;
                int    pairIndex    = -1;
                char   a            = first;
                char   b            = second;
                char   c            = 'c';
                string name         = "";

                while (!chainOkay)
                {
                    pairIndex = Random.Range(0, 676);
                    if (ChainExistsFromPair(pairIndex))
                    {
                        chainOkay = true;
                        a         = (pairIndex / 26).ToChar();
                        b         = (pairIndex % 26).ToChar();
                        name     += a.Capitalize();
                        name     += b;
                    }
                }
                while (!nameFinished)
                {
                    c = chains[pairIndex].GetRandomNext();
                    if (c != '/')
                    {
                        name     += c;
                        a         = b;
                        b         = c;
                        pairIndex = CharsToIndex(a, b);
                        if (name.Length > maxLength)
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (name.Length >= minLength)
                        {
                            nameFinished = true;
                        }
                        break;
                    }
                }
                if (nameFinished)
                {
                    return(name);
                }
                else
                {
                    return(GenerateName(minLength, maxLength, first, second));
                }
            }