CS 371p: Object-Oriented Programming



Project #4: Darwin


  • Due: Wed, 11 Nov, 11:59 pm
  • Write a program, ideally with a partner, to solve Darwin [C++23 (g++ 14.2.0, 2 sec, 512 MB, source 50 KB)].
  • You may not use new, delete, malloc() or free().
  • You may use the STL.
  • Inheritance is not needed for this project.

Specification


  • 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 to zero, 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.
  • Various types of creatures are defined below:
        Food
         0: left
         1: go 0
    
        Hopper
         0: hop
         1: go 0
    
        Rover
         0: if_enemy 9
         1: if_empty 7
         2: if_random 5
         3: left
         4: go 0
         5: right
         6: go 0
         7: hop
         8: go 0
         9: infect
        10: go 0
    
        Trap
         0: if_enemy 3
         1: left
         2: go 0
         3: infect
         4: go 0
  • The interface to your classes should be rich enough to be able to create your own creature without writing any code.
  • I mean something like this:
    Species species_f;
    species_f.add_instruction(...);
    species_f.add_instruction(...);
    ...
    Species species_h;
    species_h.add_instruction(...);
    species_h.add_instruction(...);
    ...
    Species species_r;
    species_r.add_instruction(...);
    species_r.add_instruction(...);
    ...
    Species species_t;
    species_t.add_instruction(...);
    species_t.add_instruction(...);
    ...
    // read eval print loop (REPL)
    ...
    Darwin x(72, 72);
    x.add_species("f", species_f);
    x.add_species("h", species_h);
    x.add_species("r", species_r);
    x.add_species("t", species_t);
    ...
    Creature creature("f", ...);
    ...
    x.add_creature(creature, ...);
    ...
  • Create a good object-oriented design with no getters and setters by writing well-defined classes that are responsible for a specific and modular part of the solution:
  • Read Getters and Setters and More on Getters and Setters
  • create a UML diagram using PlantUML and put it on GitLab as Darwin.uml and Darwin.svg

Rubrics


Name Description Points
Estimation
  • estimate and track time to completion
GitLab
  • create a private code repo (https://gitlab.com/GitLab-ID/cs371p-darwin/)
  • give the TAs Developer access
1. GitLab Issues
  • enable issues here: Settings -> General -> Visibility, project features, permissions -> Work Items
  • create the following issue labels here: Manage -> Labels (labels are case sensitive):
    • build_files (Blue-gray)
    • unit_tests (Green-cyan)
    • run (Crimson)
    • acceptance_tests (Dark sea green)
    • hackerrank (Titanium Yellow)
    • continuous_integration (Carrot orange)
    • documentation (Lavender)
    • ai_design (Dark coral)
    • ai_criteria (Dark coral)
  • create at least 30 issues with the above labels from these rubrics
  • create at least 5 more issues for bugs and optimizations
  • close all issues as you develop, debug, and optimize the solution
5
2. Build Files
  • .gitignore, ignore everything but the files listed in these rubrics
  • .gitlab-ci.yml
  • Makefile
  • README.md
5
3. Unit Tests
  • DarwinTest.cpp
  • create at least 15 Google Tests
  • run astyle, a code formatter
  • run cppcheck, a static analyzer
  • run gcov, a coverage tool
  • run Valgrind, a memory checker
15
4. Run
  • Darwin.cpp
  • add assertions for pre/post conditions, invariants, etc.
  • run astyle, a code formatter
  • run cppcheck, a static analyzer
  • do not run gcov
  • do not run valgrind
15
5. Acceptance Tests 15
6. HackerRank
  • submit Darwin.cpp to HackerRank
  • pass at least 2 of the 3 tests to be eligible for partial credit
15
7. Continuous Integration
  • show a clean build in https://gitlab.com/gpdowning-ut/cs371p-darwin/-/pipelines/ to be eligible for partial credit
  • change gpdowning to your GitLab-ID
5
8. Documentation
  • create inline comments in Darwin.cpp
  • specify the complexity of every function/method and the entire program in Darwin.cpp
  • run doxygen on Darwin.cpp to produce html
  • create Darwin.uml
  • run PlantUML to produce Darwin.svg
  • run git log to produce Darwin.log.txt
  • run git rev-parse HEAD to produce a Git SHA
  • README.md
    • Full Name
    • EID
    • GitLab ID
    • GitLab URL
    • GitLab Pipeline
    • Git SHA
    • HackerRank ID
    • Estimated completion time
    • Actual completion time
    • Comments
5
9. AI Design 10
10. AI Criteria
  • create CRITERIA.md
  • Criteria should lead to specific tests.
  • A Goldfish must be able to create the tests from only DESIGN.md and CRITERIA.md.
10
Submission
  • create a single PDF of README.md, DESIGN.md, and CRITERIA.md
  • submit that PDF to Canvas

Copyright © cs371p, 1995-2026
Updated 27 Oct 2026