A popular word game involves finding words from a grid of randomly generated letters. Words must be at least three letters long and formed from adjoining letters. Letters may not be reused and it is valid to move across diagonals. As an example, consider the 4x4 grid of letters below.

A B C D
E F G H
I J K L
M N O P

The word "FAB" is valid (letters in the upper left corner) and the word "KNIFE" is valid. The word "BABE" is not valid because the "B" may not be reused. The word "MINE" is not valid because the "E" is not adjacent to the "N".

Write a program that implements the above problem. The program should randomly select letters for the board. Either place a "U" next to a "Q" or to treat "QU" as a single letter. The program should show the dice tray and ask the user to enter words found in the dice tray. When the user enters ZZ (or zZ or Zz), show the following information:

  • All words the user found in the dice tray that are in the list of words from the text file (words.txt). Show all words in lowercase, 10 words per line max, guessed correctly.
  • All incorrect words the user entered that were either not in the board or not in the list of words. Must be in lowercase and duplicate words only count as one word.
  • Show all words not guessed that are in the word file from the current tray. These are the words the user did not find (and there are usually many).
  • Ask the user to play again (check case)

User-defined functions/methods must be used in the program. Do not use break or continue statements. Use any data structure of your choice. Recursion must be used for full credit. Refer to the sample output below.

Sample Run:

Generated Board:
H A H I
V W O S
E E S E
T I P W
Enter words or ZZ to quit:

tip tips sPIt SeE how show notInTheBoard
tie tee tees shows spite
have have have
shave shaves
Aardvark ZymUrgy zZ

You found these words correctly: 14

tees shaves how tie have tee spite show tip shows
see shave spit tips

Words you tried that were incorrect: 3

notintheboard aardvark zymurgy

Number of words the computer found that you could have listed: 66

awe awes epee eve eves ewe ewes hah haves haw
haws his hiss hoe hoes hos hose hoses hows ohs
owe owes pee peso pesos pet pew pews pie pies
pis pit psi set sew sews shah shoe shoes sieve
sip sit site sos sow sows spew ssh sweep sweet
ties tis veep veeps vet wave waves wee weep weeps
wet who whoa whose woe woes

Play again? N
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.