Bradley Model

Bradley Model preview image

1 collaborator

Default-person Bradley Davey (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.2.2 • Viewed 74 times • Downloaded 1 time • Run 0 times
Download the 'Bradley Model' 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 [
 badger-pxcor
 badger-pycor
 agent-near
 speed
 squirrel-speed
 badger-eats-squirrel
 coyote-eats-squirrel
 squirrel-survives
 squirrel-survives-counter
 squirrels-who
]

breed [badgers badger]
breed [coyotes coyote]
breed [squirrels squirrel]
;breed [acorns acorn]

badgers-own [badger-adrenaline badger-speed squirrel-near?]
coyotes-own [coyote-adrenaline coyote-speed squirrel-near?]

squirrels-own [
  chased-by-coyote?
  chased-by-badger?
  coyote-near?
  badger-near?
  fear
  exhaustion
]

patches-own [
  predator-scent
  prey-scent
]

to go
  set squirrel-survives squirrel-survives + 1
  ;if squirrel-survives > squirrel-survives-at-ticks [
  ;  reset-ticks
  ;  show "The squirrel survived another day!"
  ;  set squirrel-survives-counter squirrel-survives-counter + 1
  ;]

  if not any? squirrels [
    ;reset-ticks how to do this?
    wait 2
    clear-turtles
    create-agents
  ]

    ;create-squirrels 1 [
    ;setxy (5 - random 20) 4
    ;set color red
    ;set size 0.75
    ;set heading 90
    ;set chased-by-coyote? False
    ;set coyote-near? False
    ;set badger-near? False] ]

  ;if ticks >= squirrel-survives-at-ticks [set squirrel-survives squirrel-survives + 1]
  ; how to do this?

  move-badgers
  move-coyotes
  move-squirrels

  ask patches [
    if prey-scent >= 0.1 [set prey-scent prey-scent - 0.05]
    if predator-scent >= 0.1 [set predator-scent predator-scent - 0.05]
  ]

  tick
end 

;;;;;;;;;;;; create agents (badger, coyote, squirrel) ;;;;;;;;;;;;;;;;;;;;

to create-agents
    create-badgers 1 [setxy (12 - random 24) -7
    set color white
    let random-heading random 2
    ifelse random-heading = 0 [set heading 90] [set heading 270]
    ifelse badger? [st set badger-speed 0.185] [ht set badger-speed 0]
    set squirrel-near? False]

  create-coyotes 1 [
    ifelse coyote? [st set coyote-speed 0.2 setxy (5 + random 10) 4] [ht set coyote-speed 0 setxy (5 + random 10) -7]
    set size 1.5
    set color brown
    let random-heading random 2
    ifelse random-heading = 0 [set heading 90] [set heading 270]
    set squirrel-near? False]

  create-squirrels 1 [
    setxy (5 - random 20) 4
    set color red
    set size 0.75
    let random-heading random 2
    ifelse random-heading = 0 [set heading 90] [set heading 270]
    set chased-by-coyote? False
    set coyote-near? False
    set squirrel-speed 0.2
    set badger-near? False
    ]
end 

;;;;;;;;;;;; move commands for agents ;;;;;;;;;;

to move-badgers
  ask badgers [
    if [pcolor] of patch-ahead 1 != black and [pcolor] of patch-left-and-ahead 90 1 = black [lt 90]
    if [pcolor] of patch-ahead 1 != black and [pcolor] of patch-right-and-ahead 90 1 = black [rt 90]
    let random-turn random 100
    if random-turn = 50 and not any? squirrels in-radius 5 [rt 180]
    ifelse can-move? 1 and [pcolor] of patch-ahead 1 = black
    [fd badger-speed]
    [rt 180]

    let prey one-of squirrels-here
    if prey != nobody [
      ask prey [ die ]
      set badger-eats-squirrel badger-eats-squirrel + 1]

    ask patch-here [set predator-scent predator-scent + 1]
    ;ifelse patch-here predator-scent = 0 ;; need to ask patch's value for this var

  ]
end 

to move-coyotes
  ask coyotes [
    squirrel-near-coyote?
    ifelse coyote-adrenaline >= 1 [set coyote-speed 0.30] [set coyote-speed 0.20]
    if coyote-adrenaline > 0 [set coyote-adrenaline coyote-adrenaline - 0.5]
    let random-turn random 100
    if random-turn = 50 and not any? squirrels in-radius 6 [rt 180]
    ifelse can-move? 1 and [pcolor] of patch-ahead 1 = green
    [fd speed]
    [rt 180]
    ask patch-here [set predator-scent predator-scent + 1]

    let prey one-of squirrels-here
    if prey != nobody [
      ask prey [ die ]
      set coyote-eats-squirrel coyote-eats-squirrel + 1
    ] ;show ["the squirrel was eaten!"]]

  ]
