;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 1. DECLARATIONS                                                        ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

breed  [ mammals  mammal ]
breed  [ reptiles reptile ]

turtles-own [
  body-size             ;; intrinsic size of the turtle (scales movement, energy threshold, predation)
  energy                ;; accumulated energy from eating; when ≥ body-size * tummy-size-factor → breed
  breeding-mode?        ;; true if turtle is seeking a mate
  infected?             ;; true if reptile is infected by fungus
  family-avoid-timer    ;; ticks remaining to avoid close proximity to family after breeding
  base-color            ;; default color to revert to when not in special state
  sprint-timer          ;; ticks remaining in a sprint (fleeing or chasing)
  cooldown-timer        ;; ticks remaining before turtle may hunt again
  has-moved?            ;; true if turtle has already moved this tick
  post-kill-immunity    ;; ticks remaining immune to infection after making a kill
]

patches-own [
  plant-mass            ;; units of plant biomass on this patch
  fungus-level          ;; units of fungal biomass on this patch
  meat-level            ;; units of meat available here (dropped by kills)
  meat-age              ;; ticks since meat was created; only meat-age > 0 is edible
]

globals [
  BASE-SPEED               ;; base movement speed (patches per tick)
  REPTILE-SPEED-MULTIPLIER ;; speed multiplier applied to reptiles
  MINIMUM-SIZE             ;; minimum allowed body-size for hatchlings
  zcor                     ;; vertical offset so turtles hover above patches

  ;; slider‐defined parameters (commented out here; defined on the Interface)
  ;; INITIAL-REPTILES            ; number of reptile agents at setup
  ;; INITIAL-MAMMALS             ; number of mammal agents at setup
  ;; INITIAL-PLANT-SEEDS         ; initial number of plant patches
  ;; INITIAL-FUNGAL-SPORES       ; initial number of fungus patches
  ;; OFFSPRING_SIZE_FRAC_DIFF    ; variation fraction in offspring size
  ;; FOOD-CONSUMPTION-RATE       ; max food units consumed per tick
  ;; FAMILY-AVOIDANCE-DUR        ; ticks to avoid family after reproduction
  ;; LIGHT-LEVEL                 ; ambient light level (0–1) affecting growth
  ;; FUNGAL-GROWTH-RATE          ; base rate at which fungus spreads
  ;; PLANT-GROWTH-RATE           ; base rate at which plants spread
  ;; INITIAL-SIZE-FRAC           ; initial size variation fraction
  ;; FUNGAL-RECOVERY-CHANCE      ; per-tick chance reptiles recover from infection
  ;; SEED-SPAWN-PERIOD           ; avg ticks between random plant seed spawns
  ;; PERCEPTION-RADIUS           ; detection radius for food, threats, mates
  ;; PREY-SIZE-FRAC-MIN          ; min prey size as fraction of predator
  ;; PREY-SIZE-FRAC-MAX          ; max prey size as fraction of predator
  ;; FUNGUS-AVOIDANCE            ; chance reptiles avoid fungus ahead
  ;; CHASE-DURATION              ; ticks spent sprinting when chasing prey
  ;; FLEE-DURATION               ; ticks spent sprinting when fleeing threat
  ;; ROT-CHANCE                  ; chance meat patch turns to fungus when eaten
  ;; MEAT-BONUS                  ; energy gained per unit of meat
  ;; HUNT-COOLDOWN               ; ticks predator must wait post-hunt

  ;; meat counts (when eating live turtles and scavenging)
  meat-consumed-by-mammals
  meat-consumed-by-reptiles

  ;; plant & fungus counters (when foraging)
  fungus-consumed-by-mammals
  plant-consumed-by-mammals
  plant-consumed-by-reptiles

  tummy-size-factor ;controls how much turtles need to eat before entering breeding mode

  SPORE-EMISSION     ;; how much each fungus patch emits per tick (e.g. 1)
  SPORE-DIFFUSION    ;; fraction of neighbor field that flows in (e.g. 0.2)
  SPORE-DECAY        ;; fraction lost each tick (e.g. 0.05)
  PREDATION-IMMUNITY-TICKS  ;; how many ticks of immunity you want
]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 2. SETUP                                                               ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all

   ;; set our movement constants
  set BASE-SPEED               1
  set REPTILE-SPEED-MULTIPLIER 1.25
  ;; enforce a minimum initial size
  set MINIMUM-SIZE 2
  set zcor 1  ;; Keep turtle above patches
  set tummy-size-factor 10

  set SPORE-EMISSION  1
  set SPORE-DIFFUSION 0.2
  set SPORE-DECAY     0.05
  set PREDATION-IMMUNITY-TICKS 20

  ;; -- reset patches --
  ask patches [
    set plant-mass    0
    set fungus-level  0
    set meat-level   0
    set meat-age     0
    set pcolor        scale-color white LIGHT-LEVEL 0 1
  ]

  ;; -- seed plants & fungus --
  ask n-of INITIAL-PLANT-SEEDS   patches [
    set plant-mass 1
    set pcolor     green
  ]
  ask n-of INITIAL-FUNGAL-SPORES patches [
    set fungus-level 1
    set pcolor       violet
  ]

  ;; -- create mammals with float sizes & initialized state --
  create-mammals INITIAL-MAMMALS [
    ;; size variability with a global minimum
    let base-size 3.0
    let frac      INITIAL-SIZE-FRAC
    let raw-min   base-size * (1 - frac)
    let min-size  max (list raw-min MINIMUM-SIZE)
    let max-size  base-size * (1 + frac)
    set body-size (random-float (max-size - min-size)) + min-size
    set size      body-size
    set post-kill-immunity 0

    ;; visuals & shape
    set base-color       brown
    set color            base-color
    set shape            "mammal"
    set zcor 1

    ;; initialize state
    set energy           0
    set breeding-mode?   false
    set infected?        false
    set family-avoid-timer 0

    set sprint-timer 0
    set cooldown-timer 0

    move-to one-of patches

    ;; clear any food under this newborn
    ask patch-here [
      set plant-mass   0
      set fungus-level 0
      set meat-level   0
      set pcolor scale-color white LIGHT-LEVEL 0 1]
  ]

  ;; -- create reptiles with float sizes & initialized state --
  create-reptiles INITIAL-REPTILES [
    let base-size 5.0
    let frac      INITIAL-SIZE-FRAC
    let raw-min   base-size * (1 - frac)
    let min-size  max (list raw-min MINIMUM-SIZE)
    let max-size  base-size * (1 + frac)
    set body-size (random-float (max-size - min-size)) + min-size
    set size      body-size

    set base-color       (yellow + 2)
    set color            base-color
    set shape            "reptile"
    set zcor 1

    set energy           0
    set breeding-mode?   false
    set infected?        false
    set post-kill-immunity 0

    set sprint-timer 0
    set cooldown-timer 0
    set family-avoid-timer 0

    move-to one-of patches

    ;; clear any food under this newborn
    ask patch-here [
    set plant-mass   0
    set fungus-level 0
    set meat-level   0
      set pcolor scale-color white LIGHT-LEVEL 0 1]
  ]

  ;; initialize all consumption counters
  set meat-consumed-by-mammals    0
  set meat-consumed-by-reptiles   0
  set fungus-consumed-by-mammals  0
  set plant-consumed-by-mammals   0
  set plant-consumed-by-reptiles  0

  reset-ticks
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 3. MAIN LOOP ("go")                                                    ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  ;; Reset movement flags
  ask turtles [ set has-moved? false ]

  no-display

  ;; age all meat by one tick
  ask patches with [ meat-level > 0 ] [
    set meat-age meat-age + 1
  ]

  ;; 1. background only on empty ground
  update-background-color

  ;; 2. animal behavior
  ask mammals [
    if family-avoid-timer > 0 [
      set family-avoid-timer family-avoid-timer - 1
    ]
    if not breeding-mode? [
      wander-and-hunt
    ]
    if breeding-mode? [
      seek-mate
    ]
  ]
  ask reptiles [
    if family-avoid-timer > 0 [
      set family-avoid-timer family-avoid-timer - 1
    ]
    if not breeding-mode? [
      wander-and-hunt
    ]
    if breeding-mode? [
      seek-mate
    ]
  ]

  ;; 3. reproduction & infection
  handle-mating
  ask reptiles [
    if [fungus-level] of patch-here > 0
      and not infected?
      and post-kill-immunity = 0 [
      set infected? true
    ]
    if infected? [
      handle-infection
    ]
  ]

  ;; 4. plant & fungus growth
  ask patches with [ plant-mass > 0 ] [
    grow-plants-on-patch
  ]
  spawn-plant-seeds

  ;diffuse-spores
  ask patches with [ fungus-level > 0 ] [
    grow-fungus-on-patch
    ;grow-fungus-chemotactic
  ]

  ;; 5. visual updates
  ;ask mammals  [ update-visuals ]
  ;ask reptiles [ update-visuals ]
  ask turtles [ update-visuals ]

  ;; finally, draw and advance time
  display
  tick

  ask turtles with [post-kill-immunity > 0] [
    set post-kill-immunity post-kill-immunity - 1
  ]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 4. BACKGROUND UPDATE                                                  ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to update-background-color
  ask patches with [
    plant-mass  = 0
    and fungus-level = 0
    and meat-level = 0
  ] [
    set pcolor scale-color white LIGHT-LEVEL 0 1
  ]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 5. FORAGING & MOVEMENT                                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to avoid-fungus-old
  ;; reptiles only
  if breed = reptiles [
    let ahead patch-ahead 1
    if ahead != nobody and [fungus-level] of ahead > 0 and random-float 1 < FUNGUS-AVOIDANCE [
      let safe patches in-radius PERCEPTION-RADIUS with [fungus-level = 0]
      if any? safe [
        face one-of safe
      ]
    ]
  ]
