Fall 1997 Semester
CS78 Section A
Lab 11 Assignment
Assigned 97/11/18
Due      97/12/01


Jaqueline has been on a rampage.  She's just gotten way too
creative for ya'.  She's come up with a wonderful idea (*shiver*).
The old maze file format was:

---------------------------------------------------------
rows cols
maze description
---------------------------------------------------------

where the maze description consists of 'X' for walls, ' ' for
the floor, 'S' for the start position, and 'E' for the exit
position.  And the player was a 'P' and their trail was '.'.
But that's too simple and static for her.  She wants the maze
designer to have more control.  The new maze file will look like:

---------------------------------------------------------
option_tag = option_value
.
.
.
CharMaze =
maze description
---------------------------------------------------------

where most option_tag's have their value on the line they are
on and the option_tag CharMaze has it's value on the following
lines (till the end of the file).

Valid option_tag/option_value pairs are:

  -- ROWS = rows
     the number of rows in the maze is given (Jaqueline thinks
     the maximum should now be 17)
     this option is REQUIRED
  -- COLS = cols
     the number of columns in the maze is given (the maximum is
     now 70)
     this option is REQUIRED
  -- TRAIL = 'c'
     the character that will represent the player's trail in
     the maze is given (default is still '.')
     this option is OPTIONAL
  -- WALL = 'c'
     the character that will represent walls in the maze is
     given (default is still 'X')
     this option is OPTIONAL
  -- FLOOR = 'c'
     the character that will represent floors in the maze is
     given (default is still ' ')
     this option is OPTIONAL
  -- PLAYER = 'c'
     the character that will represent the player in the maze is
     given (default is still 'P')
     this option is OPTIONAL
  -- START1 = 'c'
     the character that will represent the start position in the
     maze is given (default is still 'S')
     this represents a static (nonmobile) starting position
     this option is OPTIONAL
  -- START2 = 'c'
     the character that will represent the start position in the
     maze is given (default is 'R')
     this represents a random (moves with each playing of a maze)
     starting position -- this cannot be a WALL or an EXIT
     this random movement only happens when the player is originally
     placed in the maze -- not if they roam over the position of the
     START2 later on in play
     this option is OPTIONAL
  -- WARP1 = 'c'
     the character that will represent a warp in the maze is
     given (default is 'w')
     a warp, when the player steps on it, will randomly teleport
     the player to another location (not the exit or a wall) in
     the maze
     if the player lands on a warp (either from a START2 or from
     a WARP1 or a WARP2), it doesn't go off -- only when they
     choose to move onto it does it teleport them
     this warp lasts once -- once stepped on, it disappears
     this option is OPTIONAL
  -- WARP2 = 'c'
     the character that will represent a warp in the maze is
     given (default is 'W')
     a warp, when the player steps on it, will randomly teleport
     the player to another location (not an EXIT or a WALL) in
     the maze
     if the player lands on a warp (either from a START2 or from
     a WARP1 or a WARP2), it doesn't go off -- only when they
     choose to move onto it does it teleport them
     this warp lasts forever
     this option is OPTIONAL
  -- EXIT = 'c'
     the character that will represent the exit position in the
     maze is given (default is still 'E')
     when the player lands on this space, the game is won
     this option is OPTIONAL
  -- GOLD = 'c'
     the character that will represent gold in the maze is given
     (default is 'g')
     when the player walks onto a GOLD spot, a random amount of
     gold is given to them (something in a normal range, please)
     this option is OPTIONAL

You can assume that the option_tag starts the line and that there
will always be spacing around the equal sign and tick marks ('')
around the characters.  You should obviously change START1 to
PLAYER when displaying the maze.  You should choose a random location
to place PLAYER if START2 is present.  Only one of these two can
be in a single maze (both or more is an error -- don't use the maze).
There can be multiple EXITs, however.  Also note that all options
must preceed the CharMaze itself.  They should be read in a case
insensitive manner -- the designer should be allowed to type ExIt,
EXIT, exit, or even Exit for the EXIT option_tag.

When reading in the maze, you should catch error conditions including
(but not limited to):

  -- not having a ROWS or a COLS or both (neither?)
  -- having ROWS and COLS specified which are greater than the
     maximums allowed
  -- a maze that is too short (not enough rows)
  -- invalid characters in the maze (those other than specified in
     previously-read options)
  -- having a maze with multiple START1s or START2s or both
  -- having a maze with no START1s or START2s
  -- having a maze with no EXIT(s)

Any of the above errors should NOT play the game.  The following
problems should generate warnings (pause before displaying the
maze if warnings were generated -- make the player hit Enter,
basically before going on to the actual game play):

  -- having unrecognized option_tag's in the maze file
  -- having extra stuff at the end of the line of a maze
     description (or any line, really)
  -- having extra stuff at the end of the file (after the
     maze description is over)

The characters for WARP1 and WARP2 may be displayed if you so
choose, but play will be more interesting if FLOOR/TRAIL is
displayed instead.  This is your choice, since doing the latter
is a bit more difficult.

There are also three new commands (in addition to the directions
the player could enter before).  ? will display a help screen to
explain all the valid commands (directional and these three new
ones, basically).  g will display a character legend (explaining
what the characters that can be visible in the displayed maze
mean/stand for).  And q will allow the player to quit before they've
reached an EXIT.

Once the player has either won or quit, you'll display three things:
an appropriate message to how the game ended, the amount of gold
they collected, and statistics.  Three statistics should be kept:
the number of moves the player made, the average time it took the
player to make a move, and the average time it took the program to
process the player's moves.

The rest of the structure remains the same -- including the loop
for a yes/no to continue/start playing and the loop around entry
of a maze file name.


Jaqueline feels sorry for how much trouble you had last time helping her and has given you a selection of sample maze files. And, in case you lost yours, here's Jaqueline's copy of the previous program.
Make sure you get inputs in the right order and check for the appropriate error conditions. Remember, part of your grade comes from using what was taught this week! Use the stuff I taught this week! (That means the new function arguments, binary search, case insensitive compare, random numbers, timing, etc. Make your functions appropriate and useful.) Feel free to use previous weeks' material as well, of course. But don't work ahead. What: are you TRYING to drive me nuts? *phbbt* *grin*
You are to still perform the first four steps of the SDP. However, you won't be required to turn them in this time. If you come to me for help, I may ask you to see your SDP. And if people don't do well, I'll have you start turning it in again. But for now, you can just submit the C++ lab portion. This should be turned in as lab 11, C++ lab -- one file.
I believe that about covers it. See you in class! Remember, if you have ANY questions, please email me or come see me in my office hours. Thank you...