breed [triangles triangle]

breed [circles circle]

triangles-own [energy]

circles-own [energy]

to setup

clear-all

setup-patches

setup-triangles

setup-circles

do-plots

end

to setup-patches

ask patches [set pcolor lime – 4]

end

to setup-triangles

create-triangles 5

[set shape “default”

set color yellow

set energy 10

setxy random-xcor random-ycor]

end

to setup-circles

create-circles 5

[set shape “circle”

set color red

set energy 10

setxy random-xcor random-ycor]

end

to go

move-agents

eat-grass

reproduce

check-death

regrow-grass

do-plots

end

to move-agents

ask triangles [

left random 360

forward 1

set energy energy – 1

]

ask circles [

left random 360

forward 1

set energy energy – 1

]

end

to eat-grass

ask triangles [

if pcolor = lime – 4 [

set pcolor black

set energy (energy + 2)

]

ifelse show-energy?

[set label energy]

[set label “”]

]

ask circles [

if pcolor = lime – 4 [

set pcolor black

set energy (energy * energy-reinforcement-rate)

]

ifelse show-energy?

[set label precision(energy) 1]

[set label “”]

]

end

to reproduce

ask triangles [

if energy > birth-energy-triangle [

set energy energy – birth-energy-triangle

hatch 1 [set energy birth-energy-triangle]

]

]

ask circles [

if energy > birth-energy-circle [

set energy energy – birth-energy-circle

hatch 1 [set energy birth-energy-circle]

]

]

end

to check-death

ask triangles [

if energy <= 0 [die]

]

ask circles [

if energy <= 0 [die]

]

end

to regrow-grass

ask patches [

if random 100 <= grass-regrow-rate * 100 [set pcolor lime – 4]

]

end

to do-plots

set-current-plot “Agents-scale1”

set-current-plot-pen “triangles1”

plot count triangles

set-current-plot-pen “circles1”

plot count circles

set-current-plot “Agents-scale2”

set-current-plot-pen “triangles2”

plot count triangles with [ (xcor > 0) and (ycor > 0)]

set-current-plot-pen “circles2”

plot count circles with [ (xcor > 0) and (ycor > 0)]

set-current-plot “Agents-scale3”

set-current-plot-pen “triangles3”

plot count triangles with [ (xcor > 25) and (ycor > 25)]

set-current-plot-pen “circles3”

plot count circles with [ (xcor > 25) and (ycor > 25)]

set-current-plot “Grass”

set-current-plot-pen “grass”

plot count patches with [pcolor = lime – 4]

set-current-plot “Total-energy”

set-current-plot-pen “triangle-energy”

plot sum [energy] of triangles

set-current-plot-pen “circle-energy”

plot sum [energy] of circles

end