end

to avoid-fungus [orig-hdg]
  ;; reptiles only
  if breed = reptiles [
    let ahead patch-ahead 1
    if ahead != nobody
       and [fungus-level] of ahead > 0
       and random-float 1 < FUNGUS-AVOIDANCE [

      ;; pick one of three equally likely strategies
      let choice random 3

      if choice = 0 [
        ;; OPTION 1: head to any fungus-free plant patch in perception
        let safe-plants patches in-radius PERCEPTION-RADIUS with [
          plant-mass > 0
          and fungus-level = 0
        ]
        if any? safe-plants [
          face one-of safe-plants
          stop
        ]
        ;; if none, fall through to next options
      ]

      if choice = 1 [
        ;; OPTION 2: just wander
        rt random 360
        stop
      ]

      ;; OPTION 3: original detour logic
      let candidates neighbors4 with [
        fungus-level = 0
        and abs subtract-headings orig-hdg towards myself <= 90
      ]
      if any? candidates [
        let best min-one-of candidates [
          abs subtract-headings orig-hdg towards myself
        ]
        face best
        stop
      ]

    ]
  ]
end


to wander-and-hunt
  show-turtle
  if has-moved? [ stop ]
  if breeding-mode? [ stop ]

  ;; 1) EAT UNDERFOOT: MEAT
  if [meat-level] of patch-here > 0 and [meat-age] of patch-here > 0 [
    let eaten-m min (list FOOD-CONSUMPTION-RATE [meat-level] of patch-here)
    ask patch-here [
      set meat-level meat-level - eaten-m
      if meat-level = 0 [
        set meat-age 0
        set pcolor scale-color white LIGHT-LEVEL 0 1
        if [breed] of myself = mammals and random-float 1 < ROT-CHANCE [
          set fungus-level 1
          set pcolor violet
        ]
      ]
    ]
    set infected? false
    set energy energy + (MEAT-BONUS * eaten-m)
    if energy >= (body-size * tummy-size-factor) [
      set breeding-mode? true
      stop
    ]
    set has-moved? true
    stop
  ]

  ;; 2) EAT UNDERFOOT: FUNGUS (mammals only)
  if breed = mammals and [fungus-level] of patch-here > 0 [
    let eaten-f min (list FOOD-CONSUMPTION-RATE [fungus-level] of patch-here)
    ask patch-here [
      set fungus-level fungus-level - eaten-f
      if fungus-level <= 0 [
        set fungus-level 0
        set pcolor scale-color white LIGHT-LEVEL 0 1
      ]
    ]
    set fungus-consumed-by-mammals fungus-consumed-by-mammals + eaten-f
    set energy energy + eaten-f
    if energy >= (body-size * tummy-size-factor) [
      set breeding-mode? true
      stop
    ]
    set has-moved? true
    stop
  ]

  ;; 3) EAT UNDERFOOT: PLANTS
  if [plant-mass] of patch-here > 0 [
    let eaten-p min (list FOOD-CONSUMPTION-RATE [plant-mass] of patch-here)
    ask patch-here [
      set plant-mass plant-mass - eaten-p
      if plant-mass <= 0 [
        set plant-mass 0
        set pcolor scale-color white LIGHT-LEVEL 0 1
      ]
    ]
    if breed = mammals [
      set plant-consumed-by-mammals plant-consumed-by-mammals + eaten-p
    ]
    if breed = reptiles [
      set plant-consumed-by-reptiles plant-consumed-by-reptiles + eaten-p
    ]
    set energy energy + eaten-p
    if energy >= (body-size * tummy-size-factor) [
      set breeding-mode? true
      stop
    ]
    set has-moved? true
    stop
  ]

  ;; 4) SPRINT / HUNT‑COOLDOWN
  if sprint-timer > 0 [
    let spd BASE-SPEED
    if breed = reptiles [
      set spd spd * REPTILE-SPEED-MULTIPLIER
      if infected? [ set spd spd * 0.5 ]
    ]
    fd spd * (1.2 + random-float 0.3)
    set sprint-timer sprint-timer - 1
    if sprint-timer = 0 [
      set cooldown-timer HUNT-COOLDOWN
    ]
    set has-moved? true
    stop
  ]
  if cooldown-timer > 0 [
    set cooldown-timer cooldown-timer - 1
  ]

  ;; 6) COMPUTE STEP SIZE
  let step-size BASE-SPEED
  if breed = reptiles [
    set step-size step-size * REPTILE-SPEED-MULTIPLIER
    if infected? [ set step-size step-size * 0.5 ]
  ]
  if step-size <= 0 [
    set step-size 0.1
  ]

  ;; 7) FLEE THREATS
  let threats turtles in-radius PERCEPTION-RADIUS with [
    self != myself and
    body-size > ([body-size] of myself) * 1.5 and
    not (breeding-mode? and [breeding-mode?] of myself and breed = [breed] of myself)
  ]
  if any? threats [
    let threat min-one-of threats [distance myself]
    face threat
    rt 180
    if can-move? step-size [
      fd step-size
    ]
    set sprint-timer FLEE-DURATION
    set has-moved? true
    stop
  ]

  ;; 8) HUNT LIVE PREY (only off cooldown)
  if cooldown-timer = 0 and not (breed = reptiles and infected?) [
    let prey turtles in-radius PERCEPTION-RADIUS with [
      self != myself and
      body-size < ([body-size] of myself) * prey-size-frac-max and
      body-size > ([body-size] of myself) * prey-size-frac-min
    ]
    if any? prey [
      let target one-of prey
      face target
      if breed = reptiles [ avoid-fungus heading ]
      let d distance target
      let kill-range max list step-size (body-size / 2)
      if d <= kill-range [
        ask target [ kill-creature ]
        set post-kill-immunity PREDATION-IMMUNITY-TICKS
        set infected? false
        set cooldown-timer HUNT-COOLDOWN
        set has-moved? true
        stop
      ]
      if can-move? step-size [
        fd step-size
      ]
      set has-moved? true
      stop
    ]
  ]

  ;; 9) FORAGE FOR MEAT IN VISION
  let meat-patches patches in-radius PERCEPTION-RADIUS with [
    meat-level > 0 and meat-age > 0
  ]
  if any? meat-patches [
    let target-patch min-one-of meat-patches [distance myself]
    face target-patch
    if breed = reptiles [ avoid-fungus heading ]
    let d distance target-patch
    if can-move? step-size [
      ifelse d <= step-size [
        move-to target-patch
      ] [
        fd step-size
      ]
    ]
    if patch-here = target-patch [
      let eaten-m min (list FOOD-CONSUMPTION-RATE meat-level)
      ask patch-here [
        set meat-level meat-level - eaten-m
        if meat-level = 0 [
          set meat-age 0
          set pcolor scale-color white LIGHT-LEVEL 0 1
          if random-float 1 < ROT-CHANCE [
            set fungus-level 1
            set pcolor violet
          ]
        ]
      ]
      set energy energy + (MEAT-BONUS * eaten-m)
      if energy >= (body-size * tummy-size-factor) [
        set breeding-mode? true
        stop
      ]
      if breed = mammals [
        set meat-consumed-by-mammals meat-consumed-by-mammals + eaten-m
      ]
      if breed = reptiles [
        set meat-consumed-by-reptiles meat-consumed-by-reptiles + eaten-m
      ]
    ]
    set has-moved? true
    stop
  ]

  ;; 10) FORAGE FOR FUNGUS (mammals only)
  if breed = mammals [
    let fungus-patches patches in-radius PERCEPTION-RADIUS with [
      fungus-level > 0
    ]
    if any? fungus-patches [
      let target-patch min-one-of fungus-patches [distance myself]
      face target-patch
      let d distance target-patch
      if can-move? step-size [
        ifelse d <= step-size [
          move-to target-patch
        ] [
          fd step-size
        ]
      ]
      if patch-here = target-patch [
        let eaten-f min (list FOOD-CONSUMPTION-RATE fungus-level)
        ask patch-here [
          set fungus-level fungus-level - eaten-f
          if fungus-level <= 0 [
            set fungus-level 0
            set pcolor scale-color white LIGHT-LEVEL 0 1
          ]
        ]
        set energy energy + eaten-f
        set fungus-consumed-by-mammals fungus-consumed-by-mammals + eaten-f
        if energy >= (body-size * tummy-size-factor) [
          set breeding-mode? true
          stop
        ]
      ]
      set has-moved? true
      stop
    ]
  ]

  ;; 11) FORAGE FOR PLANTS
  let plant-patches patches in-radius PERCEPTION-RADIUS with [
    plant-mass > 0
  ]
  if any? plant-patches [
    let target-patch min-one-of plant-patches [distance myself]
    face target-patch
    if breed = reptiles [ avoid-fungus heading ]
    let d distance target-patch
    if can-move? step-size [
      ifelse d <= step-size [
        move-to target-patch
      ] [
        fd step-size
      ]
    ]
    if patch-here = target-patch [
      let eaten-p min (list FOOD-CONSUMPTION-RATE plant-mass)
      ask patch-here [
        set plant-mass plant-mass - eaten-p
        if plant-mass <= 0 [
          set plant-mass 0
          set pcolor scale-color white LIGHT-LEVEL 0 1
        ]
      ]
      set energy energy + eaten-p
      if energy >= (body-size * tummy-size-factor) [
        set breeding-mode? true
        stop
      ]
      if breed = mammals [
        set plant-consumed-by-mammals plant-consumed-by-mammals + eaten-p
      ]
      if breed = reptiles [
        set plant-consumed-by-reptiles plant-consumed-by-reptiles + eaten-p
      ]
    ]
    set has-moved? true
    stop
  ]

  ;; 12) RANDOM WANDER
  rt random 50 - 25
  if can-move? step-size [
    fd step-size
  ]
  set has-moved? true
