private void LeftPart(Word partialWord, Lib.Node root, int limit, Rack rack, Square[,] board, Square anchor) { ExtendRight(partialWord, root, board, anchor, rack, anchor); if (limit > 0) { foreach (var e in root.Children) { if (rack.HasLetter(e.Key)) { rack.Remove(e.Key); LeftPart(partialWord.Append(e.Key, false), e.Value, limit - 1, rack, board, anchor); rack.Add(e.Key); } else if (rack.HasBlank) { rack.Remove('?'); LeftPart(partialWord.Append(e.Key, true), e.Value, limit - 1, rack, board, anchor); rack.Add('?'); } } } }
// TODO: Anchor shouldnt need to be known if we know the board is transposed or not. Find another way to // figure out if we placed a tile? private void ExtendRight(Word partialWord, Node root, Square[,] board, Square square, Rack rack, Square anchor) { if (!square.IsOccupied) { if (root.EndOfWord && square.Position != anchor.Position) { // square is off one position to the right of the word, we calc start by the end of the word minus the letter count // start is offset by 1 because it should be partialWord.Length - 1, leaving it just .Length accomplishes the same LegalMove(partialWord, square.Offset(0, -(partialWord.Length)), square.Offset(0, -1), board, rack); } foreach (var e in root.Children) { if (rack.HasLetter(e.Key) && square.CrossChecks.ContainsKey(e.Key)) { rack.Remove(e.Key); ExtendRight(partialWord.Append(e.Key, false), e.Value, board, board[square.Position.Y, square.Position.X + 1], rack, anchor); rack.Add(e.Key); } else if (rack.HasBlank && square.CrossChecks.ContainsKey(e.Key)) { rack.Remove('?'); ExtendRight(partialWord.Append(e.Key, true), e.Value, board, board[square.Position.Y, square.Position.X + 1], rack, anchor); rack.Add('?'); } } } else { var key = square.Tile.Value; if (root.Children.ContainsKey(square.Tile.Value)) { ExtendRight(partialWord.Append(key, square.HasBlank), root.Children[key], board, board[square.Position.Y, square.Position.X + 1], rack, anchor); } } }