Final Program Tutorial 3

Final Program Tutorial 3 preview image

1 collaborator

Default-person Colleen Moore (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.2.2 • Viewed 87 times • Downloaded 5 times • Run 0 times
Download the 'Final Program Tutorial 3' modelDownload this modelEmbed this model

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]     ;; for keeping track of when the turtle is ready
                         ;; to reproduce and when it will die

to setup
  clear-all
  setup-patches
  setup-turtles
  reset-ticks
end 

to setup-patches
  ask patches [ set pcolor green ]
end 

to setup-turtles
  create-turtles number       ;; uses the value of the number slider to create turtles
  ask turtles [ setxy random-xcor random-ycor ]
end 

to go
  if ticks >= number-of-ticks [ stop ]  ;; stop after user defined # of ticks
  if not any? turtles [ stop ]      ;; stops if number of turtles reaches 0
  move-turtles
  eat-grass
  check-depth
  reproduce
  regrow-grass
  tick      ;; increase the tick counter by 1 each time through
end 

to move-turtles
  ask turtles [
    right random 360
    forward 1
    set energy energy - energy-to-move     ;; when the turtle moves it looses the user defined amount of energy
  ]
end 

to eat-grass
  ask turtles [
    if pcolor = green [
      set pcolor black       ;; the value of birth-energy slider is added to energy
      set energy birth-energy
    ]
    ifelse show-energy?
      [ set label energy ]      ;; the label is set to be the value of the energy
      [ set label "" ]          ;; the label is set to an empty text value
  ]
end 

to reproduce
  ask turtles [
    if energy > birth-energy [
      set energy energy - birth-energy      ;; take away birth-energy to give birt
      hatch 1 [ set energy birth-energy ]   ;; give this birth-energy to the offspring
    ]
  ]
end 

to check-depth
  ask turtles [
    if energy <= 0 [ die ]      ;; removes the turtle if it has no energy left
  ]
end 

to regrow-grass
  ask patches [
    if random 100 < grass-regrowth-rate [ set pcolor green ]      ;; each patch has a random chance of growing grass
  ]                                                               ;; based on the grass-regrowth-rate set by user
end 

There is only one version of this model, created over 1 year ago by Colleen Moore.

Attached files

File Type Description Last updated
Final Program Tutorial 3.png preview Preview for 'Final Program Tutorial 3' over 1 year ago, by Colleen Moore Download

This model does not have any ancestors.

This model does not have any descendants.