YunZhou_FinalProjectProcess1

No preview image

1 collaborator

Default-person Yun Zhou (Author)

Tags

eecs472 

Tagged by Yun Zhou almost 11 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 119 times • Downloaded 5 times • Run 0 times
Download the 'YunZhou_FinalProjectProcess1' 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

breed [fishes fish]
breed [predators predator]
breed [boats boat]

turtles-own [ age  flockmates  nearest-neighbor]
patches-own [seagrass]

to setup
  clear-all
  ask patches [  
    set seagrass random-float 10.0
    set pcolor scale-color blue seagrass 0 20
  ]
  
  create-fishes number-of-fish [  
    setxy random-xcor random-ycor
    set color red
    set shape "fish"  
    set age random 3
  ]
  create-predators number-of-predator [ 
    setxy random-xcor random-ycor
    set color yellow
    set shape "shark"
    set age random 5
    set size 2 ;; increase their size so they are a little easier to see
  ]
  if human-involoved?
  [ create-boats 10 [  
    setxy random-xcor random-ycor
    set color white
    set shape "boat"  
    set size 2
  ]]
  reset-ticks
end 

to go
  if not any? turtles [  
    stop
  ]
  
  ask fishes [
    ifelse flock? [
      flock
      ;; avoid
      fd 1
      set age age + 1
    ]
    [ avoid
      fd 1
      set age age + 1
    ]
    eat-seagrass
    fish-reproduce
  ]
  
   
  ask predators [
    chase
    eat-fish
    predator-reproduce
    check-if-dead
    set age age + 1
  ]
  
  
  if human-involoved?
  [
    ask boats [
      move
      
      fishing
    ]
  ]
  
  regrow-seagrass
  tick  
  my-update-plots
end 

to flock  ;; turtle procedure
  find-flockmates
  if any? flockmates
    [ find-nearest-neighbor
      ifelse distance nearest-neighbor < 0.75
        [ separate ]
        [ align
          cohere ] ]
end 

to find-flockmates  ;; turtle procedure
  set flockmates other turtles in-radius 3
end 

to find-nearest-neighbor ;; turtle procedure
  set nearest-neighbor min-one-of flockmates [distance myself]
end 

to separate  ;; turtle procedure
  turn-away ([heading] of nearest-neighbor) 3.50
end 

to align  ;; turtle procedure
  turn-towards average-flockmate-heading 5
end 

to cohere  ;; turtle procedure
  turn-towards average-heading-towards-flockmates 5.75
end 

to turn-towards [new-heading max-turn]  ;; turtle procedure
  turn-at-most (subtract-headings new-heading heading) max-turn
end 

to turn-away [new-heading max-turn]  ;; turtle procedure
  turn-at-most (subtract-headings heading new-heading) max-turn
end 

to turn-at-most [turn max-turn]  ;; turtle procedure
  ifelse abs turn > max-turn
    [ ifelse turn > 0
      [ rt max-turn ]
      [ lt max-turn ] ]
    [ rt turn ]
end 

to-report average-flockmate-heading  ;; turtle procedure
                                     ;; We can't just average the heading variables here.
                                     ;; For example, the average of 1 and 359 should be 0,
                                     ;; not 180.  So we have to use trigonometry.
  let x-component sum [dx] of flockmates
  let y-component sum [dy] of flockmates
  ifelse x-component = 0 and y-component = 0
    [ report heading ]
    [ report atan x-component y-component ]
end 

to-report average-heading-towards-flockmates  ;; turtle procedure
                                              ;; "towards myself" gives us the heading from the other turtle
                                              ;; to me, but we want the heading from me to the other turtle,
                                              ;; so we add 180
  let x-component mean [sin (towards myself + 180)] of flockmates
  let y-component mean [cos (towards myself + 180)] of flockmates
  ifelse x-component = 0 and y-component = 0
    [ report heading ]
    [ report atan x-component y-component ]
end 

to avoid ;; android procedure
  let candidates patches in-radius 1 with [ not any? predators ]
  ifelse any? candidates
    [ face one-of candidates ]
    [ rt (random 4) * 90 ]
end 

to chase 
  ifelse any? fishes in-radius 3
    [ let candidates one-of fishes in-radius 3
      
      face candidates 
      fd ratio-speed-fishwolves]
    [ if random 100 < predator-fight-percent
      [fight ]]
end 

to fight
  ifelse any? predators in-radius 1
  
  [let candidates one-of predators in-radius 1  
    face candidates
    fd 1
    ask candidates [ die ]
  ]
  [ rt (random 4) * 90 
    fd 1]
end 

to eat-seagrass
  if ( seagrass >= 1) [
    set seagrass seagrass - 1
    set pcolor scale-color blue seagrass 0 20
  ] 
end 

to eat-fish
  if any? fishes in-radius 2 [ 
    ask fishes in-radius 2 [     
      die
    ]
  ]
end 

to fishing
  if random 100 < 70
    [
      ifelse any? predators-here [
        let target one-of predators
        ask target [
          die
        ]]
      [ ask fishes in-radius 3 [
        die
      ]
      ]
    ]
end 

to fish-reproduce
  if random 100 < fish-reproduce-percent [
    if age > 3 [
      hatch fish-hatch-number [ set age 0]
      
      die
    ]
  ]
end 

to predator-reproduce
  if random 100 < predator-reproduce-percent [
    hatch 1 [ set age 0]
  ]
end 

to check-if-dead
  if age > 8 [
    die
  ]
end 

to regrow-seagrass
  ask patches [
    set seagrass seagrass + 0.1
    if seagrass > 10 [
      set seagrass 10
    ]
    set pcolor scale-color blue seagrass 0 20
  ]
end 

to my-update-plots
  set-current-plot-pen "fish"
  plot count fishes
  set-current-plot-pen "shark"
  plot count predators * 10 ;; scaling factor so plot looks nice
  set-current-plot-pen "seagrass"
  plot sum [seagrass] of patches / 50 ;; scaling factor so plot looks nice end
end 

to boat-move
  rt random 360
  forward 2
end 

to move
  rt random 360
  forward 1  
end 

There is only one version of this model, created almost 11 years ago by Yun Zhou.

Attached files

File Type Description Last updated
EECS 472 Final Project Progress Report.pdf pdf Report almost 11 years ago, by Yun Zhou Download

This model does not have any ancestors.

This model does not have any descendants.