BehaviorSpace freezes on step #0 - netlogo

Sorry if this is obvious, I have searched everything I can think of and asked a colleague and we are both stuck.
I have some code (below - a slight twist on wolf sheep predation) that I want to run behaviorspace (input also below). However, it never runs to completion. It always seems to get stuck on step #0 of a run (the run # it gets stuck on varies). The runs that it sticks on work fine if they are run in isolation (so all the variables seem fine). It just seems to freeze (producing no error messages, nor does it crash).
Any ideas what is causing it?
Thanks,
Simon
Code:
globals [grass] ;; keep track of how much grass there is
;; Sheep and wolves are both breeds of turtle.
breed [sheep a-sheep] ;; sheep is its own plural, so we use "a-sheep" as the singular.
breed [wolves wolf]
turtles-own [energy] ;; both wolves and sheep have energy
patches-own [countdown]
to setup
clear-all
ask patches [ set pcolor green ]
;; check GRASS? switch.
;; if it is true, then grass grows and the sheep eat it
;; if it false, then the sheep don't need to eat
if grass? [
ask patches [
set countdown random grass-regrowth-time ;; initialize grass grow clocks randomly
set pcolor one-of [green brown]
]
]
if fences?[ ; this code adds in blue fences to create patches of various size (if fences are turned on). Turtles cannot pass over fences
ask patches with [pxcor mod connectivity2 = 0]
[ set pcolor blue ]
ask patches with [pycor mod connectivity = 0]
[ set pcolor blue ]
]
set-default-shape sheep "sheep"
create-sheep ((count patches - (count patches with [pcolor = blue])) / 25) ;; create the sheep, then initialize their variables. The starting density always remains constant despite a varying world size
[
set color white
set size 1.5 ;; easier to see
set label-color blue - 2
set energy random (2 * sheep-gain-from-food)
setxy random-xcor random-ycor
]
set-default-shape wolves "wolf"
create-wolves ((count patches - (count patches with [pcolor = blue])) / 50) ;; create the wolves, then initialize their variables. The starting density always remains constant despite a varying world size
[
set color black
set size 2 ;; easier to see
set energy random (2 * wolf-gain-from-food)
setxy random-xcor random-ycor
]
display-labels
set grass count patches with [pcolor = green]
reset-ticks
end
to go
if count wolves = 0 and count sheep = 0 and ((count patches with [pcolor = green]) = (count patches - (count patches with [pcolor = blue]))) [ stop ] ; stop model when the whole world has flipped to grass
ask sheep [
move
if grass? [
set energy energy - 1 ;; deduct energy for sheep only if grass? switch is on
eat-grass
]
death
reproduce-sheep
]
ask wolves [
move
set energy energy - 1 ;; wolves lose energy as they move
catch-sheep
death
reproduce-wolves
]
if grass? [ ask patches [ grow-grass ] ]
set grass count patches with [pcolor = green]
tick
display-labels
end
to move ;; turtle procedure
rt random 50
lt random 50
ifelse [pcolor] of patch-ahead 1 = blue
[ move] ;; If there is a blue patch ahead of you, choose another random direction
[ fd 1 ] ;; Otherwise, it is safe to move forward.
end
to eat-grass ;; sheep procedure
;; sheep eat grass, turn the patch brown
if pcolor = green [
set pcolor brown
set energy energy + sheep-gain-from-food ;; sheep gain energy by eating
]
end
to reproduce-sheep ;; sheep procedure
if random-float 100 < sheep-reproduce [ ;; throw "dice" to see if you will reproduce
set energy (energy / 2) ;; divide energy between parent and offspring
hatch 1 [ ifelse [pcolor] of patch-ahead 1 = blue ;; hatch an offspring
[ move] ;; If there is a blue patch ahead of the offspring, it chooses another random direction
[ fd 1 ] ;;If not, offspring move forward 1 step
]]
end
to reproduce-wolves ;; wolf procedure
if random-float 100 < wolf-reproduce [ ;; throw "dice" to see if you will reproduce
set energy (energy / 2) ;; divide energy between parent and offspring
hatch 1 [ ifelse [pcolor] of patch-ahead 1 = blue ;; hatch an offspring
[ move ] ;; If there is a blue patch ahead of the offspring, it chooses another random direction
[ fd 1 ] ;;If not, offspring move forward 1 step
] ]
end
to catch-sheep ;; wolf procedure
let prey one-of sheep-here ;; grab a random sheep
if prey != nobody ;; did we get one? if so,
[ ask prey [ die ] ;; kill it
set energy energy + wolf-gain-from-food ] ;; get energy from eating
end
to death ;; turtle procedure
;; when energy dips below zero, die
if energy < 0 [ die ]
end
to grow-grass ;; patch procedure
;; countdown on brown patches: if reach 0, grow some grass
if pcolor = brown [
ifelse countdown <= 0
[ set pcolor green
set countdown grass-regrowth-time ]
[ set countdown countdown - 1 ]
]
end
to display-labels
ask turtles [ set label "" ]
if show-energy? [
ask wolves [ set label round energy ]
if grass? [ ask sheep [ set label round energy ] ]
]
end
; Copyright 1997 Uri Wilensky.
; See Info tab for full copyright and license.
behaviorspace input:
variables:
["world-width" 51]
["fences?" true]
["wolf-gain-from-food" 20]
["sheep-reproduce" 7]
["show-energy?" false]
["grass?" true]
["connectivity" 10 25 50]
["wolf-reproduce" 5]
["grass-regrowth-time" [1 1 100]]
["sheep-gain-from-food" 4]
repetitions: 1
reporters:
count wolves
count sheep
count patches with [pcolor = green]
measure runs at each step
setup: setup
Go: go
Stop (I have tried it with and without this): count wolves = 0 and count sheep = 0 and ((count patches with [pcolor = green]) = (count patches - (count patches with [pcolor = blue])))
Time limit: 5000

