Deer vs Plants

Deer vs Plants preview image

1 collaborator

Default-person Chris Caprette (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.4.0 • Viewed 29 times • Downloaded 0 times • Run 0 times
Download the 'Deer vs Plants' modelDownload this modelEmbed this model

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

;; defines the types of turtle agents
breed [invasives invasive] ;; creates the invasive plants
breed [natives native] ;; creates the native plants
breed [deer a-deer] ;; creates the herbivores, deer is both singular and plural so "a-deer" is used for one deer

natives-own [age max-life]
invasives-own [age max-life]
globals [ restricted-zone ]

;******************************* SETTING UP THE MODEL *************************************

to setup ;; what to do when the "Setup" button is pressed
  clear-all ;; clears all patches and turtles
  setup-patches ;; calls "setup-patches" procedure
  setup-deer ;; calls "setup-deer" procedure below
  setup-invasives ;; calls "setup-plants" procedure below
  setup-natives ;; calls the "setup-natives procedure below
  reset-ticks
end 

;; sets the patch properties background

to setup-patches
  ask patches
   [
    set pcolor 33 ;; sets the patch color to dark brown
   ]
  set restricted-zone patches with [ pxcor >= -5 and pxcor < 5 and pycor >= -5 and pycor < 5 ]

ask restricted-zone
  [
    ifelse enclosure?
    [ set pcolor black ]
    [ set pcolor 33 ]
]
end 

;; procedure to create the native plants and set their characteristics

to setup-natives
  create-natives number-of-natives ;; sets the number of natives according to the slider
  ask natives ;; sets the characteristics of the invasives
   [
    setxy random-xcor random-ycor ;; distributes the natives randomly
    set shape "plant" ;; gives them the plant shape
    set color 65 ;; sets the color to bright green
    set size 1.0 ;; makes them small
    set max-life 1000 ;; give them a maximum lifespan of 1000
    set age random max-life ;; set each turtles age between 0 and one half of max-life
  ]
end 

;; procedure to create the invasive plants and set their characteristics

to setup-invasives
  create-invasives number-of-invasives ;; sets the number of invasives according to the slider
    ask invasives ;; sets the characteristics of the invasives
    [
      setxy random-xcor random-ycor ;; distributes the invasives randomly
      set shape "plant" ;; gives them the plant shape
      set color 48 ;; sets the color to pale yellow
      set size 1.0 ;; makes them small
      set max-life 1000 ;; give them a maximum lifespan of 1000
      set age random max-life ;; set each turtles age between 0 and max-life
      while
       [
         member? patch-here restricted-zone
       ]
     [
      setxy random-xcor random-ycor
  ]
   ]
end 

;; procedure to create the deer and set their characteristics

to setup-deer
  create-deer number-of-deer ;; sets the number of deer according to the slider
  ask deer ;; gives the deer their characteristics
  [
    set shape "color_deer" ;; makes the turtles deer-shaped
    set color 28 ;; sets the color to a light orangish-brown
    set size 2 ;; makes them large enough to see clearly
    setxy random-xcor random-ycor ;; distributes the deer randomly
    while
    [
      member? patch-here restricted-zone
    ]
    [
      setxy random-xcor random-ycor
  ]
  ]
end 
;; end of the setup procedures

;;******************************* RUNNING THE MODEL **********************************
To go

  ask deer
  [
    move-deer ;; calls the "move-deer" procedure
    eat-plants ;; calls the "eat-natives" procedure
  ]

  ask natives
  [
    set age age + 1 ;; native plants grow older by 1
    if age > 1000 ;; 1000 is the maximum lifespan
    [
      die
    ]
  ]

  ask invasives
  [
    set age age + 1 ;; invasive plants grow older by 1
    if age > 1000 ;; 1000 is the maximum lifespan
    [
      die
    ]
  ]
tick
;end

ask restricted-zone
  [
    ifelse enclosure?
    [ set pcolor black ]
    [ set pcolor 33 ]
]

;;********************** PLANT REPRODUCTION ***************************

  let native-repro-prob random-float 1.0 ;; creates a random number between 0 and 1

  ;; controls reproduction of native plants calling on the slider
     if any? natives
    [
     let random-native one-of natives ;; limit number of invasives that can reproduce
     ask random-native
      [
       let empty-patches patches with
      [
       not any? turtles-here ;; checks the landscape for empty patches
      ]
        if any? empty-patches ; an empty patch has no plants or deer
      [
       if native-repro-prob < natives-repro ;; compares natives-repro to the random number
       [
        hatch 1
         [
          move-to one-of empty-patches ;; if there are empty patches the plant reproduces and moves new plant to the empty patch
          set age 1
         ]
       ]
      ]
     ]
    ]

  let invasive-repro-prob random-float 1.0 ;; creates a random number between 0 and 1


  ;; controls plant reproduction calling on the slider, sequence based on ticks
  if any? invasives
   [
     let random-invasive one-of invasives ;; limit number of invasives that can reproduce
     ask random-invasive
     [
      let empty-patches patches with
     [
      not any? turtles-here ; an empty patch has no plants or deer
     ]
        if any? empty-patches
       [
        if invasive-repro-prob < invasives-repro
         [
           hatch 1
         [
            move-to one-of empty-patches
            set age 1
         ]
        ]
       ]
      ]
    ]
end 

;; ********************* DEER STUFF ****************************

to move-deer
  let move-prob random-float 1.0
    ask one-of deer
    [
     ifelse move-prob < 0.5 and pcolor != black
    [
     right random 360
     forward 1 ;; move the deer in a random direction 1 unit
    ]
    [
      set heading heading - 180
      forward 2
    ]
  ]
end 

to eat-plants
  let eat-prob random-float 1.0

  let native-on-patch natives-here ;; check for native plants on a patch
    if any? native-on-patch ;; conditions the action based on presence of a native plant
      [
        ask one-of native-on-patch
      [
        if eat-prob < deer-preference ;; a deer-preference > 0.5 makes it more likely the deer will eat a native
          [
            die
          ] ;; if there is a native plant on a patch with a deer, then the native plant is consumed by the deer
       ]
      ]

  let invasive-on-patch invasives-here
    if any? invasive-on-patch ;; conditions the action based on the presence of an invasive plant
    [
      ask one-of invasive-on-patch
    [
      if eat-prob > deer-preference ;; a deer-preference of <0.5 makes it more likely the deer will eat an invasive
        [
          die
        ]
    ]
  ]
end 

There is only one version of this model, created about 19 hours ago by Chris Caprette.

Attached files

File Type Description Last updated
Deer vs Plants.png preview Preview for 'Deer vs Plants' about 19 hours ago, by Chris Caprette Download

This model does not have any ancestors.

This model does not have any descendants.