netlogo - How to make turtles move around patches with specific rules? -



netlogo - How to make turtles move around patches with specific rules? -

i new netlogo, , have questions. great if help me.

i create fruit flies moving around tree made greenish patches. fruit flies attracted tree. turn tree if fruit flies move away distance (such 5 grids) tree.

in beginning, not stop on greenish patches because have plenty energy. time passed, loss energy. find closest greenish patch, , remain on time 1 time energy reaches 0. gain energy after that, , can short hops bottom branch top 1 (3 hops). flies move bottom branch when on top part of tree. think need while loop, have no thought how that. please @ codes.

breed [flies fly] breed [suns sun] turtles-own [energy] flies-own [count-down] setup clear-all setup-suns setup-flies setup-patches reset-ticks end setup-suns ;; create sun set-default-shape suns "sun" create-suns 1 [ setxy max-pxcor - 3 max-pycor - 3 set color yellowish set size 7 ] end setup-flies set-default-shape flies "bee 2" create-flies number-fly [ set color white setxy random-xcor random-ycor set count-down 15] end setup-patches ;; create sky , grass inquire patches [ set pcolor bluish ] inquire patches [pycor < min-pycor + 2] [ set pcolor 66 ] ;; create trunk , branches inquire patches [ pxcor = -15 , pycor <= 0 ] [ set pcolor brownish ] inquire patches [ pxcor = -15 , pycor < 8 , pycor > 0] [ set pcolor lime ] inquire patches [ pxcor = pycor - 15 , pycor <= 5 , pycor > 0 ] [ set pcolor lime ] inquire patches [ pxcor = (- pycor) - 15 , pycor <= 5 , pycor > 0 ] [ set pcolor lime ] inquire patches [ pxcor = pycor - 8 , pycor <= 2 , pxcor > -15 ] [ set pcolor lime ] inquire patches [ pxcor = (- pycor) - 22 , pycor <= 2 , pxcor < -15 ] [ set pcolor lime ] inquire patches [ pxcor = pycor - 1 , pycor <= -1 , pxcor > -15 ] [ set pcolor lime ] inquire patches [ pxcor = (- pycor) - 29 , pycor <= -1 , pxcor < -15 ] [ set pcolor lime ] inquire patches [ pxcor = 15 , pycor <= 0 ] [ set pcolor brownish ] inquire patches [ pxcor = 15 , pycor < 8 , pycor > 0] [ set pcolor lime ] inquire patches [ pxcor = pycor + 15 , pycor <= 5 , pycor > 0 ] [ set pcolor lime ] inquire patches [ pxcor = (- pycor) + 15 , pycor <= 5 , pycor > 0 ] [ set pcolor lime ] inquire patches [ pxcor = pycor + 22 , pycor <= 2 , pxcor > 15 ] [ set pcolor lime ] inquire patches [ pxcor = (- pycor) + 8 , pycor <= 2 , pxcor < 15 ] [ set pcolor lime ] inquire patches [ pxcor = pycor + 29 , pycor <= -1 , pxcor > 15 ] [ set pcolor lime ] inquire patches [ pxcor = (- pycor) + 1 , pycor <= -1 , pxcor < 15 ] [ set pcolor lime ] inquire patches [ pxcor = -26 , pycor = -3 ] [ set pcolor reddish ] inquire patches [ pxcor = -10 , pycor = 5 ] [ set pcolor reddish ] inquire patches [ pxcor = 21 , pycor = -1 ] [ set pcolor reddish ] end go move-flies tick end move-flies inquire flies [ set energy 6 ifelse energy > 10 [ ;rt random 50 lt random 50 jump random-float 1 ; allow nearest-leaf min-one-of (patches [pcolor = lime] ) [distance myself] ; find closest leaf within 5 grids - long range search. if is-patch? nearest-leaf [ ; if leaf, , flies attracted leaf. face nearest-leaf ;set heading 45 ;fd distance nearest-leaf rt random 50 lt random 50 jump random-float 5 ; protential resources create flies move actively (fast movement). ;move-to nearest-leaf ; ] ] [ ifelse pcolor != lime [ rt random 50 lt random 50 jump random-float 1 ; initialization - flies fly around search resources. continue] [ remain ] ] ] end go on allow nearest-leaf min-one-of (patches in-radius 1 [pcolor = lime] ) [distance myself] ; find closest leaf within 2 grids - short hops. ifelse is-patch? nearest-leaf [ ; if leaf, , flies attracted leaf. face nearest-leaf fd random distance nearest-leaf ;ask patches in-radius 1 [set pcolor red] ;rt random 50 lt random 50 jump random-float 5 ; protential resources create flies move actively (fast movement). ;move-to nearest-leaf ; ] [ allow turn-back min-one-of (patches [pcolor = lime] ) [distance myself] ; ;set heading 180 face turn-back jump random-float 5 ] move-up ;flies tend move through branches short hops. need while loop. ; move downwards if reach top of tree allow canopy patch-at-heading-and-distance 0 1 allow canopy-left patch-left-and-ahead 45 1 allow canopy-right patch-right-and-ahead 45 1 if canopy != lime or canopy-left != lime or canopy-right != lime [ move-down ] end move-up inquire flies [ set heading one-of [0 30 -30] ] end move-down inquire flies [ set heading one-of [180 120 -120] ] end remain set count-down count-down - 1 ;;decrement timer set label count-down if count-down = 0 [ rt random 50 lt random 50 jump random-float 1 set label "" reset-count-down ;;it's procedure ] end reset-count-down set count-down 30 end

i sorry if confused codes. appreciate help. thanks.

kind regards,

ming

from description, think don't want while loop. in netlogo model's go procedure, you're specifying happens in single tick. utilize while if need express happens in single instant, not process unfolds on multiple ticks.

(agree frank much code post have chance of getting help. take quite while me read , study much code, allow lone seek help it. in reply i've tried extract , address single aspect.)

netlogo

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -