Hi, I'm currently having an error with one of my netlogo 3D projects... I am trying to simulate swarm intelligence based off of flocking, but I keep getting an error message that says: "Expected command"
here's my code:
turtles-own [
members
nearest-neighbor
acceleration
]
</div>
<div>
globals [ scale ]
</div>
<div>
</div>
<div>
to setup
</div>
<div>
ca
</div>
<div>
set scale 0.25 ;; scale let's us have a bigger
world without too many patches
</div>
<div>
crt swarm#
</div>
<div>
[ set color red - 2 + random 7
</div>
<div>
setxyz random-xcor
</div>
<div>
random-ycor
</div>
<div>
random-zcor
</div>
<div>
right random-float 360
</div>
<div>
tilt-up asin (1.0 - random-float
2.0)
</div>
<div>
roll-right random-float 360
</div>
<div>
set acceleration [ 0 0 0 ]
</div>
<div>
]
</div>
<div>
ask turtle 0 [ set color yellow ]
</div>
<div>
end
</div>
<div>
</div>
<div>
to go
</div>
<div>
ask turtles [ swarm ]
</div>
<div>
repeat 5
</div>
<div>
[
</div>
<div>
ask turtles
</div>
<div>
[
</div>
<div>
fd scale / 2
</div>
<div>
]
</div>
<div>
display
</div>
<div>
]
</div>
<div>
tick
</div>
<div>
end
</div>
<div>
</div>
<div>
to swarm
</div>
<div>
find-members
</div>
<div>
set acceleration (list 0 0 0)
</div>
<div>
add-urge avoid-obstacle-urge avoidance-constant
</div>
<div>
if any? members
</div>
<div>
[find-nearest-neighbor
</div>
<div>
ifelse distance nearest-neighbor < (
minimum-prevention * scale )
</div>
<div>
[align]
</div>
<div>
[cohere]
</div>
<div>
collision-prevention]
</div>
<div>
end
</div>
<div>
</div>
<div>
to find-nearest-neighbor
</div>
<div>
set nearest-neighbor min-one-of members [distance
myself]
</div>
<div>
end
</div>
<div>
</div>
<div>
to find-members
</div>
<div>
set members other turtles in-radius (vision *
scale)
</div>
<div>
end
</div>
<div>
</div>
<div>
to align
</div>
<div>
turn-towards average-member-heading
max-align-turn
</div>
<div>
pitch-towards average-member-pitch max-align-turn
</div>
<div>
end
</div>
<div>
</div>
<div>
to cohere
</div>
<div>
turn-towards
average-heading-towards-<wbr />members max-cohere-turn
</div>
<div>
pitch-towards average-pitch-towards-members
max-cohere-turn
</div>
<div>
end
</div>
<div>
</div>
<div>
to collision-prevention
</div>
<div>
turn-away ([heading] of nearest-neighbor)
max-collision-turn
</div>
<div>
pitch-away ([pitch] of nearest-neighbor)
max-collision-turn
</div>
<div>
end
</div>
<div>
</div>
<div>
;; Procedures to define COHERE and ALIGN
</div>
<div>
</div>
<div>
to turn-towards [new-heading max-turn]
</div>
<div>
turn-at-most (subtract-headings new-heading
heading) (max-turn * scale)
</div>
<div>
end
</div>
<div>
</div>
<div>
to pitch-towards [new-pitch max-turn]
</div>
<div>
pitch-at-most (subtract-headings pitch new-pitch)
(max-turn * scale)
</div>
<div>
end
</div>
<div>
</div>
<div>
;; Procedures to define ALIGN
</div>
<div>
</div>
<div>
to-report average-member-heading
</div>
<div>
report atan sum [sin heading] of members
</div>
<div>
sum [cos heading] of members
</div>
<div>
end
</div>
<div>
</div>
<div>
to-report average-member-pitch
</div>
<div>
report atan sum [sin pitch] of members
</div>
<div>
sum [cos pitch] of members
</div>
<div>
end
</div>
<div>
</div>
<div>
;; Procedures to define COHERE
</div>
<div>
</div>
<div>
to-report
average-heading-towards-<wbr /><wbr /><wbr />members
</div>
<div>
report atan mean [sin (towards myself + 180)] of
members
</div>
<div>
mean [cos (towards myself + 180)] of members
</div>
<div>
end
</div>
<div>
</div>
<div>
to-report average-pitch-towards-members
</div>
<div>
report mean [0 - (towards-pitch myself)] of
members
</div>
<div>
end
</div>
<div>
</div>
<div>
;; Procedures to define COLLISION-PREVENTION
</div>
<div>
</div>
<div>
to turn-away [new-heading max-turn]
</div>
<div>
turn-at-most (subtract-headings heading
new-heading) (max-turn * scale)
</div>
<div>
end
</div>
<div>
</div>
<div>
to pitch-away [new-pitch max-turn]
</div>
<div>
pitch-at-most (subtract-headings pitch new-pitch)
(max-turn * scale)
</div>
<div>
end
</div>
<div>
</div>
<div>
;; Procedures to define COHERE and COLLISION-PREVENTION
</div>
<div>
</div>
<div>
to turn-at-most [turn max-turn]
</div>
<div>
ifelse turn > 0
</div>
<div>
[ rt max-turn ]
</div>
<div>
[ lt max-turn ]
</div>
<div>
rt turn
</div>
<div>
end
</div>
<div>
</div>
<div>
to pitch-at-most [turn max-turn]
</div>
<div>
ifelse abs turn > max-turn
</div>
<div>
[ ifelse turn > 0
</div>
<div>
[ tilt-up max-turn ]
</div>
<div>
[ tilt-down max-turn ] ]
</div>
<div>
[ tilt-up turn ]
</div>
<div>
end
</div>
<div>
</div>
<div>
to build-cubes
</div>
<div>
ask n-of 20 patches
</div>
<div>
[ set pcolor blue + random 3
</div>
<div>
ask neighbors [ set pcolor blue + random 3
] ]
</div>
<div>
end
</div>
<div>
</div>
<div>
to-report avoid-obstacle-urge
</div>
<div>
let urge (list 0 0 0)
</div>
<div>
if avoidance-constant = 0 [ report urge ]
</div>
<div>
ask patches in-radius vision with [ pcolor !=
black ]
</div>
<div>
[ set urge
</div>
<div>
add
</div>
<div>
urge
</div>
<div>
subtract
</div>
<div>
(list [xcor] of
myself [ycor] of myself [zcor] of myself)
</div>
<div>
(list pxcor pycor
pzcor)
</div>
<div>
]
</div>
<div>
report urge
</div>
<div>
end
</div>
<div>
</div>
<div>
to-report add [ v1 v2 ]
</div>
<div>
report (map [ ?1 + ?2 ] v1 v2)
</div>
<div>
end
</div>
<div>
</div>
<div>
to-report normalize [ vector ]
</div>
<div>
let m magnitude vector
</div>
<div>
if m = 0 [ report vector ]
</div>
<div>
report map [ ? / m ] vector
</div>
<div>
end
</div>
<div>
</div>
<div>
to-report subtract [ v1 v2 ]
</div>
<div>
report (map [ ?1 - ?2 ] v1 v2)
</div>
<div>
end
</div>
<div>
</div>
<div>
to-report magnitude [ vector ]
</div>
<div>
report sqrt sum map [ ? * ? ] vector
</div>
<div>
end
</div>
<div>
</div>
<div>
to add-urge [urge factor]
</div>
<div>
set acceleration add acceleration
scale<span style=
"background-color: rgb(255, 255, 0);">factor</span><span style="background-color: rgb(255, 255, 255);"></span>normalize
urge
</div>
<div>
end
</div>
I'vehighlighted the word the error message highlights.
Thanks in advance! respond quickly please :P (if you need the
file itself with all the buttons and sliders, email me, i can
send it to you)