turtles-own [message? other-turtle] to setup ca cct 200 [ set message? false fd random (4 * screen-edge-y) ; initialize turtle locations at random screen positions ] set message?-of random-one-of turtles true ; give the message to one of the turtles ask turtles [ color-turtles ; color the turtles red if they have the message, blue otherwise ] end to go every 0.1 [ ask turtles [move] ask turtles [ ;;when they're all done moving, start a new "ask turtles" communicate color-turtles ] ] end ; move randomly to move ;a turtle procedure fd random 4 ; turn a random amount between -40 and 40 degrees, ; keeping the average turn at 0 rt random 40 lt random 40 end ; the core procedure! to communicate ;;a turtle procedure set other-turtle random-one-of other-turtles-here ; get the ID of another turtle on your patch if(other-turtle != nobody) ; if there is one there [if message?-of other-turtle ; (only IDs of 0 and above are valid) [set message? true] ; if the other turtle has the message ] ; get the message end ; color turtles with message red, and those without message blue to color-turtles ; a turtle procedure ifelse message? [set color red] [set color blue] end ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML) ; The project gratefully acknowledges the support of the National Science ; Foundation (Applications of Advanced Technologies Program) -- grant numbers ; RED #9552950 and REC #9632612. ; ; Copyright 1999 by Uri Wilensky. All rights reserved. ; Converted to NetLogo from StarLogoT, 2001. ; ; Permission to use, copy, or modify this software and its documentation for ; educational and research purposes only and without fee is hereby granted, ; provided that this copyright notice and the original authors' names appear ; on all copies and supporting documentation. For any other uses of this ; software, in original or modified form, including but not limited to ; distribution in whole or in part, specific prior permission must be ; obtained from Uri Wilensky. These programs shall not be used, rewritten, or ; adapted as the basis of a commercial software or hardware product without ; first obtaining appropriate licenses from Uri Wilensky. We make no ; representations about the suitability of this software for any purpose. It ; is provided "as is" without express or implied warranty. @#$#@#$#@ CC-WINDOW 18 156 301 329 Command Center BUTTON 76 34 131 67 NIL setup NIL 1 T OBSERVER BUTTON 147 34 202 67 NIL go T 1 T OBSERVER BUTTON 76 34 131 67 NIL setup NIL 1 T OBSERVER BUTTON 147 34 202 67 NIL go T 1 T OBSERVER MONITOR 94 91 284 140 NIL count turtles with [color = red] 3 1 GRAPHICS-WINDOW 321 10 621 310 12 12 12.0 1 @#$#@#$#@ WHAT IS IT? ----------- This code example is a simple demo of turtle-turtle communications. One turtle starts out with a message (the red turtle) and she spreads the message to other turtles. The monitor keeps track of how many turtles have the message by reporting: count turtles with [color = red] Note that if you put a procedure inside an "ask turtles [ ]" bracket, then everything in that procedure will be executed by all of the turtles. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 @#$#@#$#@ NetLogo 1.0 Beta 8d @#$#@#$#@ @#$#@#$#@ @#$#@#$#@