Hi, I am currently working on a homework assignment with the topic being a boggle game. We are creating the boggleboard class and one of the function that must be included is this:
bool playWord (string word, string player)
This method returns false if word does not appear in the dictionary, if it is not possible to form
word on the Boggle board, or if word has fewer than three letters. Otherwise it should return true.
The second parameter is the name of the player who is playing the word.
the problem I am currently having is this part: "if it is not possible to form
word on the Boggle board, or if word has fewer than three letters."
The professor suggested we use a recursive function that will backtrack to confirm the letters on the boggleboard is valid.
He also gave us an example:
Suppose you have a 4x4 array of characters called "board" that
represents the board. Imagine a method
bool matches (str, row, col, used)
that reports whether the string "str" matches the board configuration
beginning at the specified row and col when given an array "used" that
tells us which letters on the board have been used.
If str is empty, we return true.
Otherwise, if used[row][col] is true, we return return false.
Otherwise, if board[row][col] matches the first character of the
string, and (after making used[row][col] true), the recursive call
matches (rest of str, r, c, used)
returns true (where position r,c is adjacent to position row,col), we
Otherwise, we set used[row][col] back to false and return false.
Despite this, I still don't understand how a string type and a letter on the board can relate to each other. For example, say our word is str, How do we tell the board side of things to analyze whether the letter is a "s" or not at that board space? I think for the part where it states "or if word has fewer than three letters." it is just a simple check on the used array to count up the letters we used to form the word.
I'm not looking for code, but rather comments on what thought processes I should perhaps take to reach a solution or perhaps I am missing a major concept? Thanks