The Darwin world is a two-dimensional grid populated by a number of creatures. Each creature inhabits a square in the grid, and faces north, south, east or west. Each creature belongs to a species, which determines how the creature behaves.
In the picture below from the Darwin simulator, there are six rover creatures indicated by a black R, four hopper creatures indicated by a red H, three flytraps indicated by a green F, and one food indicated by a blue f.
In a Darwin-world simulation, each creature acts according to its species program. In some sense the creatures are like robots that obey their program. For example, all Rovers behave the same way as do all Flytraps, but each species behaves differently from other species.
In a simulation, each creature gets a turn. During a turn, a creature executes part of its program in which it can see directly in front of itself and take an action depending on what's there. Creatures can turn left or right, move forward, and infect other creatures. Infecting a creature turns it into the same species doing the infecting. The ultimate goal is to be the fittest creature and survive by taking over the world. When a turn ends, another creature gets a turn. When every creature has had a turn the process begins again with each creature getting another turn. This continues indefinitely until there is only one species left or until some predetermined time limit is reached.
|1|| || if there is an enemy ahead, goto step 4
|| turn left
|| go (back) to step 1
|| infect the creature adjacent/in front
|| go (back) to step 1
The step numbers are not part of the actual program, but make it easier
to understand the program. A Flytrap first checks to see if there is a
creature immediately in front. If there is a creature in front, the
program jumps to step 4 and infects the creature there. If there is no
creature in front, the program continues to execute with step 2 which
makes the creature turn left. In either case the next statement is
go 1 so that program execution continues
with step 1 and the Flytrap starts over at the beginning of the
Programs begin execution with step 1 and continue with each step in
sequence although this order can change based on
if statements. A list of legal program instructions is
infectis equivalent to
goinstructions without relinquishing its turn. The turn ends only when the program executes one of the instructions
The program for a species is stored in a file with a suffix of
.spc, i.e., a flytrap species program would be
stored in a file
The first line of a file is the name of the species, and
the first letter is used when displayed in the graphical
Darwin-world. The program ends with a
blank line, or when no other instruction follows. Comments may appear
after the blank line. For example, a program for a flytrap might be
written as follows:
Flytrap ifenemy 4 left go 1 infect go 1 The flytrap sits in one place and spins. It infects anything which comes in front. Flytraps do well when they clump.
There are four supplied species:
food left go 1 food spins, its only hope is to get infected by something else when it is then "reincarnated"
Hop hop go 1 go to a wall and do nothing
For the program, see the listing above.
Rover ifenemy 11 ifwall 6 ifsame 6 hop go 1 ifrandom 9 left go 1 right go 1 infect go 1 The rover constantly moves forward. When it runs into a wall or another rover, it randomly turns left or right. It infects any creature it encounters.
You can run the program with different arguments as described below.
It's possible to combine several species, i.e.,
darwin food.spc 5 hop.spc 6 rover.spc 3
darwin foo.spc 5 rover.spc 4 -world 10 10
Write programs for each of the following species
zap rover.dthen the rover program will be written to a file named rover.spc. You'll need to edit this file using emacs to add the name of the species at the top.