CS371p: Object-Oriented Programming



Project #4: Darwin


  • Due: Wed, 12 Nov, 11:59 pm
  • Issues: adapt Grades.csv into Darwin.csv

Specification


  • Write a program, ideally with a partner, to solve Darwin [C++20 (g++ 14.2.0, 2 sec, 512 MB, source 50 KB)].
  • 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 to represent the design. Use any UML editor that you like. The diagram needs to show data members, methods, associations and multiplicity between the classes.
  • Use Gliffy, PlantUML, yUML, or something else.
  • You may not use new, delete, malloc(), free(), or allocator. You may use the STL.
  • Inheritance is not desirable for this project.

Submission


  • create a private code repo (https://gitlab.com/GitLab-ID/cs371p-voting/)
  • enable issues here: Settings -> General -> Visibility, project features, permissions -> Issues
  • create the following issue labels here: Manage -> Labels (labels are case sensitive):
    • correctness (Crimson)
    • build_files (Blue-gray)
    • issues (Dark coral)
    • unit_tests (Green-cyan)
    • acceptance_tests (Dark sea green)
    • continuous_integration (Carrot orange)
    • code (Titanium Yellow)
    • documentation (Lavender)
    • ai_report (Deep violet)
  • import the issues: Issues -> Import issues -> Import CSV
  • close all issues
  • add and close new issues as you debug and optimize your solution
  • provide your GitLab URL on the Canvas assignment

AI Report


  • Summary of AI Interactions
    • List the tools used (e.g., ChatGPT, Copilot, etc.).
    • Debugging help (error explanation, bug location, runtime issue)
    • Conceptual clarification (CS concept, syntax, algorithm idea)
    • Code improvement (style, efficiency, readability, testing)
    • Alternative approaches (asking “is there a simpler way?”)
    • Other (describe)
  • Reflection on Use
    • What specific improvements to your code or understanding came from this AI interaction?
    • How did you decide what to keep or ignore from the AI’s suggestions?
    • Did the AI ever produce an incorrect or misleading suggestion? How did you detect that?
  • Evidence of Independent Work
    • Paste a before-and-after snippet (3–5 lines max) showing where you changed your own code in response to AI guidance.
    • In 2–3 sentences, explain what you learned by making this change.
  • Integrity Statement
    • "I confirm that the AI was used only as a helper (explainer, debugger, reviewer) and not as a code generator. All code submitted is my own work."

Repos


Rubrics


Assets Location
1. Correctness
  • 4 tests
  • at least 3 tests to be eligible to resubmit
  • hr_Darwin.cpp (combine Darwin.hpp and run_Darwin.cpp)
2. Build Files
  • .gitignore
  • .gitlab-ci.yml
  • Makefile
  • README.md
3. Issues
  • 28 issues
  • add at least 5 more issues for bugs and optimizations
4. Unit Tests
  • test_Darwin.cpp
5. Acceptance Tests
  • between 50 and 100 tests
  • run checktestdata
  • do not run gcov
  • do not run valgrind
6. Continuous Integration
  • GitLab Pipelines
7. Code
  • Darwin.hpp
8. Documentation
  • create inline comments
  • specify the complexity of every function/method and the entire program
  • explain the why
  • run doxygen on Voting.hpp
  • run git log
  • create a UML diagram to represent the design
  • use Gliffy, PlantUML, yUML, or something else
  • Darwin.html
  • Darwin.log.txt
  • Darwin.[pdf, png, svg]
9. AI Report
  • summary, reflection, evidence, integrity
  • Voting.ai.md

Copyright © Glenn P. Downing, 1995-2025
Updated 28 Oct 2025