project process4
No preview image
Model was written in NetLogo 5.0.4
•
Viewed 144 times
•
Downloaded 19 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Click to Run Model
breed [fishes fish] breed [predators predator] breed [boats boat] breed [detritus detritu] turtles-own [ age flockmates nearest-neighbor energy] patches-own [seagrass] to draw-island if mouse-down? ;; reports true or false to indicate whether mouse button is down [ ;; mouse-xcor and mouse-ycor report the position of the mouse -- ;; note that they report the precise position of the mouse, ;; so you might get a decimal number like 12.3, but "patch" ;; automatically rounds to the nearest patch ask patch mouse-xcor mouse-ycor [ set pcolor red ] ] end to setup clear-all ask patches [ set seagrass random-float 10.0 set pcolor scale-color blue seagrass 0 20 ] create-fishes number-of-fish [ setxy random-xcor random-ycor set color red set shape "fish" set age random 3 set energy random 20 ] create-detritus 50 [ setxy random-xcor random-ycor set color green set shape "molecule hydrogen" set energy random 10 ] create-predators number-of-predator [ setxy random-xcor random-ycor set color yellow set shape "shark" set age random 5 set energy random 60 set size 2 ;; increase their size so they are a little easier to see ] if human-involoved? [ create-boats 10 [ setxy random-xcor random-ycor set color white set shape "boat" set size 2 ]] reset-ticks end to go if not any? turtles [ stop ] ask fishes [ ifelse flock? [ flock ;; avoid fd 1 set age age + 1 set energy energy - 1 ] [ avoid let walls patches in-radius 1 with [pcolor = red] ifelse any? walls [ move] [forward 1 ] set age age + 1 set energy energy - 2 ] check-fish-dead eat-seagrass fish-reproduce ] ask detritus[ move ] ask predators [ chase eat-fish predator-reproduce check-if-dead set age age + 1 ] if human-involoved? [ ask boats [ move fishing ] ] regrow-seagrass tick my-update-plots end to flock ;; turtle procedure find-flockmates if any? flockmates [ find-nearest-neighbor ifelse distance nearest-neighbor < 0.75 [ separate ] [ align cohere ] ] end to find-flockmates ;; turtle procedure set flockmates other turtles in-radius 3 end to find-nearest-neighbor ;; turtle procedure set nearest-neighbor min-one-of flockmates [distance myself] end to separate ;; turtle procedure turn-away ([heading] of nearest-neighbor) 3.50 end to align ;; turtle procedure turn-towards average-flockmate-heading 5 end to cohere ;; turtle procedure turn-towards average-heading-towards-flockmates 5.75 end to turn-towards [new-heading max-turn] ;; turtle procedure turn-at-most (subtract-headings new-heading heading) max-turn end to turn-away [new-heading max-turn] ;; turtle procedure turn-at-most (subtract-headings heading new-heading) max-turn end to turn-at-most [turn max-turn] ;; turtle procedure ifelse abs turn > max-turn [ ifelse turn > 0 [ rt max-turn ] [ lt max-turn ] ] [ rt turn ] end to-report average-flockmate-heading ;; turtle procedure ;; We can't just average the heading variables here. ;; For example, the average of 1 and 359 should be 0, ;; not 180. So we have to use trigonometry. let x-component sum [dx] of flockmates let y-component sum [dy] of flockmates ifelse x-component = 0 and y-component = 0 [ report heading ] [ report atan x-component y-component ] end to-report average-heading-towards-flockmates ;; turtle procedure ;; "towards myself" gives us the heading from the other turtle ;; to me, but we want the heading from me to the other turtle, ;; so we add 180 let x-component mean [sin (towards myself + 180)] of flockmates let y-component mean [cos (towards myself + 180)] of flockmates ifelse x-component = 0 and y-component = 0 [ report heading ] [ report atan x-component y-component ] end to avoid ;; android procedure let candidates patches in-radius 1 with [ not any? predators ] ifelse any? candidates [ face one-of candidates ] [ rt (random 4) * 90 ] end to chase ifelse any? fishes in-radius 3 [ let candidates one-of fishes in-radius 3 let walls patches in-radius 1 with [pcolor = red] face candidates ifelse any? walls [ move] [fd ratio-speed-fishwolves set energy energy - 3]] [ if random 100 < predator-fight-percent [fight ]] end to fight ifelse any? predators in-radius 1 [let candidates one-of predators in-radius 1 set energy energy - 4 face candidates let walls patches in-radius 1 with [pcolor = red] ifelse any? walls [ move] [forward 1 ] ask candidates [ die ] ] [ move set energy energy - 2] end to eat-seagrass if ( seagrass >= 1) [ set seagrass seagrass - 1 set pcolor scale-color blue seagrass 0 20 ] end to eat-fish if any? fishes in-radius 2 [ ask fishes in-radius 2 [ die ] set energy energy + 10 ] end to fishing if random 100 < 70 [ ifelse any? predators-here [ let target one-of predators ask target [ die ]] [ ask fishes in-radius 3 [ die ] ] ] end to fish-reproduce if random 100 < fish-reproduce-percent [ if age > 3 [ hatch fish-hatch-number [ set age 0 set energy random 10] die ask detritus [hatch 1] ] ] end to predator-reproduce if random 100 < predator-reproduce-percent and energy > 20[ hatch 1 [ set age 0] set energy energy - 20 ] end to check-if-dead if age > 8 or energy < 1 [ die ask detritus [hatch 2] ] end to check-fish-dead if energy < 1 [ die ] end to regrow-seagrass ask patches with [pcolor = blue][ set seagrass seagrass + 0.1 if seagrass > 10 [ set seagrass 10 ] set pcolor scale-color blue seagrass 0 20 ] end to my-update-plots set-current-plot-pen "fish" plot count fishes set-current-plot-pen "shark" plot count predators * 10 ;; scaling factor so plot looks nice set-current-plot-pen "seagrass" plot sum [seagrass] of patches / 50 ;; scaling factor so plot looks nice end end to boat-move rt random 360 forward 2 end to move rt random 360 let walls patches in-radius 1 with [pcolor = red] ifelse any? walls [ move] [forward 1 ] end
There is only one version of this model, created over 11 years ago by Yun Zhou.
This model does not have any ancestors.
This model does not have any descendants.
Yun Zhou
I get a question (Question)
For the main part of my project, why it would stop all the movement?
Posted over 11 years ago