end


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 6. REPRODUCTION & INFECTION                                            ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to kill-creature
  ;; 1) build a pool of nearby patches
  let pool patches in-radius 1
  ;; 2) decide how many meat‐pieces to drop
  let raw-pieces ceiling body-size
  let pieces min (list raw-pieces count pool)
  if pieces < raw-pieces [
    set pool patches in-radius 2
    set pieces min (list raw-pieces count pool)
  ]
  ;; 3) drop the meat on those patches
  ask n-of pieces pool [
    set meat-level meat-level + 1
    set meat-age   0
    set pcolor     red
  ]
  ;; 4) **now kill the turtle itself**
  die
end


to seek-mate
  show-turtle
  if not breeding-mode? [ stop ]

  ;; 1) FLEE any larger threat
  let threats turtles in-radius PERCEPTION-RADIUS with [
    self != myself
    and body-size > ([body-size] of myself) * 1.5
    and not (breeding-mode? and [breeding-mode?] of myself and breed = [breed] of myself)
  ]
  if any? threats [
    let threat min-one-of threats [ distance myself ]
    face threat
    rt 180
    ; Don't call avoid-fungus here because they'd rather risk infection than get eaten!
    let spd BASE-SPEED
    if breed = reptiles [
      set spd spd * REPTILE-SPEED-MULTIPLIER
      if infected? [ set spd spd * 0.5 ]
    ]
    let flee-speed spd * (1.2 + random-float 0.3)
    if can-move? flee-speed [ fd flee-speed ]
    set has-moved? true
    stop
  ]

  ;; 2) FIND A PARTNER
  let partner min-one-of turtles with [
    breed = [breed] of myself
    and breeding-mode?
    and self != myself
  ] [ distance myself ]
  if partner = nobody [ stop ]

  ;; 3) MOVE TOWARD THE PARTNER without overshooting
  face partner
  if breed = reptiles [ avoid-fungus heading ]
  let spd BASE-SPEED
  if breed = reptiles [
    set spd spd * REPTILE-SPEED-MULTIPLIER
    if infected? [ set spd spd * 0.5 ]
  ]
  let d distance partner
  if d <= spd [
    move-to partner
    set has-moved? true
    stop
  ]
  if can-move? spd [ fd spd ]
  set has-moved? true
