private DawgNode GetDawgNode(string word) { if (word.IsNullOrEmpty()) { return(new DawgNode(word, DawgWithAlphabet.GetAlphabet().ToHashSet())); } IEnumerable <string> wordsContainingPrefix = DawgWithAlphabet.GetWordsWithGivenPrefix(prefix: word); HashSet <char> lettersThatCanFollowPrefix = new(); foreach (string wordContainingPrefix in wordsContainingPrefix) { if (!wordContainingPrefix.Equals(word)) { lettersThatCanFollowPrefix.Add(wordContainingPrefix[word.Length]); } } return(new DawgNode(word, lettersThatCanFollowPrefix)); }
public Dictionary <BoardTile, HashSet <char> > GetCrossChecksForBoardTiles(BoardTileCollection boardTileCollection) { BoardWordRetriever boardWordRetriever = new(Board); char[] charsFromAlphabet = DawgWithAlphabet.GetAlphabet(); HashSet <char> charsFromAlphabetHashSet = charsFromAlphabet.ToHashSet(); Dictionary <BoardTile, HashSet <char> > tilesAndTheirCrossChecks = new(); foreach (BoardTile boardTile in boardTileCollection) { if (boardTile.CharTile != null) { continue; } tilesAndTheirCrossChecks.Add(boardTile, new HashSet <char>()); BoardTileVerticalWordConnectionChecker verticallityChecker = new(Board); if (!verticallityChecker.BoardTileIsVerticallyPartOfAWord(boardTile.X, boardTile.Y)) { tilesAndTheirCrossChecks[boardTile] = charsFromAlphabetHashSet; continue; } foreach (char ch in charsFromAlphabet) { Board.PlaceCharTile(boardTile.X, boardTile.Y, ch); VerticalBoardWord verticalWord = boardWordRetriever.GetVerticalWordTilesAtCoordinates(boardTile.X, boardTile.Y); if (DawgWithAlphabet.IsWordValid(verticalWord.GetWord())) { tilesAndTheirCrossChecks[boardTile].Add(ch); } Board.RemoveCharTile(boardTile.X, boardTile.Y); } } return(tilesAndTheirCrossChecks); }