HIDDEN WORD PUZZLE


INTRODUCTION

There is a kind of word puzzle where a list of words is hidden among random letters and the goal is to find the hidden words. For example, the puzzle:
 

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


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 very small one. 20 x 20 is a better size. People usually have more trouble finding small words in the puzzle than big words.)

ASSIGNMENT

You are to write a program to create a hidden word puzzle. This will demonstrate your understanding of two-dimensional arrays, strings, and file input.

First you must invent a list of words to hide. The list should have a minimum of ten words, twenty is better. Usually the words are chosen around a common theme such as wild animals, famous gangsters or politicians, volleyball, rock bands, etc. Be sure to include a few long words. Using a text editor, enter the words into a datafile, one word per line.

REQUIREMENTS

The program may use a constant puzzle size, but ideally the program should 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 the file. The program must assign the word a random location and random orientation in the square. The program must make sure the word actually fits within the puzzle boundaries (there are many ways to accomplish this - use whichever you think is best). After a place has been found for the word, the program should 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. Your program should then fill the empty cells by assigning them random letters. (Extra credit: Have the random assignment follow the distribution of occurrence of letters in natural English text).

Finally, print the completed square centered on the page (though you'll probably want it left justified for screen display during testing). Optionally, underneath the square list the hidden words, four words per line and double spaced, in columns which are centered on the page.

For example, during construction of the square above the program output might appear as:

HIDDEN WORD PUZZLE PROGRAM

*** 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
 
 

ERROR CONDITIONS

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 necessary for words which cross over each other to share common letters, as CAT and TEASE do in the example. (Being able to share letters is a MUCH more complicated problem). Your algorithm does not even have to check if the cells are occupied before it assigns a word. Words which are assigned early in the process may get clobbered by subsequent words -- that's okay.