MIHS-17 Michael M, Nicole H

MIHS-17 Michael M, Nicole H preview image

1 collaborator

Default-person Nicole H (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.0.2 • Viewed 94 times • Downloaded 15 times • Run 0 times
Download the 'MIHS-17 Michael M, Nicole H' 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

globals [ max-cows ]  ; don't let cows population grow too large
; cows and wolves are both breeds of turtle.
breed [ cows cow ]  ; cows is its own plural, so we use "a-cows" as the singular.
breed [ wolves wolf ]
breed [ humans human ]
turtles-own [ energy ]       ; both wolves and cows have energy
patches-own [ countdown ]

to setup
  clear-all
  ifelse netlogo-web? [set max-cows 10000] [set max-cows 30000]

  ; Check model-version switch
  ; if we're not modeling grass, then the cows 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 = "cows-wolves-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-cows initial-number-cows  ; create the cows, then initialize their variables
  [
    set shape  "cow"
    set color white
    set size 3  ; easier to see
    set label-color blue - 2
    set energy random (2 * cows-gain-from-food)
    setxy random-xcor random-ycor
  ]

  create-wolves initial-number-wolves  ; create the wolves, then initialize their variables
  [
    set shape "wolf"
    set color black
    set size 2  ; easier to see
    set energy random (2 * wolf-gain-from-food)
    setxy random-xcor random-ycor
  ]

    create-humans initial-number-humans  ; create the cows, then initialize their variables
  [
    set shape  "person"
    set color turquoise
    set size 2  ; easier to see
    set label-color blue - 2
    set energy random (2 * cows-gain-from-food)
    setxy random-xcor random-ycor
  ]

  display-labels
  reset-ticks
end 

to go
  ; stop the simulation of no wolves or cows
  if not any? turtles [ stop ]
  ; stop the model if there are no wolves and the number of cows gets very large
  if not any? wolves and count cows > max-cows [ user-message "Humans have killed every living organism on the planet" stop ]
  ask cows [
    move
    if model-version = "cows-wolves-grass" [ ; in this version, cows eat grass, grass grows and it costs cows energy to move
      set energy energy - 1  ; deduct energy for cows only if running cows-wolf-grass model version
      eat-grass  ; cows eat grass only if running cows-wolf-grass model version
      death ; cows die from starvation only if running cows-wolf-grass model version
    ]
    reproduce-cows  ; cows reproduce at random rate governed by slider
  ]
  ask wolves [
    move
    set energy energy - 1  ; wolves lose energy as they move
    eat-cows ; wolves eat a cows on their patch
    death ; wolves die if our of energy
    reproduce-wolves ; wolves reproduce at random rate governed by slider
  ]
  if model-version = "cows-wolves-grass" [ ask patches [ grow-grass ] ]
  ; set grass count patches with [pcolor = green]
  tick
  display-labels
  ask humans [
    move
    set energy energy ;
    eat-wolves ;
    death ;
    reproduce-humans ;
  ]
end 

to move  ; turtle procedure
  rt random 50
  lt random 50
  fd 1
end 

to eat-grass  ; cows procedure
  ; cows eat grass, turn the patch brown
  if pcolor = green [
    set pcolor brown
    set energy energy + cows-gain-from-food  ; cows gain energy by eating
  ]
end 

to reproduce-cows  ; cows procedure
  if random-float 100 < cows-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-wolves  ; wolf procedure
  if random-float 100 < wolf-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-humans  ; wolf procedure
  if random-float 100 < human-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-cows  ; wolf procedure
  let prey one-of cows-here                    ; grab a random cows
  if prey != nobody  [                          ; did we get one?  if so,
    ask prey [ die ]                            ; kill it, and...
    set energy energy + wolf-gain-from-food + human-gain-from-food     ; get energy from eating
  ]
end 

to eat-humans  ; wolf procedure
  let prey one-of humans-here                    ; grab a random cows
  if prey != nobody  [                          ; did we get one?  if so,
    ask prey [ die ]                            ; kill it, and...
    set energy energy + wolf-gain-from-food    ; get energy from eating
  ]
end 

to eat-wolves  ; human procedure
  let prey one-of wolves-here                    ; grab a random cows
  if prey != nobody  [                          ; did we get one?  if so,
    ask prey [ die ]                            ; kill it, and...
    set energy energy + human-gain-from-food     ; get energy from eating
  ]
end 

to death  ; turtle procedure (i.e. both wolf nd cows 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 = "cows-wolves-grass" [
    report patches with [pcolor = green]
  ]
  [ report 0 ]
end 

to display-labels
  ask turtles [ set label "" ]
  if show-energy? [
    ask wolves [ set label round energy ]
    if model-version = "cows-wolves-grass" [ ask cows [ 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 Nicole H.

Attached files

File Type Description Last updated
MIHS-17 Michael M, Nicole H.png preview Preview for 'MIHS-17 Michael M, Nicole H' over 6 years ago, by Nicole H Download

This model does not have any ancestors.

This model does not have any descendants.