end 

to move-squirrels


  ask squirrels [
    ;; could have an underground procedure/state if patch color here = black, true
    ;; squirrel needs to be able to come back up from underground ...
    ;chase-by-coyote?

    coyote-near-squirrel?
    badger-near-squirrel?

    if fear > 0 [set fear fear - 0.5]
    ifelse fear > 0 [set squirrel-speed 0.25] [set squirrel-speed 0.15]

    if [pcolor] of patch-here = black and [pcolor] of patch-ahead 1 = green [
      fd 1
      let random-turn random 2
      ifelse random-turn = 1 [ rt 90 ] [ lt 90]
    ]
    if (chased-by-coyote? or coyote-near?) and [pcolor] of patch-left-and-ahead 90 1 = black [lt 90]
    if (chased-by-coyote? or coyote-near?) and [pcolor] of patch-right-and-ahead 90 1 = black [rt 90]


    ifelse can-move? 1 and ([pcolor] of patch-ahead 1 = green or [pcolor] of patch-ahead 1 = black)
    [fd squirrel-speed]
    [rt 180]
    ask patch-here [set prey-scent prey-scent + 1]

  ]
end 


;;;;;;; chase search run ;;;;;;;

to squirrel-near-coyote?
  if not squirrel-near? [
  if any? squirrels in-radius 5

    [
      set squirrel-near? True set coyote-adrenaline coyote-adrenaline + 30 ]
  ]

  if not any? squirrels in-radius 5
  [set squirrel-near? False]
end 

to prey-near
  ifelse count turtles in-radius 2 = 0
  [set agent-near False]
  [set agent-near True]
end 

to coyote-near-squirrel?
  if not coyote-near? [
    if any? coyotes in-radius 3 and [pcolor] of patch-here = green and abs ([heading] of squirrel 2 - [heading] of coyote 1) > 10
    [set coyote-near? True rt 180 set fear fear + 18]]

  if not any? coyotes in-radius 1 and [pcolor] of patch-here = black
  [set coyote-near? False set squirrel-speed 0.15] ;; squirrel slows down underground
end 

to badger-near-squirrel?


  if not badger-near?
  [if any? badgers in-radius 2 and [pcolor] of patch-here = black and abs ([heading] of squirrel 2 - [heading] of badger 0) > 10
    [set badger-near? True rt 180 set fear fear + 5]]

  if not any? badgers in-radius 4 and [pcolor] of patch-here = black
  [set badger-near? False set squirrel-speed 0.20]
end 

to chase-by-coyote?
  ifelse [predator-scent] of patch-here >= 0.6
  [ask squirrels [set chased-by-coyote? True]]
  [ask squirrels [set chased-by-coyote? False]]
end 

to move
end 

;;;;;;; report stuff ;;;;;;

to-report badger-eats-squirrel-counter
  report badger-eats-squirrel
end 

to-report coyote-eats-squirrel-counter
  report coyote-eats-squirrel
end 

;;;;;;;;;;;;;;;;;;;;; world generation ;;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all
  set-default-shape squirrels "squirrel"
  set-default-shape coyotes "wolf"
  set-default-shape badgers "badger"
  ;set-default-shape acorns "acorn"
  make-grass
  make-badger-burrows-dirt
  make-sky
  make-badger-burrows-burrows
  create-agents
  set speed 0.2
  set squirrel-speed 0.2
  set squirrel-survives-counter 0
  reset-ticks
end 

to make-grass
  ask patches [if (abs pxcor) < 20 and
    pycor = 4 [set pcolor green]]
end 

to make-badger-burrows-dirt
  ask patches [if (abs pxcor) < 20 and pycor < 4 [set pcolor brown]]
end 

to make-sky
  ask patches [if pcolor = black [set pcolor blue] ]
end 

to make-badger-burrows-burrows
  set badger-pxcor 12
  set badger-pycor 3
  repeat 10 [
  ask patches with
  [pycor = badger-pycor and (abs pxcor) = badger-pxcor]
  [set pcolor black]
  ;; loop through to make vertical part of burrow
  set badger-pycor (badger-pycor - 1)
  ]

 repeat 13 [
  ask patches with
  [pycor = badger-pycor and (abs pxcor) = badger-pxcor]
  [set pcolor black]
  ;; loop through to make vertical part of burrow
  set badger-pxcor (badger-pxcor - 1)
  ]
end 

There are 2 versions of this model.

Uploaded by When Description Download
Bradley Davey 8 months ago updating to remove non-salient information from code tab and updating coyote colors Download this version
Bradley Davey 8 months ago Initial upload Download this version

Attached files

File Type Description Last updated
Bradley Model.png preview Preview for 'Bradley Model' 8 months ago, by Bradley Davey Download

This model does not have any ancestors.

This model does not have any descendants.