Professional Documents
Culture Documents
Wolves and Sheeps
Wolves and Sheeps
breed [ sheep a-sheep ] ; sheep is its own plural, so we use "a-sheep" as the singular.
patches-own [ countdown ]
to setup
clear-all
; if we're not modeling grass, then the sheep don't need to eat to survive
; otherwise the grass's state of growth and growing logic need to be set up
ask patches [
[ set countdown random grass-regrowth-time ] ; initialize grass regrowth clocks randomly for
brown patches
]
create-sheep initial-number-sheep ; create the sheep, then initialize their variables
display-labels
reset-ticks
end
to go
if not any? wolves and count sheep > max-sheep [ user-message "The sheep have inherited the
earth" stop ]
ask sheep [
move
if model-version = "sheep-wolves-grass" [ ; in this version, sheep eat grass, grass grows and it
costs sheep energy to move
set energy energy - 1 ; deduct energy for sheep only if running sheep-wolf-grass model version
death ; sheep die from starvation only if running sheep-wolf-grass model version
ask wolves [
move
tick
display-labels
end
to move ; turtle procedure
rt random 50
lt random 50
fd 1
end
if pcolor = green [
end
if random-float 100 < sheep-reproduce [ ; throw "dice" to see if you will reproduce
end
if random-float 100 < wolf-reproduce [ ; throw "dice" to see if you will reproduce
]
end
end
end
if pcolor = brown [
end
to-report grass
ifelse model-version = "sheep-wolves-grass" [
[ report 0 ]
end
to display-labels
if show-energy? [
end