It's difficult for me to imagine this could be caused by anything other than running low on memory. Running very low on memory can cause the JVM to slow to a crawl.
What do the memory usage stats in the System tab of "About NetLogo" say? You can verify there that you're actually getting the heap size you asked for.

Related

How can I establish a decreasing relationship between variables?

I am a teacher of Primary Education and Early Childhood Education and I am trying to generate a simulator through NetLogo on how fertilization and pesticides are decimating the butterfly population. However, despite having read the manual, I am not managing to program the code to make it work.
My problem is that although I set the turtles I can't establish the following relationship between the variables/buttons:
If butterflies randomly touch a plant (which is fertilized with pesticide) its pollinating capacity is reduced by a certain percentage (depends on the amount of pesticide)
My problem is that I can't get the pollination capacity of the butterfly to be set to 100% initially and that the greater the amount of pesticide, the lower its pollination capacity is when touching a flower. Currently, although the amount of pesticide is the highest, there are peaks where its pollination capacity increases instead of being reduced.
breed [butterflies butterfly]
breed [flowers flower]
globals
[
butterfliesless-neighborhoods ;; how many patches have no butterflies in any neighboring patches?
pollinating-capacity ;; measures how well-bivouaced the butterflies are
]
patches-own
[
butterflies-nearby ;; how many butterflies in neighboring patches?
]
flowers-own
[
carried-butterflies ;; the butterflies I'm carrying (or nobody if I'm not carrying in)
found-bivouac? ;; becomes true when I find a bivouac to drop it in
]
to setup
clear-all
set-default-shape butterflies "butterflies"
set-default-shape flowers "flower"
ask patches
[ set pcolor green + (random-float 0.8) - 0.4] ;; varying the green just makes it look nicer
create-butterflies num-butterflies
[ set color white
set size 1.5 ;; easier to see
setxy random-xcor random-ycor ]
create-flowers num-flowers
[ set color brown
set size 1.5 ;; easier to see
set carried-butterflies nobody
set found-bivouac? false
setxy random-xcor random-ycor ]
reset-ticks
end
to update-butterflies-counts
ask patches
[ set butterflies-nearby (sum [count butterflies-here] of neighbors) ]
set butterfliesless-neighborhoods (count patches with [butterflies-nearby = 0])
end
to calculate-pollinating-capacity
set pollinating-capacity (butterfliesless-neighborhoods / (count patches with [not any? butterflies-here])) * 100
end
to go
ask flowers
[ ifelse carried-butterflies = nobody
[ search-for-butterflies ] ;; find a butterflies and pick it up
[ ifelse found-bivouac?
[ find-empty-spot ] ;; find an empty spot to drop the butterflies
[ find-new-bivouac ] ] ;; find a bivouac to drop the butterflies in
wiggle
fd 1
if carried-butterflies != nobody
;; bring my butterflies to where I just moved to
[ ask carried-butterflies [ move-to myself ] ] ]
ask butterflies with [not hidden?]
[ wiggle
fd pesticide-amount ]
tick
end
to wiggle ;; turtle procedure
rt random 50 - random 50
end
to search-for-butterflies ;; flowers procedure
set carried-butterflies one-of butterflies-here with [not hidden?]
if (carried-butterflies != nobody)
[ ask carried-butterflies
[ hide-turtle ] ;; make the butterflies invisible to other flowers
set color blue ;; turn flower blue while carrying butterflies
fd 1 ]
end
to find-new-bivouac ;; flowers procedure
if any? butterflies-here with [not hidden?]
[ set found-bivouac? true ]
end
to find-empty-spot ;; flowers procedure
if all? butterflies-here [hidden?]
[ ask carried-butterflies
[ show-turtle ] ;; make the butterflies visible again
set color brown ;; set my own color back to brown
set carried-butterflies nobody
set found-bivouac? false
rt random 360
fd 20 ]
end
Defined Buttons
Your screenshot is a nice start with sliders, buttons and plots. In the code tab consider making two breeds of turtles: butterflies and plants.
breed [butterflies butterfly]
butterflies-own [pollinatingCapacity]
breed [plants plant]
plants-own [pesticideAmount]
And then think about how you might decrease pollinatingCapacity of a butterfly when it is on the same patch as a plant. A butterfly can see if any plants are on the same patch using plants-here

