HIDDEN WORD PUZZLE
INTRODUCTION
There is a kind of word puzzle where a list of words is hidden amongrandom letters and the goal is to find the hidden words. For example, thepuzzle:
H T A B N BN E P I O L
C A T R S X
F S E D I L
K E E M N M
O L R I C Z
contains the hidden words: CAT, PEN, BIRD, SON, MIX, MORE, TEASE,TAB, LID, MEEK.
Within the puzzle square the words may be oriented forwards, backwards,up, down, or diagonally (right & down, left & down, right &up, left & up). (NOTE: The example above is a 5 x 5 square, a verysmall one. 20 x 20 is a better size. People usually have more trouble findingsmall words in the puzzle than big words.)
ASSIGNMENT
You are to write a program to create a hidden word puzzle. This willdemonstrate your understanding of two-dimensional arrays, strings, andfile input.
First you must invent a list of words to hide. The list should havea minimum of ten words, twenty is better. Usually the words are chosenaround a common theme such as wild animals, famous gangsters or politicians,volleyball, rock bands, etc. Be sure to include a few long words. Usinga text editor, enter the words into a datafile, one word per line.
REQUIREMENTS
The program may use a constant puzzle size, but ideally the programshould prompt the user to find out what size square to construct. Similarly,it would be nice to allow the user to enter the name of the data file.
The program builds the square by reading one word at a time from thefile. The program must assign the word a random location and random orientationin the square. The program must make sure the word actually fits withinthe puzzle boundaries (there are many ways to accomplish this - use whicheveryou think is best). After a place has been found for the word, the programshould output the word, the row and column position of it's starting letter,and optionally, it's orientation.
When all the words in the data file have been processed, print the square,showing dashes (or some other neutral character) for empty cells. Yourprogram should then fill the empty cells by assigning them random letters.(Extra credit: Have the random assignment follow the distribution of occurrenceof letters in natural English text).
Finally, print the completed square centered on the page (though you'llprobably want it left justified for screen display during testing). Optionally,underneath the square list the hidden words, four words per line and doublespaced, in columns which are centered on the page.
For example, during construction of the square above the program outputmight appear as:
*** Enter words data file name:
WORDPUZZ.DAT
*** Please enter an integer between 1 and 50 for the size
of the square: 6
CAT is located at 3,1 oriented Forwards.
PEN is located at 2,3 oriented Backwards.
BIRD is located at 1,4 oriented Down.
....
*** All words processed ***
- T A B N B
N E P I O -
C A T R S X
- S E D I L
K E E M - M
- - - - - -
*** Assigning random letters to empty spots now.
The completed puzzle, compliments of JD
H T A B N B
N E P I O L
C A T R S X
F S E D I L
K E E M N M
O L R I C Z
The hidden words are:
CAT PEN BIRD SON
BORE TEASE TAB LID
MIX MEEK
1) Reject input for square size outside range 1 to 50.
2) Terminate gracefully if the data file is
a) missing.b) has no words.
3) Reject (with a message) words that are
a) too small (1 character long).b) too long (greater than the square size).
OVERLAPPING WORDS
To simplify the program, words MAY overlap at any time. It is NOT necessaryfor words which cross over each other to share common letters, as CAT andTEASE do in the example. (Being able to share letters is a MUCH more complicatedproblem). Your algorithm does not even have to check if the cells are occupiedbefore it assigns a word. Words which are assigned early in the processmay get clobbered by subsequent words -- that's okay.