;; the following variables are defined here for use throughout the rest of the code
globals
[
num-clusters
growback-time
max-energy
min-energy
max-speed
]
patches-own
[
harvest-time
]
turtles-own
[
time-since-last-found
energy
metabolism
]
;; Alteration 2: introduces a simple setup for the following procedures
to setup
ca
setup-globals
setup-patches
setup-turtles
reset-ticks
end
;; this procedure is the main procedure for the mushroom hunt
to go
if ticks >= 500 [ stop ];; this stops the simulation after 500 ticks have occured
ask turtles [search]
ask patches
[ if pcolor = yellow
[ if ticks - harvest-time >= growback-time ;; Alteration 6: this command turns patches (mushrooms) red to indicate the mushroom has grown back
[set pcolor red ]
]
]
if ticks mod 100 = 0 ;; Alteration 10: This command clears the trails of the hunters every 100 ticks
[clear-drawing]
tick
end
;; Alteration 3: this procedure assigns values the global variables (defined above) and the values they will take on
to setup-globals
set num-clusters 4
set growback-time 100
set max-energy 10
set min-energy .4
set max-speed 1
end
;; this procedure creates random patches on the board that are classified as mushrooms in this model
to setup-patches
ask n-of num-clusters patches
[
ask n-of 20 patches in-radius 5
[
set pcolor red
]
]
end
;;this procedure creates the turtles (hunters) and assigns attributes to the turtles
to setup-turtles
crt n-hunters ;; Alteration 5: this creates n number of hunters which can be adjusted by the slider in the model
[
set size 2
set color yellow
set time-since-last-found 999
set energy 1
set metabolism .001
pen-down
]
end
;;this procedure outlines the way that the turtles (hunters) will search for the red patches (mushrooms) in the program
to search
ifelse time-since-last-found <= 20 ;;this section tells the turtles if they have found the patch in less than 20 ticks the hunter will rotate randomly
[right (random 181) - 90]
[right (random 21) - 10]
fd max-speed ;; Alteration 7: this sets the speed of the hunter the maximum speed
ifelse pcolor = red ;; set the patch has not been harvested
[
set time-since-last-found 0
set pcolor yellow ;; set the patch has been harvested
set harvest-time ticks
if energy + 1 <= max-energy ;;Alteration 9: the hunters will gain one additional unit of energy up until the maximum energy values
[ set energy energy + 1 ]
]
[
set time-since-last-found time-since-last-found + 1
]
if energy >= min-energy ;; Alteration 8: Shows how the hunters energy is effected by its metabolism, but is constrain by the set minimum energy
[set energy energy - metabolism ]
set color scale-color yellow energy .4 1 ;; As the energy for the hunter decreases the color of the hunter changes from dark to light
end