Agents on same patch

In this model the boat moves diagonally across the world (which does not wrap, 00 bottom left, max-pycor & max-pxcor 49) and 20 fish move in the opposite diagonal. The model is set up so the boat counts the fish it encounters, and as a double-check each fish counts if it met the boat. It does not matter if the boat does not meet all the fish.
My problem is that on some (10-15%) of runs, although both agents appear to be on the same patch, the relevant record does not increase, i.e. times that f-count does not increase and other times the b-count might not increase. I have spent time watching the agents closely, and they appear to be on the same patch, but the record does not increase. As a beginner with NetLogo, is there something in the coding of "boats-here", "fish-here" or "neighbors" that I am overlooking that is related to the xcor/ycor of the agents? Or is the sequence of commands the source of the problem? Thanks for considering my question.
breed [boats boat]
breed [fish a-fish]
boats-own [b-count fuel]
fish-own [f-count]
to setup
clear-all
reset-ticks
create-boats 1
[apply-boat-properties]
create-fish 20
[apply-fish-properties]
end
to apply-boat-properties
ask boats
[
set color red
set size 0.3
set shape "star"
setxy min-pxcor max-pycor
set fuel 710
]
end
to apply-fish-properties
ask fish
[
set color blue
set size 0.3
set shape "star"
setxy random-xcor max-pycor
]
end
to go
if (any? boats with [fuel <= 0 ])
[ stop ]
ask boats
[
follow-route1
survey
]
ask fish
[
check-if-boat
move
]
tick
end
to follow-route1
ask boats
[
facexy 49 0
fd 0.05
pen-down
set fuel fuel - 1
]
end
to survey
ifelse any? fish-here ;; if boat on the same patch as a fish
[ask fish-here [ ;; ask the fish on this patch
if shape = "star"[ ;; with a "star" shape
set shape "circle" ;; change shape to "circle" shape
ask boats-here ;; ask boat on same patch to increase b-
count by 1
[set b-count b-count + 1]]
]
]
;; otherwise
[ask fish-on neighbors [ ;; ask fish on neighbouring 8 patches
if shape = "circle"[ ;; if the fish has a "circle" shape
set shape "star" ] ;; change that shape to "star" shape
]]
end
to move
ask fish
[
set heading 225
fd 0.0025
]
end
to check-if-boat
ifelse any? boats-here ;; if boats on same patch as the
fish
[
ask fish-here with [color = blue] ;; ask the blue fish to change
colour to yellow
[ set color yellow
set f-count f-count + 1] ;; and increase f-count by 1
]
[ask fish-here with [color = yellow] ;; otherwise ask fish with yellow
colour to change color to blue
[set color blue
] ]
end
to-report boat-b-count ;;Report count of boats with b-
count more than 1
report sum [b-count] of boats with [b-count > 0]
end
to-report fish-f-count ;;Report count of fish with f-
count more than 1
report sum [f-count] of fish with [f-count > 0]
end
to-report %fish-counted ;;Report count of fish with f-
count more than 1
report (sum [f-count] of fish / count fish) * 100
end