end


to handle-mating
  ask mammals with [breeding-mode?] [
    if any? other mammals-here with [breeding-mode?] [
      reproduce-with one-of other mammals-here with [breeding-mode?]
    ]
  ]
  ask reptiles with [breeding-mode?] [
    if any? other reptiles-here with [breeding-mode?] [
      reproduce-with one-of other reptiles-here with [breeding-mode?]
    ]
  ]
end

to reproduce-with [mate]
  if not (breeding-mode? and [breeding-mode?] of mate) [ stop ]

  ;; determine brood size
  let num-offspring 0
  if breed = mammals [
    let r random-float 100
    if r < 65 [ set num-offspring 1 ]
    if r >= 65 [ set num-offspring 2 ]
  ]
  if breed = reptiles [
    let r random-float 100
    if r < 40 [ set num-offspring 3 ]
    if r >= 40 and r < 65 [ set num-offspring 3 ]
    if r >= 65 and r < 90 [ set num-offspring 2 ]
    if r >= 90 [ set num-offspring 1 ]
  ]
  ;; build offspring-size list with a global minimum
  let size1 body-size
  let size2 [body-size] of mate
  let raw-smaller min (list size1 size2)
  let raw-larger  max (list size1 size2)
  let frac OFFSPRING_SIZE_FRAC_DIFF
  let raw-s1 raw-smaller * (1 - frac)
  let raw-s4 raw-larger  * (1 + frac)
  ;; now enforce the minimum
  let s1 max (list raw-s1 MINIMUM-SIZE)
  let s2 max (list raw-smaller MINIMUM-SIZE)
  let s3 max (list raw-larger  MINIMUM-SIZE)
  let s4 max (list raw-s4 MINIMUM-SIZE)
  let possible-sizes (list s1 s2 s3 s4)

  ;; hatch
  hatch num-offspring [
    set shape [shape] of myself
    set body-size one-of possible-sizes
    set size body-size
    set energy 0
    set breeding-mode? false
    set infected? false
    set family-avoid-timer FAMILY-AVOIDANCE-DUR
    ;; color is handled in update-visuals
    set zcor 1
  ]

  ;; reset parents & nudge apart
  set breeding-mode? false
  set energy 0
  set family-avoid-timer FAMILY-AVOIDANCE-DUR
  ask mate [
    set breeding-mode? false
    set energy 0
    set family-avoid-timer FAMILY-AVOIDANCE-DUR
  ]
  rt 180 fd 1
  ask mate [ rt 180 fd 1 ]
  ask turtles-here with [family-avoid-timer > 0] [
    rt random 360 fd 1
  ]
end

to handle-infection
  if random-float 1 < FUNGAL-DEATH-CHANCE [
    kill-creature
    stop
  ]
  if random-float 1 < FUNGAL-RECOVERY-CHANCE [
    set infected? false
  ]
end

