Parsing English commands

(This stage of the project is done in groups.)

The first stage of the project is to recognize the commands the user enters and split them up into their relevant words. Although understanding English might appear to be quite complex, in reality, most early IF games took a simplified approach: every command was assumed to be of the form verb noun.

Your task for this stage of the project is three-fold:

If you want an example of what your stage 1 project should look like, run project-if-1 on the server. This is an example game provided for you to play with. Here’s a transcript of a playthrough of project-if-1:

You are in a small, damp cave. Moisture oozes down the rock walls.
It's very dark; you can barely see.
There is a small lamp lying on the ground.

> look
You are in a small, damp cave. Moisture oozes down the rock walls.
It's very dark; you can barely see.
There is a small lamp lying on the ground.

> look lamp
The lamp is old and rusty, but still appears functional.
> get lamp
Taken.
> look
You are in a small, damp cave. Moisture oozes down the rock walls.
It's very dark; you can barely see.

> inventory
You are carrying:
  a lamp
> look lamp
The lamp is old and rusty, but still appears functional.
> drop lamp
Dropped.
> look rock
You don't see anything interesting.
> look cave
You don't see anything interesting.
> inventory
You aren't carrying anything.
> get lamp
Taken.
> light lamp
The lamp begins to glow...
> look
You are in a small, damp cave. Moisture oozes down the rock walls.
It's very dark; you can barely see.

> drop lamp
Dropped.
> eat lamp
You don't know how to do that.
> look
You are in a small, damp cave. Moisture oozes down the rock walls.
It's very dark; you can barely see.
There is a small lamp lying on the ground.
The lamp is glowing faintly.
> quit

Notice that when you look, the description of the room changes depending on whether or not we’re carrying the lamp. Similarly, you can try to look at things like the rock walls or the cave itself, and you get an error message. (But one that tries not to break the immersion! Rather than saying “that’s an error”, the game pretends that you can look at anything, it’s just that most things aren’t “interesting”.)

The sample adds a command to light the lamp; the code has to keep track of whether or not the lamp is lit, and adjust the messages printed accordingly.

Group project

Stage 1 (and only stage 1) is a group project; if you have friends you want to be in a group with, send me an email to let me know, otherwise, I will assign you to a group. Within your group you can collaborate, share ideas, and even submit identical code if you want.

Implementation hints

If you’re having trouble getting started, try these hints. (You don’t have to follow these hints if you want to structure your program differently.)

Thus, your main will end up looking something like this:

int main() {

  bool carrying_potato = false; // Is the player carrying the potato?

  while(true) {
    string line;
    getline(cin, line);

    string verb = ... ; // Split line into verb, noun
    string noun = ... ;

    if(verb == "look" and noun == "") {

    }
    else if(verb == "get" and noun == "whatever") {

    }
    else if(verb == "quit") {
      break;
    }
    else {
      cout << "You don't know how to do that." << endl;
    }

  } // end of while
}

Submitting

Save your source code file(s) into ~/projects/stage1/.