Starlogo: Termites

In the Termites application you write code to make termites create nests. Termites are small insects of limited intelligence that appear to be 'programmed' to work together towards a common goal. See Wikipedia.

The program termites comes with a number of procedures ready-made:

Setup

In this code there are 100 termites coloured green who stamp their territory yellow and build it up a level. These may be new commands to you. THe STAMP command changes the colour of the terrain to the one named; the BUILD command increases the height of the terrain that the character is standing on. These represent the 'chips' of wood or plant material that the termites use to create their nests. The simulation involves the placing of blocks on these to create taller and taller mounds. The interesting thing is that the nests are self-organising, that is the mounds grow bigger as blocks are brought to them in a random fashion: the building of the nests is not programmed directly, it happens from the general movement and rules in the other blocks of code.

There are also 150 termites that set their terrain to green. Note that all termites start out green.

In this code, if a termite is standing on a yellow patch of terrain then the termite turns yellow. You can experiment with this command by changing the colour.

THe following procedures are defined in the code and can be inserted into a program by using the My Blocks/Termites area.

Take Chip

If the patch colour is yellow and the colour of the termite is green then the termite 'picks up' the raised block and turns yellow. The height of the chip is reduced by 1 using the DIG command; if this reduces the height to zero (level with the general terrain) then the terrain is turned from yellow to green. This simulates the idea of termites picking up blocks or chips of wood. The termites then carry the chips until they find a suitable place to drop them.

Drop Chip

This code simulates the action of dropping a chip by changing the terrain colour (STAMP) and building it up one level. THe termite's colour is set to green to show that it is no longer carrying a chip. This simulates the idea of a termite dropping a block or chip in as suitable place to build up its nest.

Standing on Chip

This procedure returns an output of Yes if the terrain is yellow and NO if it is not yellow. This converts the action of standing on yellow into the idea of standing on a chip.

Have Chip

This procedure returns an output of Yes if the termite is yellow and NO if it is not yellow. This allows you to identify whether a termite is holding a chip.

Main Program

The main program requires a Forever block. The termites need to move forward. The procedure Roll Dice is available to choose a random number from 1-6 for the movement (or just use FORWARD 1 or FORWARD RANDOM 6).

The termites turn either left or right. The procedures if heads left 90 and if heads right 90 are available to simulate a random choice of direction change.

The procedures Have Chip? and Standing On Chip? are available as conditions. They return an output provided by the condition.

Possible sequence of commands:

Move the termites forward

Make the termites turn

Check if a termite is standing on a chip and its colour: what action is taken as a result?

There are two possible termite colours and so two possible questions with different outcomes.