private string AddLetterMappings(string word, int index, string currentKey) { string allKeys = ""; for (int i = index; i < word.Length; i++) { if (Stopping) { return(""); } string key = CBWordDict.AddToKey(currentKey, i, word[i]); if (!string.IsNullOrEmpty(allKeys)) { allKeys += ";"; } allKeys += key; // Only recurse if this word is less than the max length and there is another letter in the word if (word.Length <= CBUtilities.MaxLengthForFullWordMapping && i + 1 < word.Length) { allKeys += ";"; allKeys += AddLetterMappings(word, i + 1, key); } } return(allKeys); }
public List <string> GetPossibleWords(List <List <CrosswordBuilder.Cell> > cells, int startRow, int startCol, int length, bool isAcross) { if (!HasWordsOfLength(length)) { // Return an empty list return(null); } string wordDictKey = ""; List <string> possibleWords = null; for (int i = 0; i < length; i++) { int row = startRow + (isAcross ? 0 : i); int col = startCol + (isAcross ? i : 0); CrosswordBuilder.Cell cell = cells[row][col]; if (cell.character != ' ') { wordDictKey = CBWordDict.AddToKey(wordDictKey, i, cell.character); if (length > CBUtilities.MaxLengthForFullWordMapping) { List <string> words = GetMappedWords(length, wordDictKey); // If there are no words with this key then there are no words that fit in the given cells if (words == null) { return(null); } // If the new list is less than the one we have so far then lets use that one instead if (possibleWords == null || words.Count < possibleWords.Count) { possibleWords = words; } wordDictKey = ""; } } } // If possible words is not null then we still need to get the words if (possibleWords == null) { // If wordDictKey is empty then all the cells are blank if (string.IsNullOrEmpty(wordDictKey)) { // Return all words of the given length return(loadedWords[length]); } // Return the words using the key return(GetMappedWords(length, wordDictKey)); } return(possibleWords); }