Courses/CS 461/Winter 2006/Darren Iwaki/week 3

From CSWiki

Jump to: navigation, search

The painted desert model extends on the termite model, by having different colors of wood. The painted desert restricts a termite to only pick up a certain color of wood and multiple peices unliked the original termite model. I extended the model to allow termites to pick up any colored grain of wood

Image:painteddesert2.jpg Image:DarrenTermites.nlogo

globals [ clock ] turtles-own [ chip? ] patches-own [ turtle-color]

to setup

 ca
 ask patches
   [ if random-float 100 < density
       [ set pcolor ((random colors) * 10) + 5 ] ]
 cct number
   [ 
     set color white
     set chip? false
     setxy random-float screen-size-x
           random-float screen-size-y ]
 do-plots

end

to go

 set clock clock + 1
 find-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
 do-plots

end

to find-chip  ;; turtle procedure

 if (chip? = false)
 [
   ifelse (pcolor != black)  ;; if i dont have a chip and im on a new chip
   [ 
     set color pcolor                    ;; let the turtle carry 'pcolor' 
     set pcolor black                          ;; set the patch to black
     set chip? true                            ;; turtle now has a chip
                        ;; turtle is now of the color
     get-away
     stop ]
   [  
     wiggle
     find-chip ]
  ]

end

to find-new-pile  ;; turtle procedure

 if (pcolor = color)
   [ stop ]
 fd 10
 wiggle
 find-new-pile

end

to find-empty-spot

 if pcolor = black
 [
   set pcolor color ;; put down wood chip in patch
   set chip? false
   set color white
   fd 1
   stop
 ]
 rt random-float 360
 fd 1
 find-empty-spot

end

to get-away

 rt random-float 360
 back 10
 if (pcolor = black)
   [ stop ]                ;; exit this procedure if not on a pile
 get-away

end

to wiggle

 fd 1
 rt (random-float 50 - random-float 50)

end

to do-plots

 if (clock mod 100 = 0)
 [
   set-current-plot "Termites Carrying Chips"
   set-current-plot-pen "default"
   plot count turtles with [color != white]
 ]

end

Personal tools