Java StarLogo
2.0
english
`turtle`
turtles-own [caught [yes no it]]

to turtle-setup 
  ifelse who = 0       ;make the "it" turtle different from the rest
    [setcaught it setc white] 
    [setcaught no setc green]
  seth random 360
  repeat 25 [wiggle]
end

to wiggle
  ifelse color = red       ;if you're a tagged turtle
     [ifelse together = 1    
         [seth towards xcor-of 0 ycor-of 0 fd .5]    ;if together is set to 1, follow the "it" turtle
         [lt random 60      ;else move about randomly
          rt random 6
          fd 1]]
     [lt random 60      ;if you're an untagged turtle, move about randomly
     rt random 60
     fd 1]
end

to capture-turtles
  ifelse color = white 
    [capture]    ;if you're the white "it" turtle, capture others
    [if caught = yes [setc red]]      ;if you've been tagged, turn red
end  
    
to capture    ;tag the other turtles on your patch
  grab one-of-turtles-here [setcaught-of partner yes] 
end

to go 
  wiggle
  capture-turtles
end

to slow       ;watch in slow motion, based on slider  
  wait time / 10
end


`observer`
to setup 
  ca
  crt numturts 
  ask-turtles [turtle-setup] 
end


`information`
For use with the Adventures in Modeling book, by Vanessa Colella, Eric Klopfer, and Mitchel Resnick published by Teachers College Press, 2001.  

For more information, see  
<http://education.mit.edu/starlogo/adventures>  

Challenge 9: Gotya  
This project shows a clever way of using "heading towards". The turtles in Gotya play a version of Tag in which the first turtle (who number 0) is "it". The "it" turtle (white) and the pool of "taggable" turtles (green) run randomly around the screen. If the "it" turtle lands on an untagged turtle, "it" tags the other turtle by turning it red. When the appropriate switch is thrown, the tagged turtles follow the "it" turtle.  

Click the "setup" button to create the number of turtles indicated  on the "numturts" slider. One of those turtles is designated as "it" and colored white, while the others are untagged, green turtles. Instead of relying on numeric values to indicate a turtle’s caught state in Gotya, the words yes, no, and it are used instead.  

When you click "go", the turtles move randomly about the screen.  
It is captivating to watch the turtles move apart and back together as you toggle the "together" slider. Observing this  process is a good way to get a feel for how turtles "head towards" other turtles. As you are reading through the code, be sure to look at the line

seth towards xcor-of 0 ycor-of 0  

which is the command that makes red turtles head towards the "it"  turtle (whose who number is zero).   

The interface for this project employs a true/false slider to regulate the tagged turtles’ following behavior. As turtles get tagged, they follow "it" if the "together" slider is toggled to 1, and they move randomly if the slider is toggled to 0. The "count-tagged" monitor keeps track of the total number of turtles who have been tagged, which is useful when the tagged turtles are bunched up behind "it". Finally, the "slow" button (which is scaled by the "time" slider) can be used to slow down the whole process if you’d like to watch the game more carefully.


`interface`
SLCanvas
top-left 5 237

SLButton
turtle-or-observer? turtle
top-left 103 9
width-height 88 33
name "button3"
line-to-run "slow"
forever? true
button-number 2
show-name? false
whichip 7

SLSlider
top-left 103 135
width-height 86 25
name "slider1"
variable "time"
min-value 0
max-value 99
current-value 16
slider-number 1
show-name? false

SLSlider
top-left 14 135
width-height 86 25
name "slider0"
variable "numturts"
min-value 0
max-value 300
current-value 250
slider-number 0
show-name? false

SLSlider
top-left 58 135
width-height 86 25
name "slider2"
variable "together"
min-value 0
max-value 1
current-value 1
slider-number 2
show-name? false

SLMonitor
top-left 154 79
width-height 72 36
name "count-tagged"
list-to-run "count-turtles-with [caught = yes]"
digits 0
delay 0.5
monitor-number 1
show-name? true
whichip 10
onewhichip 11

SLButton
turtle-or-observer? turtle
top-left 58 9
width-height 88 33
name "button05"
line-to-run "go"
forever? true
button-number 3
show-name? false
whichip 8

SLButton
turtle-or-observer? observer
top-left 14 10
width-height 88 33
name "button1"
line-to-run "setup"
forever? false
button-number 1
show-name? false
whichip 9


`turtle shapes`
[encoded data, 5330 characters]
qqqqqqqaoR8DO5wb3dkOFQAAFQ7Z

`template`
null

`settings`
patch-size 8
num-shapes 256
screen-half-width 25
screen-half-height 24
interface-window-xcor 312
interface-window-ycor 77
interface-window-size 699 415
output-window-xcor 0
output-window-ycor 0
output-window-width 300
output-window-height 219
info-window-xcor 0
info-window-ycor 0
info-window-width 500
info-window-height 419
control-center-xcor 0
control-center-ycor 85
control-center-width 285
control-center-height 415
turtle-command-center-height 150
observer-command-center-height 150

`string table`
H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA==

`symbol table`
H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA==

`double table`
H4sIAAAAAAAAAGNgYGB28G5gAAEHPTDFYP8AQgMAPC6/uxwAAAAAAAAc

`list table`
H4sIAAAAAAAAAE1OQQ7AMAgCuyzpDrv1sL/0Qfv/CybWpZoQQDEKoAMgEdXFjpYs
b9IWnq/rx+Vta0czkgOR5/iz4uk4uXIzofHBfYe2esb9A4q/Ms+S1yut9j7Rg9pS
xAAAAAAAAMQ=

`bytecodes`
H4sIAAAAAAAAAJ1U207CQBCd7ZVCoZVYQX2gUR6MkR8gMSG++wXGBKxNISGU0G0I
/6j/5O52utsWiNFJynZn9sycObMFOvOPA42j9DPO5jP44vYNAC6YWUzzLXv1Qdod
e0jxSsbsZ2gAaHxnAtiggtx09txbAB4PsoQ039F1PCmzPsmDJLhUWf0BZnTQR3Bl
zn75zlIHflGhdtbA1ayctdRZT0efzepw/xD3rUYXWr0Lz8EuCFj7VZKsY+acVfj3
TvB/kPyFUtiDivuqF+ROrkDxR+7cRwakwpURDNxK767soejpBvcO7q9x31Y4rsMR
vtPAuw18t44XemjgRYstG2w8KaabsejoF2FKkY26yCLWU6L12ydEM44vgKc1SOlg
I6kiYUnmVsMkbPojIonJW9ZHVTh/kcgALUmFMtKat8Mu2aMJnAlGtk73heayPC7y
LrAWfU65jSgLui85pelmGoYIdxqKWXXFPAuDJnQkVDBuAs2zwJ6qid9liamZOPv4
mm5WNN1NwyjNN7Qc+WS/osvwLVrkyZKGz+Ehzt4ZJEAOF0ppVP/siPmfyT3jPtbV
mLk+Nc72H3n0/ldf1Gr9AN9z4lceBQAAAAAFHg==

`observer world`
H4sIAAAAAAAAAGMQSMhPKk4tKkstUiguSSxJTXBggAMrBq6CnPyS8syU9NQSIJ+F
gS0nNS+9JAPI5mBgB8kVpOaBlXKDNSPJQgAjCAMA+OWZc2QAAAAAAABk

`patch world`
[encoded data, 6955 characters]
Zl+So2/2JTn6Zl+So2/2JXl7/7/2HBK23TgBAAABON0=

`turtle world`
[encoded data, 7150 characters]
P1z5tCZvOwAAAAA7bw==

