Darwin


Due: Thu, 6 Nov 2014, 10pm
70 pts, 7% of total grade.


Specification


Write a program to simulate Darwin's World.

Darwin's World contains a two-dimensional grid. Each square in the world can contain at most one creature.

Each creature has a species, a direction, and a program counter.

Each species has a program (a set of instructions).

A creature executes the instruction indicated by the program counter. Each creature is given a turn.

Here's an example of a creature program:

  1. if_wall 3
  2. hop
  3. go 0
  4. left
  5. go 0

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, reset the program counter, but leave the direction unchanged, otherwise, do nothing.
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. Call srand(0) at the start of every test case that uses rand().
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.

Create a good OO design by writing well-defined classes that are responsible for a specific and modular part of the solution. Avoid getters, setters, and friends, which are often signs of a bad design:

Getters and Setters

You must design an interface for the various classes.

The interface should be rich enough to be able to create the best creature without writing any code.

I mean something like this:

Species best;
best.addInstruction(...);
best.addInstruction(...);
...
Creature b1(best, ...);
Creature b2(best, ...);
...
Darwin x(72, 72);
x.addCreature(b1, ...);
x.addCreature(b2, ...);
...

Create a UML diagram to represent the design. Use any UML editor that you like. The diagram only needs to show the associations and multiplicity between the classes.

You may not use new, delete, malloc() or free(). You may use the STL.

Analysis


These are additional descriptions of the underlying math:

Requirements


  1. Estimate time to completion.
  2. Create a private Git repository at GitHub, named cs371p-darwin.
  3. Add at least 10 of these requirements as issues to the issue tracker at GitHub.
    Add at least 10 more issues, one for each bug or feature, both open and closed with a good description and a label.
  4. Invite the graders to your private code repo.
  5. Clone your private code repo onto your local directory.
  6. Make at least 5 commits, one for each bug or feature.
    If you cannot describe your changes in a sentence, you are not committing often enough.
    Make meaningful commit messages identifying the corresponding issue in the issue tracker (see closing issues via commit messages).
  7. Write unit tests in TestDarwin.c++ that test corner cases and failure cases until you have at least an average of 3 tests for each method, confirm the expected failures, and add, commit, and push to the private code repo.
  8. Implement and debug the simplest possible solution in Darwin.h and Darwin.c++ with assertions that check pre-conditions, post-conditions, argument validity, and return-value validity, until all tests pass, and add, commit, and push to the private code repo.
  9. Clone the public test repo onto your local directory.
    It is critical that you clone the public test repo into a different directory than the one you're using for your private code repo.
  10. Copy your unit tests and your acceptance tests to your clone of the public test repo, rename the files, do a git pull to synchronize your clone, and then add, commit and push to the public test repo.
    The files MUST be named EID-RunDarwin.out, EID-TestDarwin.c++, and EID-TestDarwin.out in the public test repo.
  11. Create the UML diagram.
  12. Run Doxygen, which will create html/, that then documents the interfaces to your functions.
    Create inline comments if you need to explain the why of a particular implementation.
    Use a consistent coding convention with good variable names, good indentation, blank lines, and blank spaces.
  13. Create a log of your commits in Darwin.log.
  14. Obtain the git SHA with
    git rev-parse HEAD
  15. Fill in the Google Form.
  16. It is your responsibility to protect your code from the rest of the students in the class. If your code gets out, you are as guilty as the recipient of academic dishonesty.

Requirements for getting a non-zero grade.


  1. [  5 pts] GitHub private repo with graders invited as collaborator and a log of the commits.
  2. [  5 pts] GitHub issue tracker with issues from requirements and more.
  3. [15 pts] Well designed OO solution with assertions that check pre-conditions, post-conditions, argument validity, and return-value validity.
  4. [15 pts] At least an average of 3 tests per method with good coverage in the public test repo with the precise naming of the files.
  5. [15 pts] Acceptance tests in the public test repo with the precise naming of the files.
  6. [  5 pts] UML diagram.
  7. [  5 pts] Doxygen documentation.
  8. [  5 pts] Google Form with time estimate.

Private Code Repo Files


Place the following files, with these exact names, directly in cs371p-darwin, no subfolders:

  1. Darwin.h
  2. Darwin.c++
  3. RunDarwin.c++ (do not run gcov, do not run valgrind)
  4. RunDarwin.out (no gcov output, no valgrind output)
  5. TestDarwin.c++ (average of of at least 3 unit tests per method, run gcov, run valgrind)
  6. TestDarwin.out (include gcov output, include valgrind output)
  7. Darwin.pdf (UML diagram)
  8. html/ (output of Doxygen)
  9. Darwin.log (output of git log)
  10. gitignore.txt (rename .gitignore, for your use only, no need to submit)
  11. makefile (for your use only, no need to submit)

Public Test Repo Files


Place the following files, with these exact names, directly in cs371p-fall-2014/darwin-tests/, no subfolders:

  1. EID-RunDarwin.out (no gcov output, no valgrind output)
  2. EID-TestDarwin.c++ ((at least an average of 3 tests per method, run gcov, run valgrind)
  3. EID-TestDarwin.out (include gcov output, include valgrind output)

Tools


Guides


Graders


Name GitHub ID GitHub Test Repository Google Form
Henry Chen chukhinhenry darwin-tests Google Form
Sam Thompson st028
Thanh Nguyen thanhcs
Tyler Hunt tylershunt