public List <string> FindAllWords() { var words = new SortedSet <string>(); var lettersInPath = new BitArray(ScrambledWord.Length); var searcher = new FlexibleBacktrackingSearch <WordSearchState>( state => state.GetChildren(ScrambledWord, lettersInPath), true); for (int i = 0; i < ScrambledWord.Length; ++i) { string initialString = ScrambledWord[i].ToString(); var initialNode = Dictionary.FindNode(initialString); if (initialNode != null) { lettersInPath[i] = true; searcher.Search( new WordSearchState(initialString, initialNode), node => { if (node.State.IsWord && node.State.CurrentString.Length >= MinWordLength) { words.Add(node.State.CurrentString); } return(NodeOption.Continue); } ); lettersInPath[i] = false; } } return(words.ToList()); }
private void SearchStartingAtTile( Tile tile, FlexibleBacktrackingSearch <WordSearchState> stateSearcher, bool useAlternate = false) { var startingState = new WordSearchState(tile, Dictionary, useAlternate); stateSearcher.Search(startingState, node => ProcessSearchNode(node)); }
/// <summary> /// Computes all words in the puzzle grid. Returns a list of unique /// word-paths in alphabetical order. /// </summary> /// <param name="minimumWordLength">the minimum length for a word to count</param> public List <WordamentPath> FindWordsWithPaths(uint minimumWordLength = 1) { AllWordPaths.Clear(); MinimumWordLength = minimumWordLength; var stateSearcher = new FlexibleBacktrackingSearch <WordSearchState>(state => { return(state.GetChildStates(PuzzleGrid)); }); // Run flexible backtracking search starting at each tile in the grid. foreach (var tile in PuzzleGrid) { SearchStartingAtTile(tile, stateSearcher); if (tile.Type == TileType.Alternating) { SearchStartingAtTile(tile, stateSearcher, true); } } return(new List <WordamentPath>(AllWordPaths.Values)); }