Ninth Assignment, due 9th December 2002

Electronic Submission, hw9

 
Submission Requirements: You must turn in a reasonable preliminary version by the main due date (9th December); this version may have a lot missing from it, but may not be just rubbish hacked together at the last minute, it must fundamentally work. If you meet this deadline, you may turn in a proper version on 16th December. Both versions should be submitted as hw9. The reason for this requirement is to ensure that you do not spend valuable time in the exam period working out how to do an assignment, you will only be making improvements to something already worked out.

The Assignment

Write a text-based adventure game. For a sample, log in to rabbit and type this command: ~data/game (note the wiggle at the beginning). Your game is not supposed to be exactly like this, which is just a simple demonstration to give you the idea. You can make the game be whatever you like. There are a number of requirements for how the programming is done, but very few requirements for how the game should play. To see the text file that defines the artificial world used by the demonstration program, follow this link. You absolutely do not have to use the same format as this file, it is for demonstration purposes only.

Requirements

Extra Credit Possibilities

(some easy-ish, some difficult)

New Tricks

Unpredictability

To make things happen unpredictably, all you need is a ranom number generator. If you #include<stdlib.h> you can use the function random() it takes no parameters, and delivers a random int between 0 and 2147483647. If you want a random number between 0 and 6, just calculate random()%7. If you want something to happen with a 1-in-7 chance, say if (random()%7==0) something; Here is a small example program.

Normally the numbers aren't really random. Each time you run a program, random() will produce exactly the same sequence of 'random' numbers. That is a good thing. It means behaviour will be reproducable, whih means things are much easier to debug. Once you beleive it works, you can make the sequence really random by calling the function srandomdev(). Just call it once at the beginning of the program, not every time you use random().

Asynchronicity

For a technique that allows things to happen behind the scenes in a program, without any input from the user (e.g. how to make monsters move around unexpectedly) look at this little program. The method it uses will only work on unix systems, not windows. You can run the program, it is perfectly safe. When it is running, type very slowly: let it run for a few seconds before giving up and thinking nothing will happen.

There are two special functions involved (note the two new #includes too): alarm(x) tells the system to send your program an alarm call in x seconds (x has to be an int). signal(SIGALRM, fff) tells your program what to do when that signal arrives. SIGALRM is the official unixy name of the signal, fff is the name of a function defined in your program (it must take one int parameter (which will be useless to you, but it must be there), and return nothing). When the alarm signal arrives, your program will suspend what it is doing, run that function, then resume what it was doing, even if it was in the middle of waiting for user input, and even if it was in the middle of a long calculation. The function can do absolutely anything, but you need to be careful: if the function modifies some data that the program was already busy modifying when the alarm arrived, the results could be unpredictable.