Example #1
0
        private static WordResultSet GetPatternedWordSet(string param, ListResultSet wordSet,
                                                         ref int indexStartSize,
                                                         int k, WordResultSet wrs)
        {
            Crypto        cChecker     = new Crypto();
            List <string> fixedLetters = new List <string>();

            int       currWordSize = wrs.GetWordSize();
            const int index1 = 1, index2 = 2, index3 = 3;

            if ((k - index1) >= index2)
            {
                indexStartSize = wordSet.allWordResultSets[k - index1].GetWordSize() +
                                 wordSet.allWordResultSets[k - index2].GetWordSize() +
                                 wordSet.allWordResultSets[k - index3].GetWordSize();
            }
            else if (((k - index1) > 0) & ((k - index1) < index2))
            {
                indexStartSize = wordSet.allWordResultSets[k - index1].GetWordSize() +
                                 wordSet.allWordResultSets[k - index2].GetWordSize();
            }
            else if ((k - index1) == 0)
            {
                indexStartSize = wordSet.allWordResultSets[k - index1].GetWordSize();
            }

            return(FindNewSet(param, indexStartSize, wrs, cChecker, fixedLetters, currWordSize));
        }
Example #2
0
        private int FindCombinations(string param, ListResultSet wordSet, bool doAnagram,
                                     int matchesFound, List <WordResultSet> existingSets)
        {
            int        resultSetCount = existingSets.Count;
            List <int> allPosValues   = new List <int>();

            for (int i = 0; i < resultSetCount; i++)
            {
                allPosValues.Add(0);
            }

            //loop through string rows/permutations across word sets
            while ((true) && (matchesFound < maxResults))
            {
                if (matchFound(param, doAnagram, matchesFound,
                               GetCombinedWords(existingSets, resultSetCount, allPosValues)))
                {
                    matchesFound++;
                }

                int upIndex = resultSetCount - 1;
                while (upIndex >= 0 && ++allPosValues[upIndex]
                       >= wordSet.allWordResultSets[upIndex].GetCount())
                {
                    allPosValues[upIndex] = 0;
                    upIndex--;
                }

                if (upIndex < 0)
                {
                    break;
                }
            }
            return(matchesFound);
        }
Example #3
0
        /// <summary>
        /// This method evaluates the user's input and checks for anagrams
        /// (if required) against the dictionary words. It also writes in
        /// the multi-line textbox its results accordingly as well as keeps
        /// track of how many matches were found.
        /// </summary>
        /// <param name="param">String letters entered by user</param>
        /// <param name="wordSet">List of word sets to check</param>
        /// <param name="doAnagram">Whether to check for anagrams</param>
        private void WriteOutCombinedResults(string param, ListResultSet wordSet, bool doAnagram)
        {
            int matchesFound = 0;
            List <WordResultSet> existingSets = wordSet.allWordResultSets;

            matchesFound = FindCombinations(param, wordSet, doAnagram,
                                            matchesFound, existingSets);

            WriteOutStatus("Found " + matchesFound + " matches");
        }
Example #4
0
        /// <summary>
        /// This method evaluates the word size format required
        /// by the user and returns a list of sets that adhere
        /// to the requirements.
        /// </summary>
        /// <param name="rawFormat">String letters that define a word size format</param>
        /// <returns>List of sets that adhere to the word size format</returns>
        private ListResultSet FindSets(string rawFormat)
        {
            ListResultSet resultSets = new ListResultSet();

            int[] wordSizes = Array.ConvertAll <string, int>(rawFormat.Split(','), int.Parse);
            foreach (int wordSize in wordSizes)
            {
                resultSets.AddNew(myDictionary.getWordsWithSize(wordSize));
            }
            return(resultSets);
        }
Example #5
0
        /// <summary>
        /// This method evaluates the user's innput and checks it for patterns against
        /// specific dictionary words from a list of word sets.
        /// </summary>
        /// <param name="param">String letters and placeholders of pattern</param>
        /// <param name="wordSet">List of word sets to check</param>
        /// <returns>List of modified word sets with the correct pattern</returns>
        private ListResultSet GetPatternListSet(string param, ListResultSet wordSet)
        {
            ListResultSet simplifiedSet  = new ListResultSet();
            int           indexStartSize = 0;

            for (int k = 0; k < wordSet.allWordResultSets.Count; k++)
            {
                WordResultSet wrs    = wordSet.allWordResultSets[k];
                WordResultSet newSet = GetPatternedWordSet(param, wordSet,
                                                           ref indexStartSize, k, wrs);
                simplifiedSet.AddNew(newSet);
            }

            return(simplifiedSet);
        }
Example #6
0
        /// <summary>
        /// This method helps evaluate results and starts/
        /// stops a timer while at it as well. It will
        /// call appropriate evaluation methods accordingly.
        /// </summary>
        private void FindResults()
        {
            var stopwatch = Stopwatch.StartNew();

            //Evaluate based on word size format
            ListResultSet originalSets = FindSets(rawWordSizeFormat);

            if (doAnagram && !doPattern)
            {
                //Only do anagram
                WriteOutCombinedResults(uAnagram, originalSets, doAnagram);
            }
            else
            {
                ListResultSet patternedSets = GetPatternListSet(uPattern, originalSets);
                WriteOutCombinedResults(uAnagram, patternedSets, doAnagram);
            }

            //Stop the timer
            stopwatch.Stop();
            lblTimer.Text = stopwatch.ElapsedMilliseconds + " ms";
        }