Individual project
Model was written in NetLogo 6.0.4
•
Viewed 121 times
•
Downloaded 12 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
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
turtles-own [energy speed movement detection] ;; Properties/attributes the turtles have globals [days turns amount-grass half-patches turtle-count] ;; sliders: food-energy speed-cost birth-requirement base-movement-cost starting-energy default turns-in-day to setup clear-all setup-patches setup-turtles reset-ticks end to go check-death-energy count-turtles move-turtles eat-grass set-label tick reset-at-50 reset-at-max end to setup-defaults set food-energy 30 set speed-cost 1.04 set birth-requirement 200 set base-movement-cost 5 set starting-energy 25 set turns-in-day 10 set starting-speed 2 set detection-cost 0.9 set initial-population 30 set two-populations false set migration false end to setup-patches ask patches [set pcolor brown] ;;makes all patches brown set amount-grass (precision (count patches / 2) -1) ;set default amount of grass to half of the total patches rounded down set half-patches (precision (count patches / 2) -1) ask n-of amount-grass patches [ set pcolor green] ;; number of random patches set to green (grass) if two-populations [ ask patches [if (pxcor = 0) and (pycor >= 0) [set pcolor black] ] ask patches [if (pycor = 0) and (pxcor >= 0) [set pcolor black] ]] end to setup-turtles create-turtles initial-population ;; Create a number of turtles at start ask turtles [ setxy random-pxcor random-pycor ;; set turtles in the center of random patches set heading one-of [0 45 90 135 180 225 270 315] ;; heading in 1 of the 8 directions set energy starting-energy set speed starting-speed ;; sets speed as starting-speed set detection 1 set movement speed ;; Sets movement to the speed of the turtle if Labels = "speed" [set label speed] if Labels = "movement" [set label movement] set color one-of [15 45 85 115 125] ] set turns 0 set days 0 end to check-death-energy ask turtles[if energy >= birth-requirement [set movement 0]] ask turtles[if energy < 0 [set energy 0]] ask turtles [if energy = 0 [die]] ask turtles [if pcolor = black [die]] end to count-turtles set turtle-count (count turtles) end to set-label ask turtles [ if Labels = "speed" [set label speed] if Labels = "movement" [set label movement]] end to move-turtles ask turtles [ if (energy > 0) and (energy < birth-requirement) [ ifelse (any? patches with [pcolor = green] in-radius detection) and (detection > 0) [face min-one-of patches with [pcolor = green] [distance myself]] [set heading (heading + one-of [-45 -90 45 90 0])] if movement > 0 [ if (is-patch? patch-ahead 1) and (two-populations) [ ifelse [pcolor] of patch-ahead 1 = black [set heading (heading + one-of [-90 90]) if is-patch? patch-ahead 1 [if [pcolor] of patch-ahead 1 != black [forward 1]]] [if is-patch? patch-ahead 1 [if [pcolor] of patch-ahead 1 != black [forward 1]]] ] if not two-populations [forward 1] setxy pxcor pycor ;;keep turtles in center of a patch set movement movement - 1 set energy energy - ((base-movement-cost + (speed-cost ^ speed)) + (detection-cost * detection ^ 2)) ]]] if all? turtles [movement = 0] [ask turtles [set movement speed] set turns turns + 1] end to reset-at-max if all? turtles [energy >= birth-requirement][ ask patches [set pcolor brown] set amount-grass (precision (count patches with [pcolor = brown] / 2) -1) ask n-of amount-grass patches [ set pcolor green] if two-populations [ ask patches [if (pxcor = 0) and (pycor >= 0) [set pcolor black] ] ask patches [if (pycor = 0) and (pxcor >= 0) [set pcolor black] ]] if (migration) and (two-populations) [ ask patches [if (pycor = 0 ) and ((pxcor >= 10) and (pxcor <= 13)) [set pcolor one-of [green brown]]]] ask turtles [if energy > birth-requirement [ set energy starting-energy hatch one-of [0 0 0 1] [ set energy starting-energy ifelse speed >= 2 [set speed speed + one-of [-1 1 0 ] ] [set speed speed + one-of [1 0]] ifelse detection >= 1 [set detection detection + one-of [-1 0 0 0 1]] [set detection detection + one-of [0 0 0 1]] ] ] ] ask turtles [ set energy starting-energy set movement speed ] set days days + 1 reset-ticks set turns 0 ] end to reset-at-50 if turns > turns-in-day [ ask patches [set pcolor brown] set amount-grass (precision (count patches with [pcolor = brown] / 2) -1) ask n-of amount-grass patches [ set pcolor green] if two-populations [ ask patches [if (pxcor = 0) and (pycor >= 0) [set pcolor black] ] ask patches [if (pycor = 0) and (pxcor >= 0) [set pcolor black] ]] if (migration) and (two-populations) [ ask patches [if (pycor = 0 ) and ((pxcor >= 10) and (pxcor <= 13)) [set pcolor one-of [green brown]]]] ask turtles [if energy >= birth-requirement [ set energy starting-energy hatch one-of [0 0 0 1] [ set energy starting-energy ifelse speed >= 2 [set speed speed + one-of [-1 1 0 ] ] [set speed speed + one-of [1 0]] ifelse detection >= 1 [set detection detection + one-of [-1 0 0 1]] [set detection detection + one-of [0 0 1]] ] ] ] ask turtles [set energy starting-energy] set days days + 1 reset-ticks set turns 0 ] end to eat-grass ask turtles [ if pcolor = green [ set pcolor brown set energy energy + food-energy ] ] end ;; unused to reproduce ask turtles [ if energy > 60 [ set energy energy - 50 hatch 1 [ set energy 10 ] ] ] end to check-death ask turtles [ if energy <= 0 [ die ] ] end to regrow-grass ask patches [ if random 100 < 3 [ set pcolor green ] ] end to set-color ask turtles[ set color scale-color red speed 0 30] end
There are 2 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Individual project.png | preview | Preview for 'Individual project' | about 5 years ago, by Louk Seton | Download |
This model does not have any ancestors.
This model does not have any descendants.