Predator Prey Grass 1
No preview image
Model was written in NetLogo 6.0.2
•
Viewed 218 times
•
Downloaded 20 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Info tab cannot be displayed because of an encoding error
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
globals [ max-prey ] ; don't let prey population grow too large ; Prey and predators are both breeds of turtle. breed [ prey a-prey ] ; prey is its own plural, so we use "a-prey" as the singular. breed [ predators predator ] turtles-own [ energy ] ; both predators and prey have energy patches-own [ countdown ] to setup clear-all ifelse netlogo-web? [set max-prey 10000] [set max-prey 30000] ; Check model-version switch ; if we're not modeling grass, then the prey 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 = "predator-prey-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-prey 100 ; create the prey, then initialize their variables [ set shape prey-type set color prey-color set size 1.5 ; easier to see set label-color blue - 2 set energy random (2 * 4) setxy random-xcor random-ycor ] create-predators 100 ; create the predators, then initialize their variables [ set shape predator-type set color predator-color set size 2 ; easier to see set energy random (2 * 20) setxy random-xcor random-ycor ] display-labels reset-ticks end to go ; stop the simulation of no predators or prey if not any? turtles [ stop ] ; stop the model if there are no predators and the number of prey gets very large if not any? predators and count prey > max-prey [ user-message "The prey have inherited the earth" stop ] ask prey [ move if model-version = "predator-prey-grass" [ ; in this version, prey eat grass, grass grows and it costs prey energy to move set energy energy - 1 ; deduct energy for prey only if running prey-predator-grass model version eat-grass ; prey eat grass only if running prey-predator-grass model version death ; prey die from starvation only if running prey-predator-grass model version ] reproduce-prey ; prey reproduce at random rate governed by slider ] ask predators [ move set energy energy - 1 ; predators lose energy as they move eat-prey ; predators eat a prey on their patch death ; predators die if our of energy reproduce-predators ; predators reproduce at random rate governed by slider ] if model-version = "predator-prey-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 fd 1 end to eat-grass ; prey procedure ; prey eat grass, turn the patch brown if pcolor = green [ set pcolor brown set energy energy + 4 ; prey gain energy by eating ] end to reproduce-prey ; prey procedure if random-float 100 < prey-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-predators ; predator procedure if random-float 100 < predator-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-prey ; predator procedure let food one-of prey-here ; grab a random prey if food != nobody [ ; did we get one? if so, ask food [ die ] ; kill it, and... set energy energy + 20 ; get energy from eating ] end to death ; turtle procedure (i.e. both predator nd prey 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 = "predator-prey-grass" [ report patches with [pcolor = green] ] [ report 0 ] end to display-labels ask turtles [ set label "" ] if show-energy? [ ask predators [ set label round energy ] if model-version = "predator-prey-grass" [ ask prey [ set label round energy ] ] ] end ; Copyright 1997 Uri Wilensky. ; See Info tab for full copyright and license.
There is only one version of this model, created over 6 years ago by Zachary Niese.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.