to update-visuals
  ;; ensure visible and appropriately sized
  show-turtle
  set size max (list 1 body-size)

  ;; 1) infected reptiles → magenta, then stop
  if breed = reptiles and infected? [
    set color magenta
    stop
  ]

  ;; 2) breeding turtles → orange for mammals, yellow for reptiles, then stop
  if breeding-mode? [
    ifelse breed = mammals [
      set color orange
    ] [
      set color yellow
    ]
    stop
  ]

  ;; 3) everyone else → their base color
  set color base-color
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 7. PATCH PROCEDURES (slow growth baseline × 0.01)                       ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; PLANT GROWTH & SPREAD (uniform biomass, replaces fungus)
to grow-plants-on-patch
  ;; ensure this patch remains a plant
  set plant-mass    1
  set fungus-level  0
  set pcolor        green

  ;; chance to colonize a neighboring patch (replace fungus but not meat)
  if random-float 1 < (PLANT-GROWTH-RATE * LIGHT-LEVEL * 0.01) [
    let targets neighbors with [
      plant-mass = 0 and
      meat-level = 0
    ]
    if any? targets [
      ask one-of targets [
        set plant-mass    1
        set fungus-level  0
        set pcolor        green
      ]
    ]
  ]
end

;; RANDOM NEW SEED SPAWNING (rare, global)
to spawn-plant-seeds
  ;; on average once every SEED-SPAWN-PERIOD ticks,
  ;; pick one patch (even if it currently has fungus) to become plant
  if random SEED-SPAWN-PERIOD = 0 [
    let target one-of patches with [
      plant-mass = 0 and
      meat-level = 0
    ]
    if target != nobody [
      ask target [
        set plant-mass    1
        set fungus-level  0
        set pcolor        green
      ]
    ]
  ]
end

to grow-fungus-on-patch
  ;; turn this patch into fungus (clearing any plants)
  set fungus-level 1
  set plant-mass    0
  set pcolor violet
  ;; then possibly spread to an empty neighbor
  if random-float 1 < (FUNGAL-GROWTH-RATE * (1 - LIGHT-LEVEL) * 0.01) [
    let empties neighbors with [
      fungus-level = 0 and
      plant-mass   = 0 and
      meat-level   = 0
    ]
    if any? empties [
      ask one-of empties [
        set fungus-level 1
        set pcolor violet
      ]
    ]
  ]
end
@#$#@#$#@
GRAPHICS-WINDOW
12
10
1025
1024
-1
-1
5.0
1
10
1
1
1
0
1
1
1
-100
100
-100
100
1
1
1
ticks
30.0

SLIDER
1237
13
1409
46
INITIAL-MAMMALS
INITIAL-MAMMALS
0
100
25.0
1
1
NIL
HORIZONTAL

SLIDER
1047
13
1219
46
INITIAL-REPTILES
INITIAL-REPTILES
0
100
25.0
1
1
NIL
HORIZONTAL

SLIDER
1243
85
1451
118
FAMILY-AVOIDANCE-DUR
FAMILY-AVOIDANCE-DUR
0
100
48.0
1
1
NIL
HORIZONTAL

SLIDER
1032
123
1227
156
FUNGAL-GROWTH-RATE
FUNGAL-GROWTH-RATE
0
3
1.5
0.05
1
NIL
HORIZONTAL

SLIDER
1033
159
1262
192
FUNGAL-RECOVERY-CHANCE
FUNGAL-RECOVERY-CHANCE
0
1
0.25
0.01
1
NIL
HORIZONTAL

SLIDER
1033
197
1336
230
FUNGAL-DEATH-CHANCE
FUNGAL-DEATH-CHANCE
0.0
0.1
0.001
.001
1
NIL
HORIZONTAL

SLIDER
1232
123
1418
156
PLANT-GROWTH-RATE
PLANT-GROWTH-RATE
0
3
1.5
.05
1
NIL
HORIZONTAL

SLIDER
1262
159
1462
192
SEED-SPAWN-PERIOD
SEED-SPAWN-PERIOD
0
20
2.0
1
1
NIL
HORIZONTAL

BUTTON
1423
15
1487
48
Setup
setup
NIL
1
T
OBSERVER
NIL
S
NIL
NIL
1

BUTTON
1494
14
1557
47
Go
go
T
1
T
OBSERVER
NIL
G
NIL
NIL
1

SLIDER
1455
85
1627
118
LIGHT-LEVEL
LIGHT-LEVEL
0
1
1.0
0.05
1
NIL
HORIZONTAL

SLIDER
1467
160
1642
193
PERCEPTION-RADIUS
PERCEPTION-RADIUS
1
100
33.0
1
1
NIL
HORIZONTAL

SLIDER
1038
49
1218
82
INITIAL-PLANT-SEEDS
INITIAL-PLANT-SEEDS
0
100
50.0
1
1
NIL
HORIZONTAL

SLIDER
1221
48
1417
81
INITIAL-FUNGAL-SPORES
INITIAL-FUNGAL-SPORES
0
100
50.0
1
1
NIL
HORIZONTAL

SLIDER
1420
49
1647
82
OFFSPRING_SIZE_FRAC_DIFF
OFFSPRING_SIZE_FRAC_DIFF
0
1
1.0
0.01
1
NIL
HORIZONTAL

PLOT
1033
336
1355
532
Animal Size Distributions
Size
Count
0.0
40.0
0.0
20.0
true
true
"" "histogram [body-size] of mammals\nhistogram [body-size] of reptiles\n"
PENS
"Mammals" 1.0 1 -8431303 true "" "histogram [body-size] of mammals"
"Reptiles" 1.0 1 -4079321 true "" "histogram [body-size] of reptiles"

PLOT
1362
336
1664
533
Population Counts
Time
Count
0.0
10.0
0.0
10.0
true
true
"" ""
PENS
"Mammals" 1.0 0 -10402772 true "" "plot count mammals"
"Reptiles" 1.0 0 -4079321 true "" "plot count reptiles"
"Infected Reptiles" 1.0 0 -7500403 true "" "plot count reptiles with [infected?]"

PLOT
1032
536
1349
766
Plant & Fungus Biomass
NIL
NIL
0.0
10.0
0.0
10.0
true
true
"" ""
PENS
"Plant" 1.0 0 -13840069 true "" "plot sum [plant-mass] of patches"
"Fungus" 1.0 0 -8630108 true "" "plot sum [fungus-level] of patches"

MONITOR
1331
769
1388
814
Ticks
ticks
17
1
11

MONITOR
1259
769
1328
814
Creatures
count turtles
17
1
11