how to use view2.5d:turtle-view in netlogo

When I try to use view2.5d:turtle-view in view2.5d extension I always get NullPointerExpectation.
extensions [view2.5d]
turtles-own[
energy
]
to setup
ca
create-turtles 50[
set color red
setxy random-xcor random-ycor
set energy random 1000
]
create-turtles 50[
set energy random 1000
setxy random-xcor random-ycor
]
view2.5d:turtle-view "test" turtles [the-turtle -> [energy] of the-turtle]
reset-ticks
end
The error message:
error (NullPointerException)
while observer running VIEW2.5D:TURTLE-VIEW
called by procedure SETUP
called by Button 'setup'
NetLogo is unable to supply you with more details about this error. Please report the problem
at https://github.com/NetLogo/NetLogo/issues, or to bugs#ccl.northwestern.edu, and paste the
contents of this window into your report.
In case anyone else runs into this, it was a known issue with the version of view2.5 released with NetLogo 6.0.4 (and earlier). A fix release of the extension is available at that link.
For a quick example of usage, open the Wolf Sheep Predation model from the models library and make the following changes in the Code tab:
Add extensions [ view2.5d ] on the first line.
In the setup procedure, add view2.5d:turtle-view "wsp" turtles [ t -> [energy] of t ] on the line after reset-ticks, right before the end. The [ t -> [energy] of t ] anonymous reporter is what determines the "height" of the turtles in the view2.5d.
At the end of the go procedure, add view2.5d:update-turtle-view "wsp" turtles right after display-labels before the end.
The above shows how you add the view2.5d to an existing model that uses turtles. Here is the full code for easier copy/pasting.
extensions [ view2.5d ]
globals [ max-sheep ] ; don't let sheep population grow too large
; Sheep and wolves are both breeds of turtle.
breed [ sheep a-sheep ] ; sheep is its own plural, so we use "a-sheep" as the singular.
breed [ wolves wolf ]
turtles-own [ energy ] ; both wolves and sheep have energy
patches-own [ countdown ]
to setup
clear-all
ifelse netlogo-web? [set max-sheep 10000] [set max-sheep 30000]
; Check model-version switch
; 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
ifelse model-version = "sheep-wolves-grass" [
ask patches [
set pcolor one-of [ green brown ]
ifelse pcolor = green
[ set countdown grass-regrowth-time ]
[ set countdown random grass-regrowth-time ] ; initialize grass regrowth clocks randomly for brown patches
]
]
[
ask patches [ set pcolor green ]
]
create-sheep initial-number-sheep ; create the sheep, then initialize their variables
[
set shape "sheep"
set color white
set size 1.5 ; easier to see
set label-color blue - 2
set energy random (2 * sheep-gain-from-food)
setxy random-xcor random-ycor
]
create-wolves initial-number-wolves ; create the wolves, then initialize their variables
[
set shape "wolf"
set color black
set size 2 ; easier to see
set energy random (2 * wolf-gain-from-food)
setxy random-xcor random-ycor
]
display-labels
reset-ticks
view2.5d:turtle-view "wsp" turtles [ t -> [energy] of t ]
end
to go
; stop the simulation of no wolves or sheep
if not any? turtles [ stop ]
; stop the model if there are no wolves and the number of sheep gets very large
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
eat-grass ; sheep eat grass only if running sheep-wolf-grass model version
death ; sheep die from starvation only if running sheep-wolf-grass model version
]
reproduce-sheep ; sheep reproduce at random rate governed by slider
]
ask wolves [
move
set energy energy - 1 ; wolves lose energy as they move
eat-sheep ; wolves eat a sheep on their patch
death ; wolves die if our of energy
reproduce-wolves ; wolves reproduce at random rate governed by slider
]
if model-version = "sheep-wolves-grass" [ ask patches [ grow-grass ] ]
; set grass count patches with [pcolor = green]
tick
display-labels
view2.5d:update-turtle-view "wsp" turtles
end
to move ; turtle procedure
rt random 50
lt random 50
fd 1
end
to eat-grass ; sheep procedure
; sheep eat grass, turn the patch brown
if pcolor = green [
set pcolor brown
set energy energy + sheep-gain-from-food ; sheep gain energy by eating
]
end
to reproduce-sheep ; sheep procedure
if random-float 100 < sheep-reproduce [ ; throw "dice" to see if you will reproduce
set energy (energy / 2) ; divide energy between parent and offspring
hatch 1 [ rt random-float 360 fd 1 ] ; hatch an offspring and move it forward 1 step
]
end
to reproduce-wolves ; wolf procedure
if random-float 100 < wolf-reproduce [ ; throw "dice" to see if you will reproduce
set energy (energy / 2) ; divide energy between parent and offspring
hatch 1 [ rt random-float 360 fd 1 ] ; hatch an offspring and move it forward 1 step
]
end
to eat-sheep ; wolf procedure
let prey one-of sheep-here ; grab a random sheep
if prey != nobody [ ; did we get one? if so,
ask prey [ die ] ; kill it, and...
set energy energy + wolf-gain-from-food ; get energy from eating
]
end
to death ; turtle procedure (i.e. both wolf nd sheep procedure)
; when energy dips below zero, die
if energy < 0 [ die ]
end
to grow-grass ; patch procedure
; countdown on brown patches: if reach 0, grow some grass
if pcolor = brown [
ifelse countdown <= 0
[ set pcolor green
set countdown grass-regrowth-time ]
[ set countdown countdown - 1 ]
]
end
to-report grass
ifelse model-version = "sheep-wolves-grass" [
report patches with [pcolor = green]
]
[ report 0 ]
end
to display-labels
ask turtles [ set label "" ]
if show-energy? [
ask wolves [ set label round energy ]
if model-version = "sheep-wolves-grass" [ ask sheep [ set label round energy ] ]
]
end
; Copyright 1997 Uri Wilensky.
; See Info tab for full copyright and license.

