Netlogo - Ordered Movement -
i have following error in netlogo , i'm unsure why. trying make turtles move around in ordered fashion keep getting error when change d angle: "face expected input agent got nobody instead". appreciated.
globals [angles] setup clear-all create-turtles amount [ setxy random-xcor random-ycor ] ask turtles [ set angles (random 360) ] reset-ticks end monitor show count patches show ticks end go if (all? patches [pcolor = yellow]) [stop] ask turtles [ face min-one-of patches [ pcolor = black ] [ distance myself ] ;; line of code tells turtle head towards nearest patch containing colour of black. set angle d angle * 1 - angle rightt angle forwardd 1 ifelse show-travel-line? [pen-down][pen-up] set color red if pcolor = black [ set pcolor yellow ] ] tick end
you can unveil problem running test:
to test ca crt 1 let x -10e307 * 10 show x ask turtle 0 [rt x] inspect turtle 0 end
you see heading
nan
because gave turn of -infinity. if move turtle, xcor
, ycor
become nan
.
to avoid problem, need limit values taken angle
. example,
globals [turn angle] setup clear-all set turn random-float 1 create-turtles 10 [ setxy random-xcor random-ycor set color red pen-down ] reset-ticks end go if (all? patches [pcolor = yellow]) [stop] ask turtles [ part1 part2 if pcolor = black [ set pcolor yellow ] ] tick end part1 let _patches (patches [ pcolor = black ]) face min-one-of _patches [ distance myself ] end part2 set turn (4 * turn * (1 - turn)) set angle turn * 360 rt angle fd 1 end
Comments
Post a Comment