示例#1
0
 public void SetWord(string word, IUser sender)
 {
     _lastSender = sender;
     UsedWords.Add(word.ToLower());
     word        = _getValidWord(word);
     _lastLetter = word.Last();
 }
示例#2
0
        private InputCheckResult _isValidInput(string input, IUser sender)
        {
            if (sender.IsBot)
            {
                return(InputCheckResult.IsBot);
            }
            if (input.StartsWith("//"))
            {
                return(InputCheckResult.IsComment);
            }
            if (input.StartsWith(">"))
            {
                return(InputCheckResult.IsQuote);
            }
            if (input.StartsWith("<:"))
            {
                return(InputCheckResult.IsEmoji);
            }
            if (input.StartsWith(":"))
            {
                return(InputCheckResult.IsEmoji);
            }
            if (_lastSender.Id == sender.Id)
            {
                return(InputCheckResult.SameUser);
            }
            if (UsedWords.Contains(input.ToLower()))
            {
                return(InputCheckResult.RepeatedWord);
            }
            var splitWords = input.Split(" ");

            if (splitWords.Length > 1)
            {
                return(InputCheckResult.TooManyWords);
            }
            if (!input.ToLower().StartsWith(char.ToLower(_lastLetter)))
            {
                return(InputCheckResult.WrongLetter);
            }
            var words   = Language.Words.Where(w => w.ToLower().StartsWith(char.ToLower(_lastLetter))).ToList();
            var results = words.Select(w => StringComparison.LevenshteinDistance(input, w)).ToList();

            if (!char.IsLetter(input.Last()))
            {
                return(InputCheckResult.Gibberish);
            }
            if (results.Max() < 0.5f)
            {
                return(InputCheckResult.Gibberish);
            }
            if (results.Max() > 0.5f && !words.Contains(input.ToLower()))
            {
                return(InputCheckResult.NotFound);
            }
            return(InputCheckResult.Success);
        }
示例#3
0
        /// <summary>
        /// Generates a name.
        /// </summary>
        /// <returns>The name.</returns>
        public override string GenerateName()
        {
            string name = string.Empty;

            DateTime startTime = DateTime.Now;

            while (DateTime.Now < startTime.AddMilliseconds(MaxProcessingTime) &&
                   !IsNameValid(name))
            {
                string word = string.Empty;

                while (string.IsNullOrWhiteSpace(word))
                {
                    word = inputWords[random.Next(inputWords.Count)];
                }

                name = word.Substring(random.Next(0, word.Length - ORDER), ORDER);

                while (name.Length < word.Length)
                {
                    string token  = name.Substring(name.Length - ORDER, ORDER);
                    char   letter = GetLetter(token);

                    if (letter == '?')
                    {
                        break;
                    }

                    name += letter;
                }

                name = name.Substring(0, 1) + name.Substring(1).ToLower();
                name = name.ToTitleCase();
            }

            UsedWords.Add(name);

            return(name);
        }
示例#4
0
        public static char[,] CreateTable()
        {
            Words.Clear();
            int tableHeight = MenuOptionsData.TableHeight;
            int tableWidth  = MenuOptionsData.TableWidth;

            char[,] table = new char[tableHeight, tableWidth];
            Random random = new Random();

            AddWords();
            while (CheckAr(table, tableHeight, tableWidth))
            {
                if (TrueWords.Count == 0)
                {
                    UsedWords.Clear();
                    Words.Clear();
                    table = CreateTable();
                    break;
                }
                Word word1 = new Word();
                char[,] timeTable = (char[, ])table.Clone();
                string word = TrueWords[random.Next(0, TrueWords.Count)];
                TrueWords.Remove(word);
                int positionX = random.Next(0, tableWidth);
                int positionY = random.Next(0, tableHeight);
                while (!CleanAr(table, positionX, positionY))
                {
                    positionX = random.Next(0, tableWidth);
                    positionY = random.Next(0, tableHeight);
                }
                table[positionY, positionX] = word[0];
                Coords.Push(positionY);
                Coords.Push(positionX);

                for (int i = 1; i < word.Length; i++)
                {
                    if (TruePos(tableWidth, tableHeight, positionX + 1, positionY) && CleanAr(table, positionX + 1, positionY))
                    {
                        positionX++;
                        table[positionY, positionX] = word[i];
                        Coords.Push(positionY);
                        Coords.Push(positionX);
                    }
                    else if (TruePos(tableWidth, tableHeight, positionX, positionY - 1) && CleanAr(table, positionX, positionY - 1))
                    {
                        positionY--;
                        table[positionY, positionX] = word[i];
                        Coords.Push(positionY);
                        Coords.Push(positionX);
                    }
                    else if (TruePos(tableWidth, tableHeight, positionX - 1, positionY) && CleanAr(table, positionX - 1, positionY))
                    {
                        positionX--;
                        table[positionY, positionX] = word[i];
                        Coords.Push(positionY);
                        Coords.Push(positionX);
                    }
                    else if (TruePos(tableWidth, tableHeight, positionX, positionY + 1) && CleanAr(table, positionX, positionY + 1))
                    {
                        positionY++;
                        table[positionY, positionX] = word[i];
                        Coords.Push(positionY);
                        Coords.Push(positionX);
                    }
                    else
                    {
                        table = timeTable;
                        Coords.Clear();
                        break;
                    }
                }
                if (Coords.Count == 0)
                {
                    continue;
                }
                UsedWords.Add(word);
                word1.Name = word;
                bool c = true;
                for (int i = word.Length - 1; i >= 0; i--)
                {
                    positionX = Coords.Pop();
                    positionY = Coords.Pop();
                    word1.CoordsX.Add(positionX);
                    word1.CoordsY.Add(positionY);
                    if (CheckFullElem(table, positionX, positionY, tableWidth, tableHeight) || CheckVariants(table, tableWidth, tableHeight, positionX, positionY))
                    {
                        continue;
                    }
                    else
                    {
                        table = timeTable;
                        Coords.Clear();
                        UsedWords.Remove(word);
                        c = false;
                        break;
                    }
                }
                if (c)
                {
                    word1.CoordsX.Reverse();
                    word1.CoordsY.Reverse();
                    Words.Add(word1);
                }
            }
            return(table);
        }