Exemplo n.º 1
0
 /*
  * This method read in all of the english words from a file
  */
 public static void ReadWords()
 {
     foreach (var line in File.ReadLines($"{Directory.GetCurrentDirectory()}\\..\\..\\..\\words.txt"))
     {
         MyDictionary.GetInstance().AddWord(Punctuation.RemoveBadPunctuation(line.ToUpper()));
     }
 }
        /*
         * This method adds a line of data read in from the file
         *
         * @param newData line of data to be added to storage
         */
        public void AddData(string newData)
        {
            _eMsg.Append(newData + "\n");

            var pieces = newData.Split(" ");

            foreach (var piece in pieces)
            {
                var noPunctuation = Punctuation.RemoveBadPunctuation(piece);

                //Part of this check here is to make sure that the data doesn't have any punctuation, good or bad
                //  The reason for this is that my dictionary doesn't contain any words that have punctuation, so
                //  those words would never have a match and the cryptogram would always be unsolvable.
                //Technically, the structure I'm using here is a set, but I couldn't use an actual {@code Set} because
                //  they can't be sorted, and I wanted to sort all of the words by length
                if (!Punctuation.HasGoodPunctuation(noPunctuation) && !_data.Contains(noPunctuation))
                {
                    _data.Add(noPunctuation);
                }
            }

            //This sorts the words in the list from longest to shortest
            _data = _data.OrderBy(s => s.Length).Reverse().ToList();
        }