Halo Grazing

Halo Grazing preview image

1 collaborator

Default-person Wade Berger (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.4 • Viewed 103 times • Downloaded 15 times • Run 0 times
Download the 'Halo Grazing' 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

breed [ fish a-fish]
breed [ predators a-predator]
breed [ reefs a-reef]
breed [ seagrass a-grass]

fish-own [
  energy
  carried-seagrass
  found-reef?
]

seagrass-own [
  count-down
]

patches-own [
  reef?
  reef-scent
]

Globals
[
  home-base                                ;; xxx location for fish and for need to figure out how to code this
  seagrass-amount                          ;; amount of grass to start out with
]

;=============== Content ===============================================================================================================
; 1. Setup
; 2. Go
; 3. Rules
; 4. Extra Code


;;                                        ================ 1. Setup =======================

to setup
  clear-all
  reset-ticks
  set seagrass-amount starting-seagrass-coverage
  set-default-shape fish "fish 3"
  set-default-shape seagrass "plant"
  set-default-shape reefs "reef1"
  set-default-shape predators "fish"
  set-up-seagrass
  Create-sand
  generate-fish
  generate-predators
end 

to set-up-seagrass
  ;; create seagrass turtles at random locations
  create-seagrass seagrass-amount
  ask seagrass [
    setxy random-xcor random-ycor
  ]
end 

to create-sand
  ask patches [
    if pcolor = black  [set pcolor 49]
  ]  ; patches not green or reef, sandy color
end 

to Generate-fish
 create-fish starting-num-fish ; from the slider
 ask fish [
    setxy 0 0 ; xxx would change with home-base
    set size 3
    set energy .5
  ]
end 

to Generate-predators
 create-predators num-predators
 ask predators [
    setxy random-xcor random-ycor
    set size 4
  ]
  ask seagrass [
    if any? predators-on neighbors
    [ die ]
  ]
end 


;;                                        ================ 2. GO =========================

to go
  if not any? fish [stop ]
  if not any? reefs [ stop ]
  if not any? seagrass [stop ]
  ask fish [
    if 2 >= ticks [ stop ]
    fish-eat-food
    wiggle
    fd 1
  ]
  ask predators [
    wiggle
    predator-walk
    Predators-eat-fish
  ]
  tick
  ask fish [ regrow-fish ]
  ask seagrass [ regrow-seagrass ]
  tick
end 


; to create-reef-with-mouse ----------------------------xxx would set xcor and ycor as home base Not working, revisit later
; if mouse-down? [
;   ask patch mouse-xcor mouse-ycor [
;      set pcolor grey
;    ]
;    display
;  ]
; End

to seed-one
  ;; tell the center to be a reef
   if any? reefs [ stop ]
  ask patch 0 0 [
    set pcolor grey
  ]
  create-reefs 1 [
    setxy 0 0 ; xxx would be xcor and ycor of reef from mouse click
    set shape "reef1"
    set size 15
    ask neighbors [ set pcolor grey ]
  ]
  ; set reef? variable to true inside the reef, false elsewhere
  ask patches [
    set reef? (distancexy 0 0) < 5 ; xxx would use xcor, ycor of mouse click
   ;; spread a reef-scent over the whole world -- stronger nearer the reef
    set reef-scent 200 - distancexy 0 0
  ]
  ask reefs [
    ask seagrass in-radius 3 [ die ]
  ]
end 



;;                                             =============== 3. Rules ===================
;----------------fish------------

to fish-eat-food
  ;energy levels 0 = die, .5 = seek food 1 = found food, now return to reef
    if energy <= 0 [ die ]
    ifelse energy = .5
    [ search-for-seagrass ]
    [ go-to-home-base ]
end 

to search-for-seagrass
  ;; fish procedure to seek out new food
  ask fish [
  let yum one-of seagrass-here
  if yum != nobody [
    ask yum [ die ]
  set energy energy + .5
    ]
  ]
end 

to go-to-home-base
  ; fish procedure for returning to the reef, combines with uphill-reef-scent and reef-scent-at-angle
  ifelse reef?
  [set energy .5]
  [ uphill-reef-scent ]
end 

to uphill-reef-scent
  let scent-ahead reef-scent-at-angle 0
  let scent-right reef-scent-at-angle 45
  let scent-left reef-scent-at-angle -45
  if (scent-right > scent-ahead) or (scent-left > scent-ahead)
  [ ifelse scent-right > scent-left
    [ rt 45 ]
    [ lt 45 ]
  ]
end 

to-report reef-scent-at-angle [angle]
  ;feeds into uphill-reef-scent
  let p patch-right-and-ahead angle 1
  if p = nobody [ report 0 ]
  report [ reef-scent ] of p
end 

;---------------predators----------

to predators-eat-fish
  ; predators contact fish and the fish lose enough energy to die, connected to fish-eat-food
  let prey one-of fish-here
  if prey != nobody [
    ask prey [ set energy energy - 1 ]
  ]
end 


;                                             ================ 4. Extra Code =======================

to regrow-seagrass
  ; xxx need to figure out the scale of this amount
    if count seagrass <= 5000
  [ hatch-seagrass 1000 * seagrass-regrowth-rate [ setxy random-xcor random-ycor ] ; xxx would love to have this outgrow the eating rate
  ]
end 

to regrow-fish
;; new fish, use same code from regrow-seagrass
  let num-fish count fish
  if num-fish <= 1
  [ hatch-fish seagrass-amount / 5000 [ setxy random-xcor random-ycor ] ; xxx
  ]
end 

to predator-walk
  ;; look for reefs, and rotate to head away from them
  ifelse not any? reefs-on patch-ahead 1
  [ fd 1 ]
  [ wiggle predator-walk ]
end 

to wiggle
  ;; fish and predator change heading procedure
  rt random 50 - random 50
end 

There is only one version of this model, created almost 6 years ago by Wade Berger.

Attached files

File Type Description Last updated
Halo Grazing.png preview Preview for 'Halo Grazing' almost 6 years ago, by Wade Berger Download

This model does not have any ancestors.

This model does not have any descendants.