private void ExtendRight(DawgNode node, BoardTile boardTile) { string partialWord = node.Word; if (boardTile == null) { AddWordToValidWordsIfValid(partialWord); } else if (boardTile.CharTile == null) { if (boardTile != StartingBoardTile) { AddWordToValidWordsIfValid(partialWord); } foreach (char edge in node.Edges) { HashSet <char> boardTileCrossChecks = GetBoardTileCrossChecks(boardTile); if (!PlayerRack.ContainsCharTile(edge) || (boardTileCrossChecks != null && !boardTileCrossChecks.Contains(edge))) { continue; } char rackChar = PlayerRack.TakeCharTile(edge); string partialWordPlusEdge = partialWord + rackChar.ToString(); DawgNode nextNode = GetDawgNode(partialWordPlusEdge); BoardTile nextBoardTile = Board.GetBoardTileAtCoordinates(boardTile.X, boardTile.Y + 1); SetBoardTileCrossChecks(nextBoardTile); ExtendRight(nextNode, nextBoardTile); PlayerRack.AddCharTile(rackChar); } } else { char charOnBoardTile = boardTile.CharTile.Letter; if (!node.Edges.Contains(charOnBoardTile)) { return; } string partialWordPlusEdge = partialWord + charOnBoardTile.ToString(); DawgNode nextNode = GetDawgNode(partialWordPlusEdge); BoardTile nextBoardTile = Board.GetBoardTileAtCoordinates(boardTile.X, boardTile.Y + 1); SetBoardTileCrossChecks(nextBoardTile); ExtendRight(nextNode, nextBoardTile); } }
private void LeftPart(DawgNode node, int limit, BoardTile anchor) { ExtendRight(node, anchor); if (LeftPartIsAlreadyProvided || limit <= 0) { return; } foreach (char edge in node.Edges) { if (!PlayerRack.ContainsCharTile(edge)) { continue; } char rackChar = PlayerRack.TakeCharTile(edge); string partialWord = node.Word; string partialWordPlusEdge = partialWord + rackChar.ToString(); DawgNode nextNode = GetDawgNode(partialWordPlusEdge); LeftPart(nextNode, limit - 1, anchor); PlayerRack.AddCharTile(rackChar); } }