Dragons-Humans-Spam

Dragons-Humans-Spam preview image

1 collaborator

Default-person Jacob Halvorson (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 93 times • Downloaded 13 times • Run 0 times
Download the 'Dragons-Humans-Spam' 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

globals [ max-humans ]      ; Maximum number of humans variable

breed [ humans human ]      ; breed of humans
breed [ dragons dragon ]    ; breed of dragons

turtles-own [ energy age ]  ; dragons and humans both have energy and an age

patches-own [ countdown ]   ; patches on display represent if spam is available, countdown for spam reproduction

to setup
  clear-all
  set max-humans 10000 ; Maximum number of humans to display, then the model stops

  ; Creating colors for the patches to be either brown for spam, or black for no spam
  ask patches [
      set pcolor one-of [ brown black ]
      ifelse pcolor = brown
        [ set countdown spam-production-time ]      ; Countdown is set to spam production time for brown patches (spam)
      [ set countdown random spam-production-time ] ; Random time for black patches to turn brown (into spam)
    ]

  create-humans initial-number-humans  ; creating humans and initial values
  [
    set shape  "person farmer"
    set color gray
    set size 1.5
    set energy random (2 * human-gain-from-food)
    set age 0
    setxy random-xcor random-ycor
  ]

  create-dragons initial-number-dragons  ; creating dragons and initial values
  [
    set shape "bird side"
    set color red
    set size 2
    set energy random (10 * dragon-gain-from-food)
    set age 0
    setxy random-xcor random-ycor
  ]
  reset-ticks
  update-plot
end 

to go
  ; if there are no dragons or humans, stop the model
  if not any? turtles [ stop ]

  ; if the there no dragons and the number of humans is too large, stop the model
  if not any? dragons and count humans > max-humans [ user-message "Overpopulation of humans." stop ]

  ; Actions of humans
  ask humans [
    move                              ; Move around
    set energy energy - 1             ; Decrease energy by moving
    eat-spam                          ; Eat spam
    set age age + 1                   ; Increase age by 1
    death                             ; Death by starvation/no energy
    if age > max-human-age [ die ]    ; If age of human is larger than the max, die
    reproduce-humans                  ; Human reproduction dictated by slider in interface
  ]

  ; Actions of dragons
  ask dragons [
    move                              ; Move around
    set energy energy - 1             ; Decrease energy by moving
    eat-humans                        ; Eat humans
    set age age + 1                   ; Increase age by 1
    death                             ; Death by starvation/no energy
    if age > max-dragon-age [ die ]   ; If the age of the dragon is larger than the max, die
    reproduce-dragons                 ; Dragon reproduction dictated by slider in interface
  ]

  ask patches [ produce-spam ] ; Produce the spam

  tick
  update-plot
end 

; humans and dragons move around randomly

to move
  rt random 50  ; randomly rotate clockwise between 0 and 50 degrees
  lt random 50  ; randomly rotate counterclockwise between 0 and 50 degrees
  fd 1          ; take 1 step in that direction
end 

; Action of eating spam for humans

to eat-spam
  ; if the patch is brown (spam), then turn it black
  if pcolor = brown [
    set pcolor black
    set energy energy + human-gain-from-food ; humans gain energy by eating spam
  ]
end 

; Action of reproducing humans

to reproduce-humans
  if random-float 100 < human-birth-rate [  ; random chance to be able to produce
    set energy (energy / 2)                 ; divide energy between parent and child
    hatch 1 [                               ; hatch a child and move it forward 1 step in a random direction
      rt random-float 360
      fd 1
      set age 0
      set energy energy / 2
    ]
  ]
end 

; Action of eating humans for dragons

to eat-humans
  let prey one-of humans-here                   ; grab a random human
  if prey != nobody  [                          ; if dragon gets a human
    ask prey [ die ]                            ; dragon eats the human
    set energy energy + dragon-gain-from-food   ; get energy from eating human
  ]
end 

; Action of reproducing dragons

to reproduce-dragons
  if random-float 100 < dragon-birth-rate [  ; random chance to be able to produce
    set energy energy / 2                    ; divide energy between parent and child
    hatch 1 [                                ; hatch a child and move it forward 1 step in a random direction
      rt random-float 360
      fd 1
      set age 0
      set energy energy / 2
    ]
  ]
end 

; Action of dying for humans and dragons

to death
  ; if energy gets below zero, die
  if energy < 0 [ die ]
end 

; Action of producing spam using a countdown

to produce-spam
  ; countdown on black patches, if it reaches 0, produce some spam
  if pcolor = black [
    ifelse countdown <= 0
      [ set pcolor brown
        set countdown spam-production-time ]
      [ set countdown countdown - 1 ]
  ]
end 

; Report the number of spam for the plot

to-report spam
  report patches with [pcolor = brown]
end 

; Update the plot with the amount of dragons and humans

to update-plot
  set-current-plot "dragons-humans-spam"
  set-current-plot-pen "dragons"
  plot count dragons
  set-current-plot-pen "humans"
  plot count humans
end 

There are 4 versions of this model.

Uploaded by When Description Download
Jacob Halvorson over 2 years ago New Values Download this version
Jacob Halvorson over 2 years ago Update on graph Download this version
Jacob Halvorson over 2 years ago New colors on graph Download this version
Jacob Halvorson over 2 years ago Initial upload Download this version

Attached files

File Type Description Last updated
Dragons-Humans-Spam.png preview Preview for 'Dragons-Humans-Spam' over 2 years ago, by Jacob Halvorson Download

This model does not have any ancestors.

This model does not have any descendants.