Making a turtle stop and then go after a special event - Robotic lawn mower simulation project

I am trying to simulate a robotic lawn mower on Netlogo. My first goal was it finds its way home to recharge itself when the battery is low.
This is now done (thanks Luke !) but I can't figure how to make the lawnmower stop when it reaches the house (it keeps moving 2 patches around). Therefore my energy slider goes infinitely below zero.
I first thought of adding an event "recharge" and placing it after "check death" in to go with a if instance. But :
How do I say if car goes on specific patch : stop and get energy ? Should I use a special patch color for the house and then code if car goes on blue patch..... ?
Could adding the recharge event at the end of the to go elements would possibly create a conflict because recharge only goes when on low battery ? Would putting it in check death be a solution ?
Then I would like it to go back to work after instant recharge.
Any ideas ?
Here's the code :
breed [cars car]
cars-own [target]
breed [houses house]
to setup
clear-all
setup-patches
setup-cars ;;represent lawn mower
setup-house
reset-ticks
end
to setup-patches
ask patches [set pcolor green] ;; Setup grass patches
ask patches with [
pxcor = max-pxcor or
pxcor = min-pxcor or
pycor = max-pycor or
pycor = min-pycor ] [
set pcolor red ;; Setup the borders of the garden
]
end
to setup-cars
create-cars 1 [
setxy 8 8
set target one-of houses
]
end
to setup-house
set-default-shape houses "house"
ask patch 7 8 [sprout-houses 1]
end
to place-walls
if mouse-down? [
ask patch mouse-xcor mouse-ycor [ set pcolor red ]
display
]
end
to go
move-cars
cut-grass
check-death ;; Check % battery.
tick
end
to move-cars
ask cars
[
ifelse [pcolor] of patch-ahead 1 = red
[ lt random-float 360 ] ;; see red patch ahead turn left.
[ fd 1 ] ;; otherwise it is ok to go.
set energy energy - 1
]
tick
end
to cut-grass
ask cars [
if pcolor = green [
set pcolor gray
]
]
end
to check-death ;; when low energy lawn mower will go back to house
ask cars [
ifelse energy >= 150
[ set label "Energy ok" ]
[ set label "Low Energy, returning to base"
set target min-one-of houses [distance myself]
face target
ifelse distance target < 1
[ move-to target ]
[ fd 1 ]
]
]
end
You can use a logical flag (eg charging?) in conjunction with a counter (eg charge-time) to do this. Try modifying your cars-own definitions like this:
cars-own [target charging? charge-time]
and setup-cars like this:
to setup-cars
create-cars 1 [
setxy 8 8
set target one-of houses
set charging? false
]
end
Then you can have the mower do different things based on whether charging? is true or false. Try modifying your move-cars and check-death to accommodate these changes (side note- you've got a tick in both go and move-cars):
to move-cars
ask cars [
ifelse charging? [
set charge-time charge-time + 1
if charge-time > 14 [
set energy 200
set charging? false
set charge-time 0
]
] [
ifelse [pcolor] of patch-ahead 1 = red
[ lt random-float 360 ] ;; see red patch ahead turn left.
[ fd 1 ] ;; otherwise it is ok to go.
set energy energy - 1
]
]
end
to check-death ;; when low energy lawn mower will go back to house
ask cars [
ifelse energy >= 150
[ set label "Energy ok" ]
[ set label "Low Energy, returning to base"
set target min-one-of houses [distance myself]
face target
ifelse distance target < 1
[ move-to target
set charging? true
]
[ fd 1 ]
]
]
end
I suggest you change energy a turtle variable like car-energy so that the turtles values are independent of your slider. That would mean you could have multiple mowers and they could reset their energy level to the slider setting once they are charged! You would just include a line like
set car-energy energy
in your setup-cars (and then modify so that energy in your car procedures is instead car-energy).

Netlogo Flocking model turtles are bored

I'm new to programming in Netlogo and I need to adapt the code so that turtles get bored after 50 ticks of flying in formation and make a right turn of 90 degrees. I modified the code while looking at some other examples but I get a very strong hunch it doesn't do what it's supposed to do. Can you please help me or give me a hint? Here's the code in question:
turtles-own [
flockmates ;; agentset of nearby turtles
nearest-neighbor ;; closest one of our flockmates
flock-tick
]
to setup
clear-all
create-turtles population
[ set color yellow - 2 + random 7 ;; random shades look nice
set size 1.5 ;; easier to see
setxy random-xcor random-ycor
set flockmates no-turtles
set flock-tick 0 ]
reset-ticks
end
to go
ask turtles [ flock ]
;; the following line is used to make the turtles
;; animate more smoothly.
repeat 5 [ ask turtles [ fd 1 ] display ]
;; for greater efficiency, at the expense of smooth
;; animation, substitute the following line instead:
;; ask turtles [ fd 1 ]
tick
end
to flock ;; turtle procedure
find-flockmates
if any? flockmates
[ find-nearest-neighbor
ifelse distance nearest-neighbor < minimum-separation
[ separate ]
[ align
cohere ] ]
end
to find-flockmates ;; turtle procedure
set flockmates other turtles in-cone vision 90
end
to find-nearest-neighbor ;; turtle procedure
set nearest-neighbor min-one-of flockmates [distance myself]
end
to flock-timer
if any? flockmates [
set flock-tick 50
while [ flock-tick > 0 ] [
set flock-tick ( flock-tick - 1 ) ]
if flock-tick = 0
[ set heading ( heading - 90 ) ] ]
end
The rest of the code is still the same as the the model in the library.
I must admit I'm not really sure of what I'm doin and the northwestern website is also not very helpfull to me (probably my own fault).
Thanks!
If we add comments to your code, we can see the logic problem.
to flock-timer
if any? flockmates [
;the next line sets `flock-tick` to 50
set flock-tick 50
;the next line sets `flock-tick` to 0
while [flock-tick > 0] [set flock-tick (flock-tick - 1)]
;so the next condition will always be satisfied
if (flock-tick = 0) [
;and so the heading will always be changed
set heading (heading - 90)
]
]
end
You might break things up to make it easier to follow the logic.
to flock-timer ;turtle proc
update-flock-tick
if (flock-tick = 0) [get-bored]
end
to update-flock-ticks ;turtle proc
;you can add additional logic here if you wish
if (flock-tick > 0) [
set flock-tick (flock-tick - 1)
]
end
to get-bored ;turtle proc
set heading (heading + one-of [-90, 90])
end
This is not a complete solution, but it should get you started.