CS371p: Object-Oriented Programming

  • Fall 2024: 50595 (57), 50600 (55)
  • 26 Aug - 9 Dec 2024


Project #4: Darwin


Specification

  • Write a program, ideally with a partner, to solve Darwin [C++20 (g++ 8.3.0, C++20 standard, 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 my_species_f;
    my_species_f.add_instruction(...);
    my_species_f.add_instruction(...);
    ...
    Species my_species_h;
    my_species_h.add_instruction(...);
    my_species_h.add_instruction(...);
    ...
    Species my_species_r;
    my_species_r.add_instruction(...);
    my_species_r.add_instruction(...);
    ...
    Species my_species_t;
    my_species_t.add_instruction(...);
    my_species_t.add_instruction(...);
    ...
    // read eval print loop (REPL)
    ...
    Darwin x(72, 72);
    x.add_species("f", my_species_f);
    x.add_species("h", my_species_h);
    x.add_species("r", my_species_r);
    x.add_species("t", my_species_t);
    ...
    Creature my_creature("f", ...);
    ...
    x.add_creature(my_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 necessary for this project.


Submission

  • create a private code repo (https://gitlab.com/GitLabID/cs371p-darwin/)
  • enable issues here: Settings -> General -> Visibility, project features, permissions -> Issues
  • create the following issue labels here: Issues -> New Issue -> Labels -> Manage project labels (labels are case sensitive):
    • build (Titanium yellow)
    • code (Dark violet)
    • documentation (Gray)
    • tests (Dark coral)
  • import the issues: Issues -> Import issues -> Import CSV
  • close all issues
  • add and close new issues as you debug and develop your solution
  • provide your GitLab URL on the Canvas assignment

Repos


Rubrics

Assets Location
Correctness
  • 4 tests
  • at least 3 tests to be eligible to resubmit
  • HackerRank
  • hr_Darwin.cpp (combine Darwin.hpp and run_Darwin.cpp)
Build Files
  • .gitignore
  • .gitlab-ci.yml
  • Makefile
  • README.md
  • GitLab
Issues
  • add at least 5 more issues
  • GitLab
Unit Tests
  • test_Darwin.cpp
Acceptance Tests
  • between 10 and 15 tests, between 250 and 500 lines, total
  • max output file size of 500k
  • run checktestdata
  • do not run gcov
  • do not run Valgrind
Continuous Integration
  • GitLab Pipelines
Code
  • Darwin.hpp
Documentation
  • create inline comments if you need to explain the why of a particular implementation
  • run doxygen (Darwin.hpp only)
  • 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]

Copyright © Glenn P. Downing, 1995-2024
Updated 18 Nov 2024