CSE110 Spring 2001

Homework #7

Due Friday, April 6th at 5pm

Note: bold text in the examples is input from the user.


  1. [25 points] Don't take this the wrong way, you wrote a fine simulator and everything, but the thing about the ocean is that it has way more water than you have on your map. In real life the ocean is a veritable sea of water, and things like messes of smelts and bunches of shells are comparatively rare. In order to make your simulator more realistic, you should replace the smelts and shells areas -- ugh! and the ``undersea tomb'' as well -- with three identical areas that just contain water.

    Big deal, right? Well hold on, if you've implemented your simulator the way you were told (with a Move function that just takes a Location type as input), you won't be able to put the same Location type in more than one area of the map without eliciting bizzarre `teleportation' behavior whenever Ringo leaves one of the areas. This is because the Move function has no way of knowing which of the identical Locations Ringo is actually in, so it just picks the first one it finds in every case.

    But you also don't want to have a different Location type for every stretch of water in the ocean, or you'll needlessly complicate your other functions with separate cases for identical locations. What the simulator needs in this case is a Move function that takes and returns a pair of x and y coordinates rather than a Location type, so it can distinguish identical places on the map without requiring their descriptions to be unique. In order to send and return all this information at once, you'll need to use (instead of the basic Location type) an ObjectInfo structure for Ringo's location containing two integers for the x and y coordinates on the simulation map as well as an enumerated State type for the special places (such as `Ringo's hand' and `the floor') that were formerly represented as non-map Locations. Since we might want more than just Ringo to move around in the future, also add a field for the enumerated type or #define'd integer that you use to identify game objects. A prototype for the new Move function is shown below.

    ObjectInfo Move ( ObjectInfo object, char direction, Location map [5][5] ) ;
    

    Example:

    % a.out
    You are in the octopus' garden again.
    Your action: g
    You grab the octopus with your mighty European arms.
    Your action: t
    You throw the octopus onto the ground.  It is momentarily dazed.
    Your action: w
    You swim west, out of the octopus' garden, into the pointy rocks.
    Your action: n
    You swim north, out of the pointy rocks, into the prawn shop.
    Your action: n
    You swim north, out of the prawn shop, into the water.
    Your action: s
    You swim south, out of the water, into the prawn shop.
    Your action: s
    You swim south, out of the prawn shop, into the pointy rocks.
    Your action: s
    You swim south, out of the pointy rocks, into the sunken pirate ship.
    Your action: w
    You swim west, out of the sunken pirate ship, into the water.
    Your action: e
    You swim east, out of the water, into the sunken pirate ship.
    Your action: q
    You quit, bored of undersea life already.
    
  2. [30 points] Ringo still has to be careful when he goes throwing this crab around in certain water areas: it will occasionally end up in one of the other water areas. This may suit the crab, which momentarily escapes further mistreatment, but it's not so good for the plausibility of your simulation. If you want to keep bragging about it down at the wharf, you're going to have to fix the Grab and Throw functions so they use ObjectInfo structures as well. More precisely, you will have to replace the object Location array with an array of ObjectInfo structures (still indexed by the Object enum type) in order to more precisely represent the whereabouts of game objects. Then the Grab and Throw functions should take this ObjectInfo array as a parameter and modify it, instead of the old Location array. Your functions should match the prototypes below.
    void Grab ( ObjectInfo objects [100] ) ;
    void Throw ( ObjectInfo objects [100] ) ;
    

    Example:

    % a.out
    You are in the octopus' garden again.
    Your action: g
    You grab the octopus with your mighty European arms.
    Your action: t
    You throw the octopus onto the ground.  It is momentarily dazed.
    Your action: n
    You swim north, out of the octopus' garden, into the brine & spirits shop.
    Your action: e
    You swim east, out of the brine & spirits shop, into the crab's cottage.
    Your action: g
    You grab the crab.  Its hair is pretty but its clothes are drab.
    Your action: w
    You swim west, out of the crab's cottage, into the brine & spirits shop.
    Your action: w
    You swim west, out of the brine & spirits shop, into the prawn shop.
    Your action: n
    You swim north, out of the prawn shop, into the water.
    Your action: t
    You throw the crab to the floor.
    There is a crab here.
    Your action: g
    You grab the crab.  You hope it takes you to its secret lab.
    Your action: s
    You swim south, out of the water, into the prawn shop.
    Your action: s
    You swim south, out of the prawn shop, into the pointy rocks.
    Your action: s
    You swim south, out of the pointy rocks, into the sunken pirate ship.
    Your action: w
    You swim west, out of the sunken pirate ship, into the water.
    Your action: t
    You throw the crab to the floor.
    There is a crab here.
    Your action: g
    You grab the crab.  Its vest conceals a roll of hidden flab.
    Your action: q
    You quit, bored of undersea life already.
    
  3. [30 points] Speaking of plausibility, your simulated crab has been tossed around, teleported, and contaminated with biohazards, all by Ringo's hand. In the real world, that crab would ditch him as fast as it could; in your simulated world it should do no differently.

    This is where you get your sweet reward for using a function to control Ringo's movement. Each turn, before carrying out Ringo's move, simply pick a direction (north, south, east, or west) that leads away from Ringo's current location, and call the Move function using the ObjectInfo structure for the crab (if Ringo is not already weilding it) instead for Ringo. You should also set up a conditional in the Move function to produce object-specific update messages, as shown in the example below.

    Example:

    % a.out
    You are in the octopus' garden again.
    Your action: g
    You grab the octopus with your mighty European arms.
    The crab swims north, out of the crab's cottage, into the spooky sinkhole.
    Your action: t
    You throw the octopus onto the ground.  It is momentarily dazed.
    The crab swims east, out of the spooky sinkhole, into Micky Dolens' locker.
    Your action: n
    You swim north, out of the octopus' garden, into the brine & spirits shop.
    The crab tries to swim east, out of Micky Dolens' locker, but the current draws it back.
    Your action: q
    You quit, bored of undersea life already.