CSC 161 Program #2

"Wasp"

Our second program is Wasp, a Word Search Puzzle generator.

 


Logistics

This program is worth 8 points, or 8% of your final grade. The pertinent time coordinates:

  • Assigned: Apr 12, 2005
  • Design due: Apr 19, 2005
  • Program due: Apr 26, 2005

Some of the fun, new stuff we'll cover includes:

  • Pointers and dynamic memory allocation
  • 2-D arrays
  • Using the random number generator
  • Enums
  • Using pointers and pointer arithmetic rather than arrays and []
  • Friend function
  • Constructor, destructor
  • Inheritance
  • Maybe some more advanced string stuff

  



Description

Wasp will generate pseudo-random word search puzzles. These are the letter puzzles that have words embedded in a seemingly random square of characters.

The input to Wasp will be a file describing a puzzle to be built:

  1. the name of the puzzle
  2. the puzzle size... all puzzles are square, BTW
  3. the number of words in the puzzle
  4. the list of words to be used in your puzzle

The input file can be any format. Mine is just a text file containing one word per line, like this ( students.txt ).

Your output will be an HTML file, so that we can see/play your Word Search puzzle using a web browser. Here's an example puzzle: ws1.htm

Some issues:
  • Puzzles should be generated randomly. The placement of each word in the puzzle should be random. Also, the filler letters should be randomly chosen.
  • OK, let's say your trying to generate your Word Search puzzle, and your program gets stuck; it can't create a puzzle with the words and random numbers that it has been dealt. Then, try again with new random numbers. Limit the number of times you try, and if there still is no solution, then give up and tell the user you failed.
  • In most browsers, you can examine the HTML in a web page using one of the options in the "View" menu. In Mozilla, use "View/Page Source". You can do this to figure out how to write web pages for the Word Search puzzles.

A couple disclaimers:

  • Wasp should probably check that it doesn't randomly create 2 copies of any word in your list. I won't take points off if you don't check for this.
  • Your puzzles may be less interesting if they don't share letters between words. You can add code to share letters, if you like. You may want to do this randomly, for say 10-20% of the words in the puzzle. This is optional as well.
  • Wasp should check its input file for redundant words and such. This level of error-checking is optional.

     


Design Requirements

Req. #1 Use pointers - For this program, please use only pointers and pointer arithmetic to access arrays. Suggestion: go ahead and use the array brackets [], get things working, and then go back and replace the brackets using pointer arithmetic.

Req. #2 Use inheritance - Make your Word Search class a subclass of a more general-purpose class dealing with letter-based puzzles. Such a superclass (mine is called LetterPuzzle) should also be applicable to something like a Crossword puzzle.

Req. #3 Use enum - When placing words on your puzzle, you're probably going to need an (x, y) location and a direction for the word. I defined an "enum" called Direction with values of North, South, East, West, NorthEast, NorthWest, SouthEast, and SouthWest.

Req. #4 Use friend functions - Define a friend function of your Word Search class, so that it can be printed using the output stream operator, <<. You can use this for debugging. Another nice debugging trick is to define the input stream operator, >>, so that you can read in puzzles while you're debugging.

  


Grading

Same as program #1... your program will be graded on three areas:
  • Design, 25%
  • Quality, 25%
  • Function, 50%
Each of these areas is discussed in the handout: CSC 161 Program Design, Style and Testing. Please leave a README file in your folder describing your testing and the state of your program... problems, questions, etc.

thanks... yow, bill

 


Notes

Apr 12, 2005

Random numbers are covered on page 136-137 of our text. You only have to call seed() once at the beginning of your program. Don't ask for a seed value. Try this:

#include <ctime>
// blah blah blah
seed( time());

2-D arrays are covered on page 516-524. Remember to eventually change those [] references to use pointers, eh.

An example of using friend functions so that your class works with the stream operators (<< and >>) are on pages 707-713.

Apr 14, 2005

Oops. Correction on seeding your random number generator:

#include <cstdlib>
// blah blah blah
srand( time( NULL));

Sorry... yow, bill

One more thing.. it is apparent from grading Program #1 that you need a little more guidance in the testing area. So, for program #2, please include:

  • A README file describing the state of your program (what doesn't work) and where your tests are
  • You are required to create at least 5 Word Search puzzles in your testing.
  • I will also provide (next week) 5 Word Search puzzle files of my own for you to generate. You may need to massage these files if your format does not match my own. That is fine.

April 21, 2005

The requirement to write your puzzle in HTML format is dropped. You can use the wasp_check program available in the common_area of the k: drive to get HTML for your puzzle.