Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,353 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,118 people online right now. Registration is fast and FREE... Join Now!




somewhat recursive related homework question

 
Reply to this topicStart new topic

somewhat recursive related homework question, Need help with understanding some concepts

jianxu
post 30 Aug, 2008 - 08:41 PM
Post #1


New D.I.C Head

*
Joined: 30 Aug, 2008
Posts: 1

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
return true

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
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 04:05AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month