[starlogo-users] Help needed for termite simulation

Yi Zhen Ng ngyizhen at gmail.com
Fri Oct 6 04:11:39 EDT 2006


Dear all,

Hi! I'm a Year 3 biology major from the National University of Singapore.
I'm working on a project and I'm hoping to simulate the behaviour of the
termites' building using this program. Specifically, I hope to build upon
the termites.slogo model from "Sample Projects" (pun intended ^_^).

In termites.slogo, the termites are told to pick up a block if they are not
carrying anything and they chance upon one, and to put it down next to
another block if they are holding one and chance upon a block.

What I hope to add on to this model, is for the termites lay a trail
pheromone(a chemical signal) and for their movement around to be influenced
by this trail pheromone as well as the block rules above.

That's where the problem comes in. I have no experience in programming. I
have read "Turtles, termites, and traffic jams" and "Adventures in
Modelling". But is still stuck on how to proceed.

So I hit upon the idea of combining the "termites.slogo" and  "slime.slogo".
Slime.slogo is also another model under "Sample Projects" which deals with
diffusion of  chemicals by turtles and following the chemicals based on
intensity. Which in principle, is equivalent to the termite trail pheromone!
So clever.... right? Sigh. I can't seem to get the pheromones to show up in
colour after I combined these two codes together.  I know its there cos
eventually my termites end up following a trail, but the trail in an
invisible one! Not like the green colour of different intensities in "
slime.slogo".

So, I've included my coding below for you guys to help look through and spot
any mistakes.

In addition, I'm hoping to add something known as "cement pheromone" to my
model. After a block is laid by a termite, I want it to secrete this cement
pheromone for a very short period of time which will attract termites to lay
blocks next to them. Also, if possible, I want to let the termites lay
block ON TOP of other block,  so that the colour intensity of  the blocks
will also be an indication of the height of the block (even
though Starlogo is a 2D environment).

Finally, is that any coding which I should learn like Java, C++ etc that
would be useful?

Any ideas/suggestions will be very very welcomed and much appreciated!

Thanks!

Cheers,
Yi Zhen
 ngyizhen at gmail.com

*Observer *
patches-own [chemical]
to setup
  ca
  crt number
  ask-patches [setchemical 0
         if (random 100) < density [setpc yellow]]
  ask-turtles [setup]
end
to go
  ask-turtles [go]
  diffuse chemical 1     ;disperse the chemical to surrounding patches
  ask-patches [set chemical chemical * 0.9
               scale-pc red chemical 0.5 10]
end


*Turtle Procedure*

to setup
  setxy random screen-width random screen-height
  setchemical chemical + 20
  setshape termite-shape
end

to go
  uphill
  rt random 40
  lt random 40
  grid-step
  setchemical chemical + 20
  search-for-chip   ; find a wood chip and pick it up
  find-new-pile     ; find another wood chip
  find-empty-spot   ; find a place to put down wood chip
end

to grid-step
  fd 1
  setxy round xcor round ycor      ;round your coordinates to the nearest
whole number
end

;the next two procedures use local variables
;in order to allow the turtles to move along the gradient of chemical
;more about local variables can be found in the StarLogo online
documentation
to uphill
  let [:dir sniff]
  if :dir >= -45 [seth heading + :dir]
end

to sniff
  let [:dir -45
       :best-val chemical
       :best-dir -100]
  let [:current chemical-towards :dir 1]
  if :current > :best-val
    [set :best-val :current
     set :best-dir :dir]
  set :dir :dir + 45
  set :current chemical-towards :dir 1
  if :current > :best-val
    [set :best-val :current
     set :best-dir :dir]
  set :dir :dir + 45
  set :current chemical-towards :dir 1
  if :current > :best-val
    [set :best-val :current
     set :best-dir :dir]
  output :best-dir
end

to search-for-chip
  if pc = yellow    ; if find a wood chip...
    [stamp black     ; remove wood chip from patch
     setshape termite-wood-shape     ; turn orange while carrying chip
     jump 20
     stop]           ; exit procedure
  grid-step
  search-for-chip
end

to find-new-pile
  if pc = yellow [stop]   ; if find a wood chip, stop
  grid-step
  find-new-pile
end

to find-empty-spot
  if pc = black      ; if find a patch without a wood chip
   [stamp yellow     ; put down wood chip in patch
    setshape termite-shape         ; set own color back to red
    get-away
    stop]
  seth random 360
  fd 1
  find-empty-spot
end

to get-away   ;leave the pile where you put your chip
  seth random 360
  jump 20
  if pc = black [stop]
  get-away
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://education.mit.edu/pipermail/starlogo-users/attachments/20061006/34321ccf/attachment.html


More information about the starlogo-users mailing list