CompSci 307
Fall 2021
Software Design and Implementation

OOLALA: Darwin Simulator

This language was invented by Nick Parlante at Stanford University where it was a classic final assignment for CS106B (their version of CompSci 101).

Create an interactive simulator for a world populated by a number of creatures, showing each creature's current species, location, and orientation, to see how they interact together (and perhaps which species dominates!).

A creature's species is determined by the program it executes each step so all creatures of the species behave the same way (by running the same program although they may each be at a different instruction of their program). A step of the simulation is completed when all non-infected creatures have run one step of their program (i.e., if a creature is infected during a step, then it does not get a chance to run its new program). The order in which creatures are selected to run their program should be random so as not to bias the simulation.

In addition to the UI features common to all applications, it should all allow the user to:

Example

This is an example of a typical program:

Program Notes Reference
# Flytrap species
ifenemy 4
left 90
go 1
infect
go 1

If a creature is ahead nearby, go to instruction 4
Turn left 90 degrees
Go back to instruction 1
Infect the other creature
Go back to instruction 1

Instruction 1
Instruction 2
Instruction 3
Instruction 4
Instruction 5

More examples are given here, but you are expected to make your own example files as well (including ones with syntactically incorrect programs).

Programs

A creature evaluates part of its program each step in which it may look in front of itself to see what’s there and then take some action. Thus a program evaluates any number of IF or GO instructions in a single step and a step ends when the program executes an action (one of the instructions HOP, LEFT, RIGHT, or INFECT). The program starts subsequent steps at the next instruction after the last one executed.

Commands
Name Description
MOVE pixels Move creature forward by the given pixels in the direction it is facing.
If moving forward would put the creature outside the world's boundaries or cause it to land on another creature, then this instruction does nothing.
LEFT degrees Turn creature in place left by the given degrees
RIGHT degrees Turn creature in place right by the given degrees
INFECT Change a creature of a different species (an “enemy”) in the space nearby ahead into this kind of creature
When a creature is infected, it changes its internal program to the same as the infecting creature (i.e., it becomes one of them)
If there is no creature in the space nearby ahead, then this instruction does nothing
IFEMPTY instruction Perform the given instruction next only if the space nearby ahead of the creature is empty and inside the world's boundary;
otherwise, go on with the next instruction
IFWALL instruction Perform the given instruction next only if the space nearby ahead of the creature is the world's boundary;
otherwise, go on with the next instruction
IFSAME instruction Perform the given instruction next only if the space nearby ahead of the creature is occupied by a creature of the same species;
otherwise, go on with the next instruction
IFENEMY instruction Perform the given instruction next only if the space nearby ahead of the creature is occupied by a creature of a different species;
otherwise, go on with the next instruction
IFRANDOM instruction Perform the given instruction next half of the time (otherwise continue with the next instruction half of the time)
This allows some creatures to exercise what might be called the rudiments of “free will”
GO instruction Perform the given instruction next, rather than the next instruction (if present)

General notes about a program's syntax:

Resources