PLOT
1358
537
1660
767
Resource Consumption
Time
Consumption Count
0.0
10.0
0.0
10.0
true
true
"" ""
PENS
"Meat (Mammals)" 1.0 0 -1604481 true "" "plot meat-consumed-by-mammals"
"Meat (Reptiles)" 1.0 0 -8053223 true "" "plot meat-consumed-by-reptiles"
"Fungus (Mammals)" 1.0 0 -8630108 true "" "plot fungus-consumed-by-mammals"
"Plant (Mammals)" 1.0 0 -13840069 true "" "plot plant-consumed-by-mammals"
"Plant (Reptiles)" 1.0 0 -15575016 true "" "plot plant-consumed-by-reptiles"

SLIDER
1423
123
1595
156
INITIAL-SIZE-FRAC
INITIAL-SIZE-FRAC
0
2
1.1
.01
1
NIL
HORIZONTAL

SLIDER
1035
85
1241
118
FOOD-CONSUMPTION-RATE
FOOD-CONSUMPTION-RATE
1
10
1.0
1
1
NIL
HORIZONTAL

SLIDER
1050
240
1222
273
prey-size-frac-min
prey-size-frac-min
0
1
0.2
0.01
1
NIL
HORIZONTAL

SLIDER
1227
241
1399
274
prey-size-frac-max
prey-size-frac-max
0
1
0.65
0.01
1
NIL
HORIZONTAL

SLIDER
1409
232
1581
265
ROT-CHANCE
ROT-CHANCE
0
1
0.2
0.1
1
NIL
HORIZONTAL

SLIDER
1411
267
1583
300
MEAT-BONUS
MEAT-BONUS
1
5
5.0
1
1
NIL
HORIZONTAL

SLIDER
1043
282
1220
315
FUNGUS-AVOIDANCE
FUNGUS-AVOIDANCE
0
1
0.7
0.01
1
NIL
HORIZONTAL

SLIDER
1230
275
1402
308
chase-duration
chase-duration
0
50
5.0
1
1
NIL
HORIZONTAL

SLIDER
1230
309
1402
342
flee-duration
flee-duration
0
50
17.0
1
1
NIL
HORIZONTAL

SLIDER
1411
304
1583
337
HUNT-COOLDOWN
HUNT-COOLDOWN
0
100
13.0
1
1
NIL
HORIZONTAL

MONITOR
1196
768
1255
813
Reptiles
count reptiles
17
1
11

MONITOR
1126
769
1193
814
Mammals
count mammals
17
1
11

MONITOR
1037
767
1114
812
# Sprinting
count turtles with [ sprint-timer > 0 ]
17
1
11

@#$#@#$#@
WHAT IS IT?  
-----------  
This model was inspired by the PBS Eons Youtube Video, 'Why Wasn't There A Second Age of Reptiles?', which explores how an asteroid impact ended the Age of Reptiles and ushered in the Age of Mammals, despite both mammals and reptiles surviving the catastrophe.  The YouTube Video itself was inspired by papers by Arturo Casadevall and his colleagues.   

This model simulates interactions between mammals, reptiles, plants, fungus, and scavenged meat on a patch grid.  Mammals and reptiles wander, forage, hunt live prey, and reproduce.  Plants and fungus grow and spread, competing for patches, while meat is produced when creatures die and may rot into fungus.  The simulation explores how these agents' behaviors and environmental factors (e.g., light level, growth rates) influence ecosystem dynamics. The overall goal of the model is to explore how resistance to fungal infections (mammals) can help a species thrive even with weaker starting attributes (smaller size, smaller offspring litter sizes, and slower speed) than a species that is vulnerable to fungal infections.

HOW IT WORKS  
------------  
**Agents**  
  - **Mammals** and **Reptiles** ("turtles") each have body size, energy, breeding mode, infection status, and timers (sprint, cooldown, immunity).  
  - **Patches** track plant-mass, fungus-level, meat-level, and meat-age.  

**Movement & Foraging**  
  1. Agents eat food on their patch (meat x fungus chance, fungus for mammals, plants).  
  2. Sprint and cooldown timers govern chase and post-hunt rest.  
  3. Agents avoid fungus (reptiles) and flee larger threats.  
  4. Off-cooldown predators chase nearby prey; if within half predator's size, prey is killed (drops meat).  
  5. Agents detect meat, fungus, or plant patches within PERCEPTION-RADIUS, move toward them, and consume.  
  6. Random wandering when no other behavior applies.

**Reproduction & Infection**  
  - When an agents energy (body-size x tummy-size-factor), it enters breeding mode and seeks a same-breed partner.  
  - Offspring inherit sizes within a range around parents, enforcing MINIMUM-SIZE.  
  - Reptiles may become infected by fungus on their patch and can recover or die from infection.  
  - After predation, predators gain temporary immunity from infection (post-kill-immunity).

**Patch Dynamics**  
  - **Plants** spread randomly outward, replace fungus, and spread to neighbors based on PLANT-GROWTH-RATE x LIGHT-LEVEL.  
  - **Fungus** spreads randomly outward with FUNGAL-GROWTH-RATE x (1 - LIGHT-LEVEL). 
  - **Meat** ages each tick; rot chance ROT-CHANCE converts meat to fungus when depleted.

HOW TO USE IT  
-------------  
1. Adjust sliders and choosers: INITIAL-PLANT-SEEDS, INITIAL-FUNGAL-SPORES, INITIAL-MAMMALS, INITIAL-REPTILES, PLANT-GROWTH-RATE, FUNGAL-GROWTH-RATE, SEED-SPAWN-PERIOD, etc.  
2. Press **SETUP** to initialize the world (also clears the last world).  
3. Press **GO** to run the simulation.  
4. Observe the Monitors for counts of mammals, reptiles, plant-covered patches, fungal patches, and meat.  
5. Watch the Plots for population and resource level dynamics over time.

THINGS TO NOTICE  
----------------  
- How do plant and fungus distributions change with LIGHT-LEVEL?  
- Do populations oscillate in response to prey/resource availability?  
- How does meat rot into fungus and feed back into the system?  

