cs371p: project #4: darwin


Write a program to simulate Darwin's World.

Darwin's World is a two-dimensional grid. Each square in the world can contain at most one Creature. Each creature belongs to a Species and has a set of instructions.

Each creature has three properties: a species, a direction, and a program counter. Each species has a set of instructions. A creature executes the instruction indicated by the program counter. Each creature is given a turn.

Here's an example list of instructions:

Creatures begin executing at line 0. There are two types of instructions: those which cause an action and those which affect the flow of control. Above, the only action instructions are hop and left. The rest are control instructions.

Darwin gives each Creature a turn in a left-to-right and top-down ordering. During a turn a Creature can execute only one action instruction.

Here are the descriptions of the 9 instructions:

Type Instruction Description
Action hop if the space ahead is empty, move forward, otherwise, do nothing
left turn to face left
right turn to face right
infect if the space ahead contains a creature of a different species,
change that creature to be of your species, otherwise, do nothing
resets the program counter, but leaves the direction unchanged.
Control if_empty n If the space ahead is empty, go to line n, otherwise, go to the next line.
if_wall n If the space ahead is a wall, go to line n, otherwise, go to the next line.
if_random n Randomly choose between going to line n or the next line.
If rand() from <cstdlib> returns an odd number, go to line n.
if_enemy n If the space ahead contains a creature of a different species,
go to line n, otherwise, go to the next line.
go n go to line n

You must not use new, delete, or std::allocator. All memory management must be handled by STL containers.

input


There is no input for this program.

output


Your program will write its output to cout.

correctness


Your program must produce the correct output. The provided outputs are not guaranteed correct. Use Blackboard to reach consensus on the correct output.

additional correctness


The grader will test your program with other output tests.

testing


Provide a set of unit tests in TestDarwin.h.

design


Use assert() to check pre-conditions, post-conditions, argument validity, return-value validity, and invariants.

Worry about this last, but your program should run as fast as possible and use as little memory as possible.

documentation


Information about your partnership must be in Darwin.txt, a skeleton of which is provided. Edit Darwin.txt with a plain-text editor. Do not use Word!

Use Doxygen to document interfaces:

Use C-style (/*...*/) or C++-style (//...) comments to document implementations.

Follow any coding convention, but be consistent. Use good variable names. Write readable code with good indentation, blank lines, and blank spaces.

files


Type Name Description
documentation Darwin.txt Documentation of the program.
Creature.html Documentation of the class Creature,
produced by Doxygen.
Species.html Documentation of the class Species,
produced by Doxygen.
Darwin.html Documentation of the class Darwin,
produced by Doxygen.
driver main.c++ Definition of the function main().
implementation Direction.h Definition of the enum Direction.
Operation.h Definition of the enum Operation.
Instruction.h Definition of the class Instruction.
Creature.h Definition of the class Creature.
Species.h Definition of the class Species.
Darwin.h Definition of the class Darwin.
test Test.h Definition of the class Test.
TestDarwin.h Definition of the function test_darwin().
Output Darwin.out Output of the program.

submission


Projects must be done in pairs using a technique called pair programming. Only one submission will be accepted by each pair.

You must submit the following files, and only the following files:

    Creature.css
    Creature.html
    Species.css
    Species.html
    Darwin.css
    Darwin.html
    main.c++
    Direction.h
    Operation.h
    Instruction.h
    Creature.h
    Species.h
    Darwin.h
    Test.h
    TestDarwin.h

as a ZIP file, Darwin.zip, to Turnin, by the due date.

You must post your partnership to the *** Partnerships *** thread on the class discussion board in Blackboard, a week before the due date.

You must post the following file, and only the following file:

    TestDarwin.h

as an attachment, to the *** Consensus on Final Results *** thread on the class discussion board in Blackboard, by the due date.

html & css validators


Valid XHTML 1.0 Strict Valid CSS!