Sheep and Shepherds
HOW TO USE IT
The main display describes how to operate the model.
1) Select the number of Shepherds and Sheep you wish to have (or, leave the numbers the way they are)
2) Select a backdrop to use - Open field (no barriers) - Riverside (a fenced pasture with a river and a bridge) - Corral (a corral with an open gate) - Island (a series of nearly isolated land masses)
3) Click on the Go button to start the model
4) Adjust the following variables at anytime (try the defaults first):
Change the speed of the sheep (how fast they wander),
Slow down the model so you can more easily observe specific behaviors
Track an individual shepherd (he'll light up red)
THINGS TO NOTICE
The Shepherds are the brown agents running about.
When a Shepherd finds a wandering sheep and picks it up, he turns light brown.
The Shepherd will always try to place the sheep he is carrying next to another nearby sheep. THERE IS NO PLAN to herd the sheep in any particular place. The shepherds operate in a completely decentralized, agent-rules based system.
Sometimes the "herding" effect is seen quickly, other times you have to wait a little longer. And, the ease with which herding is accomplished is based on the settings of the variables. For instance, try setting the sheep speed to zero (0) and watch how quickly the sheep begin to be gathered into small herds and eventually one large herd. Speed the sheep up and see what happens.
Try playing with the variables: quantity of sheep vs. shepherds, the speed of the sheep, and the different backdrops.
How do the results vary when the variables are given different settings?
In the corral scenario, will a single herd form inside or outside the corral?
In the riverside scenario, will a single herd form on either side of the river?
Is there a particular island on which the herds form more frequently?
EXPLORATIONS
If you're the curious or playful type, you may wish to create your own custom scenario. You can do so by using the paint tools to paint your own design onto the patches. To save your creation, open the graphics window to its fullest. You will see some buttons down below that were previously hidden from view. Click on one of the blue "Save.." buttons. Then use File-Save As to save the model under a new name. Now you can run this model and select your custom backdrop as the playfield. TIP: when drawing surfaces that the sheep can walk around on, use only the colors that are used in the existing scenarios -- certain greens and browns. All other colors the sheep will treat like barriers.
CREDITS AND REFERENCES
As noted above, "Shepherds" is inspired by the "Termites" model. "Shepherds" was created by Greg Malone (gregmalone@gregmalone.com).
Turtle procedures
;
;
; ============
; SHEPHERDS
; ============
; by Greg Malone
; Santa Fe, New Mexico
; gregmalone@gregmalone.com
; See the INFO WINDOW for details
to setupherders
setc herdercolor
setxy (random 60) (random 60)
testlocation
if locationok = 0 [setupherders]
end
to setupsheep
setc sheepcolor
setxy (random 60) (random 60)
testlocation
if locationok = 0 [setupsheep]
end
to go
if (breed = herders)
[
search-for-sheep
find-new-sheep
find-empty-spot
stop
]
if breed = sheep
[
if sheepdelay = 0 [stop]
wiggle setdelaysheep (10 * (100 - sheepdelay)) stallsheep
stop
]
end
to search-for-sheep
tracker?
wiggle
if delay > 0 [wait (delay / 500)]
ifelse myrest = 0
[
if count-sheep-here > 0
[
setc carryingcolor
if who = 0
[
if trackit = 1 [setc trackcarrycolor]
]
if one-of-sheep-here >= 0 [kill one-of-sheep-here stop]
]
search-for-sheep
]
[ ;else
setmyrest myrest - 1
search-for-sheep
]
end
to find-new-sheep
if count-sheep = 0 [if (random 100) < 2 [stop]]
if who = 0
[
setc carryingcolor if trackit = 1 [setc trackcarrycolor]
]
wiggle
if delay > 0 [wait (delay / 500)]
if count-sheep-here > 0 [stop]
find-new-sheep
end
to find-empty-spot
bounce
if who = 0
[
setc carryingcolor if trackit = 1 [setc trackcarrycolor]
]
if count-sheep-here = 0
[
setc herdercolor
tracker?
hatch [setbreed sheep setc sheepcolor]
setmyrest restduration
wiggle
if delay > 0 [wait (delay / 500)]
stop
]
find-empty-spot
end
to wiggle
rt (random 50) lt (random 50)
testahead
if locationok = 0 [bk 1 bounce stop]
fd 1
end
to testahead
setlocationok 1 ; assume it's ok
ifelse currpattern = 6 ; islands
[
case pc-ahead
[
okcolor01 [stop]
; okcolor02 [stop]
okcolor03 [stop]
okcolor04 [stop]
okcolor05 [stop]
okcolor06 [stop]
]
]
[
case pc-ahead
[
okcolor01 [stop]
okcolor02 [stop]
okcolor03 [stop]
okcolor04 [stop]
okcolor05 [stop]
okcolor06 [stop]
]
]
setlocationok 0 ; not a good place to land
end
to testlocation
setlocationok 1 ; assume it's ok
ifelse currpattern = 6 ; islands
[
case pc
[
okcolor01 [stop]
okcolor03 [stop]
okcolor04 [stop]
okcolor05 [stop]
okcolor06 [stop]
]
setlocationok 0 ; not a good place to land
]
[
case pc
[
okcolor01 [stop]
okcolor02 [stop]
okcolor03 [stop]
okcolor04 [stop]
okcolor05 [stop]
okcolor06 [stop]
]
setlocationok 0 ; not a good place to land
]
end
to bounce
repeat 8
[
rt 45
if pc-ahead = okcolor01 [fd 1 stop]
if pc-ahead = okcolor02 [fd 1 stop]
if pc-ahead = okcolor03 [fd 1 stop]
if pc-ahead = okcolor04 [fd 1 stop]
if pc-ahead = okcolor05 [fd 1 stop]
if pc-ahead = okcolor06 [fd 1 stop]
]
bounce
end
to stallsheep
if delaysheep > 0 [setdelaysheep delaysheep - 1 stallsheep]
end
to tracker?
if who = 0
[
if trackit = 1 [setc red stop]
setc herdercolor
]
end
Observer procedures
to startup
ct cg
ask-patches [setpc pattern4] ; automatically show title screen
end
turtles-own [locationok delaysheep myrest]
patches-own [pattern1 pattern2 pattern3 pattern4 pattern5 pattern6]
breeds [herders sheep]
globals [
okcolor01 okcolor02 okcolor03 okcolor04 okcolor05 okcolor06
sheepcolor herdercolor carryingcolor trackcarrycolor
currpattern restduration trackit oceancolor wateranimcount
]
to setup
ct
ask-patches [setpc pattern5] ; show loading screen
wait 2
; show default background
case currpattern
[
1 [ask-patches [setpc pattern1]] ;open field
2 [ask-patches [setpc pattern2]] ;riverside
3 [ask-patches [setpc pattern3]] ;corral
4 [ask-patches [setpc pattern4]] ;title
5 [ask-patches [setpc pattern5]] ;loading
6 [ask-patches [setpc pattern6]] ; islands
]
setokcolor01 55
setokcolor02 33
setokcolor03 34
setokcolor04 35
setokcolor05 38 ;beach
setokcolor06 999
setoceancolor 104
setwateranimcount 0
setsheepcolor white
setherdercolor 32
setcarryingcolor 37
settrackcarrycolor 18
setrestduration 10
wait 0.5
create-herders numherders
ask-herders [setupherders]
wait 0.5
create-sheep numsheep
ask-sheep [setupsheep]
ask-turtles [setmyrest 0]
wait 0.5
ask-herders [repeat random 5 [setc (55 + random 5) wait 0.01] setc herdercolor]
ask-sheep [repeat 5 [setc (55 + random 5) wait 0.01] setc sheepcolor]
end