THINGS TO TRY  
-------------  
- Vary PLANT-GROWTH-RATE and FUNGAL-GROWTH-RATE to shift competitive balance.  
- Increase PERCEPTION-RADIUS: does that stabilize or destabilize predator-prey cycles?  
- Is there a LIGHT-LEVEL where both mammals and reptiles have a 50-50 chance of rising to dominance?    
- Experiment with extreme initial size variability by varying INITIAL-SIZE-FRAC: do large initial mammal herds outcompete reptiles?  Do "plagues" of mammals or reptiles take over and deplete all the fungus/plant resources?

EXTENDING THE MODEL  
-------------------  
- Add a water resource and thirst mechanics for agents.  
- Add hunger mechanics and starvation death.
- Implement seasonal light-level changes to vary plant/fungus growth rates and/or a pre-programmed light-level scenario such as a period of darkness after the KT-boundary followed by normal light-dark cycles.  
- Model spatial heterogeneity (e.g., barriers, rivers) affecting movement and spread and potential for hiding/stalking.

CREDITS AND REFERENCES  
----------------------  
Inspired by 'Why Wasn't There A Second Age of Reptiles?' (PBS Eons YouTube video), which explores how an asteroid impact ended the Age of Reptiles and ushered in the Age of Mammals:
https://youtu.be/EPXbSx17030?si=Fyxivy_RZ_QL0p5W

**Scientific Papers:**
Casadevall, A. (2005). Fungal virulence,vertebrate endothermy, and dinosaur extinction: is there a connection? Fungal Genet Biol 42: 98-106, avail. ttps://www.sciencedirect.com/science/article/abs/pii/S1087184504001938?via%3Dihub.

Casadevall, A. (2012). Fungi and the rise of mammals. PLoS Pathog.: 8(8):e1002808.  Avail. https://journals.plos.org/plospathogens/article?id=10.1371/journal.ppat.1002808  
h

Casadevall, A. and Damman, C. (2020). Updating the fungal infection-mammalian selection hypothesis at the end of the Cretaceous Period. PLoS Pathog 16(7): e1008451. Avail: https://pmc.ncbi.nlm.nih.gov/articles/PMC7365386/  


Additional inspiration from a YouTube video by Casadevall:  
https://www.youtube.com/watch?v=eaNcTM-f5y8


HOW TO CITE  
-----------  
If you mention this model or NetLogo in a publication, please include:  
Hoopes, D. (2025). NetLogo KT-Extinction-Survival model. http://ccl.northwestern.edu/netlogo/models/KT-Extinction-Survival. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 
 
Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

COPYRIGHT AND LICENSE
Copyright 1997 Uri Wilensky

COPYRIGHT AND LICENSE  
---------------------  
2025 Desmond Hoopes. CC BY-NC-SA 3.0 License.  
@#$#@#$#@
default
true
0
Polygon -7500403 true true 150 5 40 250 150 205 260 250

airplane
true
0
Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15

arrow
true
0
Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150

box
false
0
Polygon -7500403 true true 150 285 285 225 285 75 150 135
Polygon -7500403 true true 150 135 15 75 150 15 285 75
Polygon -7500403 true true 15 75 15 225 150 285 150 135
Line -16777216 false 150 285 150 135
Line -16777216 false 150 135 15 75
Line -16777216 false 150 135 285 75

bug
true
0
Circle -7500403 true true 96 182 108
Circle -7500403 true true 110 127 80
Circle -7500403 true true 110 75 80
Line -7500403 true 150 100 80 30
Line -7500403 true 150 100 220 30

butterfly
true
0
Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240
Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240
Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163
Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165
Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225
Circle -16777216 true false 135 90 30
Line -16777216 false 150 105 195 60
Line -16777216 false 150 105 105 60

car
false
0
Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180
Circle -16777216 true false 180 180 90
Circle -16777216 true false 30 180 90
Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89
Circle -7500403 true true 47 195 58
Circle -7500403 true true 195 195 58

circle
false
0
Circle -7500403 true true 0 0 300

circle 2
false
0
Circle -7500403 true true 0 0 300
Circle -16777216 true false 30 30 240

cow
false
0
Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167
Polygon -7500403 true true 73 210 86 251 62 249 48 208
Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123

cylinder
false
0
Circle -7500403 true true 0 0 300

dot
false
0
Circle -7500403 true true 90 90 120

face happy
false
0
Circle -7500403 true true 8 8 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240

face neutral
false
0
Circle -7500403 true true 8 7 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Rectangle -16777216 true false 60 195 240 225

face sad
false
0
Circle -7500403 true true 8 8 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183

fish
false
0
Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166
Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165
Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60
Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166
Circle -16777216 true false 215 106 30

flag
false
0
Rectangle -7500403 true true 60 15 75 300
Polygon -7500403 true true 90 150 270 90 90 30
Line -7500403 true 75 135 90 135
Line -7500403 true 75 45 90 45

flower
false
0
Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135
Circle -7500403 true true 85 132 38
Circle -7500403 true true 130 147 38
Circle -7500403 true true 192 85 38
Circle -7500403 true true 85 40 38
Circle -7500403 true true 177 40 38
Circle -7500403 true true 177 132 38
Circle -7500403 true true 70 85 38
Circle -7500403 true true 130 25 38
Circle -7500403 true true 96 51 108
Circle -16777216 true false 113 68 74
Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218
Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240

house
false
0
Rectangle -7500403 true true 45 120 255 285
Rectangle -16777216 true false 120 210 180 285
Polygon -7500403 true true 15 120 150 15 285 120
Line -16777216 false 30 120 270 120

leaf
false
0
Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195
Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195

line
true
0
Line -7500403 true 150 0 150 300

line half
true
0
Line -7500403 true 150 0 150 150

lizard 1
true
1
Rectangle -13840069 true false 135 150 135 165
Rectangle -13840069 true false 135 120 135 150
Circle -13840069 true false 135 135 0
Rectangle -2674135 true true 90 180 90 180
Rectangle -10899396 true false 135 195 75 135
Polygon -13840069 true false 44 203 88 208 110 197 119 181 124 167 140 151 123 125 106 147 84 133 98 136 95 122 104 135 108 119 107 132 127 115 147 145 180 124 170 91 192 63 188 39 196 63 208 53 196 68 211 66 191 72 178 93 187 119 213 103 216 100 232 97 261 113 234 133 208 135 214 155 242 152 254 137 250 149 262 141 250 155 268 157 248 161 256 179 242 162 208 162 201 140 177 164 154 178 176 205 154 208 176 215 154 215 171 233 152 220 151 247 147 211 157 199 164 199 145 182 132 184 119 201 98 214 62 217 28 199 25 187

mammal
true
0
Polygon -7500403 true true 150 30 135 60 135 75 120 90 120 135 120 165 135 180 150 270 165 180 180 165 180 90 165 75 165 60 150 30
Polygon -7500403 true true 180 90 195 90 210 75 225 75 225 90 210 105 180 105
Polygon -7500403 true true 120 90 105 90 90 75 75 75 75 90 90 105 135 105
Polygon -7500403 true true 120 150 105 150 90 165 90 180 105 180 120 165 120 150 120 150 120 150 120 150 120 150
Polygon -7500403 true true 180 150 195 150 210 165 210 180 195 180 180 165

mouse top
true
0
Polygon -7500403 true true 144 238 153 255 168 260 196 257 214 241 237 234 248 243 237 260 199 278 154 282 133 276 109 270 90 273 83 283 98 279 120 282 156 293 200 287 235 273 256 254 261 238 252 226 232 221 211 228 194 238 183 246 168 246 163 232
Polygon -7500403 true true 120 78 116 62 127 35 139 16 150 4 160 16 173 33 183 60 180 80
Polygon -7500403 true true 119 75 179 75 195 105 190 166 193 215 165 240 135 240 106 213 110 165 105 105
Polygon -7500403 true true 167 69 184 68 193 64 199 65 202 74 194 82 185 79 171 80
Polygon -7500403 true true 133 69 116 68 107 64 101 65 98 74 106 82 115 79 129 80
Polygon -16777216 true false 163 28 171 32 173 40 169 45 166 47
Polygon -16777216 true false 137 28 129 32 127 40 131 45 134 47
Polygon -16777216 true false 150 6 143 14 156 14
Line -7500403 true 161 17 195 10
Line -7500403 true 160 22 187 20
Line -7500403 true 160 22 201 31
Line -7500403 true 140 22 99 31
Line -7500403 true 140 22 113 20
Line -7500403 true 139 17 105 10

pentagon
false
0
Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120

person
false
0
Circle -7500403 true true 110 5 80
Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90
Rectangle -7500403 true true 127 79 172 94
Polygon -7500403 true true 195 90 240 150 225 180 165 105
Polygon -7500403 true true 105 90 60 150 75 180 135 105

plant
false
0
Rectangle -7500403 true true 135 90 165 300
Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285
Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285
Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210
Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135
Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135
Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60
Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90

reptile
true
0
Polygon -7500403 true true 150 45 135 75 135 90 120 105 120 165 150 255 180 165 180 105 165 90 165 75
Polygon -7500403 true true 180 105 195 105 210 90 225 90 225 105 210 120 180 120 180 105
Polygon -7500403 true true 120 105 105 105 90 90 75 90 75 105 90 120 120 120 120 105 120 105
Polygon -7500403 true true 120 150 90 150 75 165 75 180 90 180 105 165 120 165
Polygon -7500403 true true 180 150 210 150 225 165 225 180 210 180 195 165 180 165 180 150 180 150 180 150

sheep
false
15
Circle -1 true true 203 65 88
Circle -1 true true 70 65 162
Circle -1 true true 150 105 120
Polygon -7500403 true false 218 120 240 165 255 165 278 120
Circle -7500403 true false 214 72 67
Rectangle -1 true true 164 223 179 298
Polygon -1 true true 45 285 30 285 30 240 15 195 45 210
Circle -1 true true 3 83 150
Rectangle -1 true true 65 221 80 296
Polygon -1 true true 195 285 210 285 210 240 240 210 195 210
Polygon -7500403 true false 276 85 285 105 302 99 294 83
Polygon -7500403 true false 219 85 210 105 193 99 201 83

square
false
0
Rectangle -7500403 true true 30 30 270 270

square 2
false
0
Rectangle -7500403 true true 30 30 270 270
Rectangle -16777216 true false 60 60 240 240

star
false
0
Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108

target
false
0
Circle -7500403 true true 0 0 300
Circle -16777216 true false 30 30 240
Circle -7500403 true true 60 60 180
Circle -16777216 true false 90 90 120
Circle -7500403 true true 120 120 60

tree
false
0
Circle -7500403 true true 118 3 94
Rectangle -6459832 true false 120 195 180 300
Circle -7500403 true true 65 21 108
Circle -7500403 true true 116 41 127
Circle -7500403 true true 45 90 120
Circle -7500403 true true 104 74 152

triangle
false
0
Polygon -7500403 true true 150 30 15 255 285 255

triangle 2
false
0
Polygon -7500403 true true 150 30 15 255 285 255
Polygon -16777216 true false 151 99 225 223 75 224

truck
false
0
Rectangle -7500403 true true 4 45 195 187
Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194
Rectangle -1 true false 195 60 195 105
Polygon -16777216 true false 238 112 252 141 219 141 218 112
Circle -16777216 true false 234 174 42
Rectangle -7500403 true true 181 185 214 194
Circle -16777216 true false 144 174 42
Circle -16777216 true false 24 174 42
Circle -7500403 false true 24 174 42
Circle -7500403 false true 144 174 42
Circle -7500403 false true 234 174 42

turtle
true
0
Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210
Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105
Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105
Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87
Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210
Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99

wheel
false
0
Circle -7500403 true true 3 3 294
Circle -16777216 true false 30 30 240
Line -7500403 true 150 285 150 15
Line -7500403 true 15 150 285 150
Circle -7500403 true true 120 120 60
Line -7500403 true 216 40 79 269
Line -7500403 true 40 84 269 221
Line -7500403 true 40 216 269 79
Line -7500403 true 84 40 221 269

wolf
false
0
Polygon -16777216 true false 253 133 245 131 245 133
Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105
Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113

x
false
0
Polygon -7500403 true true 270 75 225 30 30 225 75 270
Polygon -7500403 true true 30 75 75 30 270 225 225 270
@#$#@#$#@
NetLogo 6.4.0
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
default
0.0
-0.2 0 0.0 1.0
0.0 1 1.0 0.0
0.2 0 0.0 1.0
link direction
true
0
Line -7500403 true 150 150 90 180
Line -7500403 true 150 150 210 180
@#$#@#$#@
0
@#$#@#$#@