Final

Final preview image

1 collaborator

Default-person Yun Zhou (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 372 times • Downloaded 38 times • Run 0 times
Download the 'Final' 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 [fishes fish]
breed [predators predator]
breed [boats boat]
breed [detritus detritu]

turtles-own [ age  flockmates  nearest-neighbor energy]
patches-own [plankton polution ]
globals [ timenum]

to draw-island              ;; draw island
  if mouse-down?     ;; reports true or false to indicate whether mouse button is down
    [
      ;; mouse-xcor and mouse-ycor report the position of the mouse --
      ;; note that they report the precise position of the mouse,
      ;; so you might get a decimal number like 12.3, but "patch"
      ;; automatically rounds to the nearest patch
      ask patch mouse-xcor mouse-ycor
        [ set pcolor red ]
    ]
end 

to draw-source        ;;draw the source of reproduce
  if mouse-down?     ;; reports true or false to indicate whether mouse button is down
    [
      ;; mouse-xcor and mouse-ycor report the position of the mouse --
      ;; note that they report the precise position of the mouse,
      ;; so you might get a decimal number like 12.3, but "patch"
      ;; automatically rounds to the nearest patch
      ask patch mouse-xcor mouse-ycor
        [ set pcolor pink ]
    ]
end 

to draw-polution      ;; draw the pollution area
  if mouse-down?     ;; reports true or false to indicate whether mouse button is down
    [
      ;; mouse-xcor and mouse-ycor report the position of the mouse --
      ;; note that they report the precise position of the mouse,
      ;; so you might get a decimal number like 12.3, but "patch"
      ;; automatically rounds to the nearest patch
      ask patch mouse-xcor mouse-ycor
        [ set pcolor grey ]
    ]
end 

to setup
  clear-all
  ask patches  [                 ;;set up the planktons
    set pcolor blue
    set plankton random sea-regrow-time
    set pcolor one-of [green blue]
  ]
end 

to create
  
  create-fishes number-of-fish [           ;;create certain numbers of forage fishes
    setxy random-xcor random-ycor
    set color red
    set shape "fish"  
    set age random 3
    set energy random random (2 * fish-gain-from-food)
    let x 0
    let y 0
    ask one-of patches with [pcolor != red]
    [
      set x pxcor
      set y pycor
    ]
    setxy x y
  ]
  
  

  
  create-predators number-of-predator [          ;;create certain numbers of predators
    setxy random-xcor random-ycor 
    set color yellow
    set shape "shark"
    set age random 5
    set energy random  (2 * predator-gain-from-food)
    set size 1.5 ;; increase their size so they are a little easier to see
    let x 0
    let y 0
    ask one-of patches with [pcolor != red]
    [
      set x pxcor
      set y pycor
    ]
    setxy x y
  ]
  if human-involoved?                       ;;if human being involved, create certain numbers of boats
  [ create-boats boats-number [  
    let x 0
    let y 0
    ask one-of patches with [pcolor != red]
    [
      set x pxcor
      set y pycor
    ]
    setxy x y
    set color white
    set shape "boat"  
    set size 2
  ]]
  
  reset-ticks
end 

to go
 
  if not any? turtles [  
    stop
  ]
  
  ask fishes [
    ifelse flock? [                     ;; check if the forage fishes would go in the pattern as a flock
      flock
      avoid                          ;;forage fishes would escape if there is any predators around
     ; move
      ; fd 1
      ;   set age age + 1
      set energy energy - 1
      
    ]
    [ avoid
      
      ;move
      
      ; set age age + 1
      set energy energy - 1
    ]
    eat-plankton         ;;eat food and gain energy
    check-fish-dead       ;;check if the forage is dead or not
    
    fish-reproduce        ;;fish reproduce 
    
  ]
  

  
  
  ask predators [                  ;; ask predators to eat forage fishes and gain energy
    
    
    eat-fish
    
    
    set energy energy - 1
    check-if-dead
    set age age + 1
    predator-reproduce          ;;predator reproduce
  ]
  
  
  if human-involoved?
  [
    ask boats [
      move
      
      fishing           ;;human go fishing
    ]
  ]
  
  regrow-plankton        ;; regrow the plankton
  
  
  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 ]        ;;if there is any predators around
  ifelse any? candidates
    [ face one-of candidates ]
    [ 
      let wall? false                              ;; check if there are walls ahead
      ask patch-ahead 1[
        if(pcolor = red)
        [
          set wall? true
        ]
      ] 
      ifelse (wall?)
      [
        rt random 360                              ;;if there are walls between walls between predators and fishes, random move
        move
      ]
      
      [ rt (random 3) * 90 
        
        ask patch-ahead 1[                 ;;else random pick a direction and escape
          if(pcolor = red)
          [
            set wall? true
          ]
        ] 
        ifelse (wall?)                       
        [
          avoid
          
        ]
        [forward 1  ]]]                  ;;if there are no predators around, move.
end 

to chase                    ;;let predators chase after forage fishes for food
  ifelse any? fishes in-radius 2
    [ let candidates one-of fishes in-radius 2
      let wall? false                 ;;if there are forage fishes nearby
      ask patch-ahead 1[
        if(pcolor = red)
        [
          set wall? true                ;;check if there are walls between them
        ]
      ] 
      ifelse (wall?)
      [
        rt random 360       ;;if there are walls, random move
        move
      ]
      
      [
        face candidates           ;;if there are no walls, face the forage fish and move
        set energy energy - 1
        fd 1
      ]   
      
    ]
  
    [ if random 100 < predator-fight-percent          ;;if there are no forage fishes around, they might fight for their space
      [fight ] ]
end 

to polution-on
;  ifelse ticks != nobody
 ; [set timenum ticks]
  ;[set timenum 0]
  set timenum ticks
  let polution-factor random 10
  ask patches with [pcolor = grey]
  [ set polution polution-factor
    ]
end 

to self-restore                         ;;self restore the pollution emitted into the ocean
  clean
  tick
end 

to clean                             ;;check if it has passed enough time to let ocean clean the pollution
  let now ticks
  if now = timenum + 3000
  [
    ask patches with [pcolor = grey]
    [set pcolor blue]]
end 

to fight                                  ;; predators fight each other when there are not enough food around for their place
  ifelse any? predators in-radius 1
  
  [let candidates one-of predators in-radius 1  
    set energy energy - 4
    face candidates
    let walls patches in-radius 1 with [pcolor = red]
    ifelse any? walls                  
    [
      move]
    [forward 1  ]
    ask candidates [ die ]                  ;;one of the predators would die in this fight and the other one would loose a lot of energy also
    
  ]
  [ move
    set energy energy - 2]
end 

to eat-plankton                         ;;forage fishes eat plankton
  if ( pcolor = green) [
    set pcolor blue         
    set energy energy + fish-gain-from-food
  ] 
end 

to eat-fish                           ;;predators eat forage fishes
  ifelse any? fishes in-radius 1 [ 
    ask fishes in-radius 1 [     
      die
    ]
    set energy energy + predator-gain-from-food
  ]
  
  [ 
    if chase?                    ;;if there are no food around, look further and chase
    [chase]]
end 

to fishing                       ;;human go fishing
  if random 100 < 70
    [
      ifelse prefer-big? [             ;;if human are prefer fishing the predators, they would catch one predator rather than all the nearby fishes
        ifelse any? predators-here [
          let target one-of predators
          ask target [
            die
          ]]
        [ ask fishes in-radius 3 [
          die
        ]
        ]
      ]
      
      [ ask fishes in-radius 2 [
        die]
      
      ]]
end 

to fish-reproduce
  ifelse produce-source?                  ;;let fish reproduce. If there required a reproduce source, make the forage fishes can only reproduce at certain place
  [
    let location false                  ;;so every time fish want to reproduce, they have to move towards those sources
    ask patch-here[
      if  pcolor = pink                 ;;and hatch their childeren out side the walls
      [ set location true
      ]]
    
    ifelse location != false
      [  
        if random 100 < fish-reproduce-percent [
          set energy (energy / 2)
          move
          move
          hatch fish-hatch-number [
            hatch 1  [ 
              rt random-float 360 
              let wall? false
              ask patch-ahead 1[
                if(pcolor = red)
                [
                  set wall? true
                ]
              ] 
              ifelse (wall?)
              [
                rt random 360
                move
              ]
              [ fd 1]]]
          
        ]]
      [ 
        
        trace-back ]]            ;;the moving towards sources procedure
  [  if random 100 < fish-reproduce-percent [        ;;otherwise, just normal reproduce. Can happen at any place
    
    set energy (energy / 2)
    hatch fish-hatch-number [
      hatch 1  [ 
        rt random-float 360 
        let wall? false
        ask patch-ahead 1[
          if(pcolor = red)
          [
            set wall? true
          ]
        ] 
        ifelse (wall?)
        [
          rt random 360
          move
        ]
        
        [forward 1  ] ] ]
    
    
  ]
  ]
end 

to trace-back
  let x 0                   ;;find the way back to the sources and reproduce
  let y 0
  let candidates one-of patches with [pcolor = pink]
  if candidates != nobody
    [ ask one-of patches with [pcolor = pink]
      [
        set x pxcor
        set y pycor
      ]
    facexy x y
    let wall? false
    ask patch-ahead 1[
      if(pcolor = red)
        [
          set wall? true
        ] 
    ] 
    ifelse (wall?)
      [
        rt random 360          ;;if there are walls on them way, they would try to find another path
        move
      ]
      [ fd 1]]
end 

to predator-reproduce              ;;predators' reproduce, the same with the normal forage fishes' reproduce
  if random 100 < predator-reproduce-percent and energy > 60[
    set energy (energy / 2)
    hatch 1  [ 
      rt random-float 360 
      let wall? false
      ask patch-ahead 1[
        if(pcolor = red)
        [
          set wall? true
        ]
      ] 
      ifelse (wall?)
      [
        rt random 360
        move
      ]
      
      [forward 1  ] ] 
    
  ]
end 

to check-if-dead          ;;check whether the predators are dead
  if energy < 5 and age > 10[
    if random 100 < 62
    [
      
      die
      ;ask detritus [hatch 2]
    ]
  ]
end 

to check-fish-dead     ;; check whether the forage fishes are dead
  if energy < 1 [
    die
  ]
end 

to regrow-plankton      ;;regrow the planktons after certain amount of time and possibilities
  ask patches with [ pcolor = blue][
    if  random 100 < sea-regrow-time
      [ set pcolor green
        set plankton sea-regrow-time]]
  
  ask patches with [pcolor = green]   [set plankton plankton - 1]
end 

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

to boat-move        ;;let boats moving around without hitting the walls
  rt random 360
  let wall? false
  ask patch-ahead 1[
    if(pcolor = red)
    [
      set wall? true
    ]
  ] 
  ifelse (wall?)
  [
    rt random 360
    move
  ]
  
  [forward 1  ]
end 

to move            ;;let turtles moving without hitting the walls
  rt random 360
  
  let wall? false
  ask patch-ahead 1[
    if(pcolor = red)
    [
      set wall? true
    ]
  ] 
  ifelse (wall?)
  [
    rt random 360
    move
  ]
  
  [forward 1  ]
end 

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

Attached files

File Type Description Last updated
Additional model.nlogo extension addition model over 11 years ago, by Yun Zhou Download
EECS 472 Final Project Progress Report.pdf pdf process report1 over 11 years ago, by Yun Zhou Download
EECS 472 Final Project Progress Report2.pdf pdf process report2 over 11 years ago, by Yun Zhou Download
EECS 472 Final Project Progress Report3.pdf pdf process report3 over 11 years ago, by Yun Zhou Download
EECS 472 Final Project Progress Report4.pdf pdf process report4 over 11 years ago, by Yun Zhou Download
Final Paper.pdf pdf final paper over 11 years ago, by Yun Zhou Download
Final.png preview Preview for 'Final' over 11 years ago, by Yun Zhou Download
HubNet.nlogo extension hubnet over 11 years ago, by Yun Zhou Download
present.pptx powerpoint present slides over 11 years ago, by Yun Zhou Download
User Guide.pdf pdf user guide over 11 years ago, by Yun Zhou Download

This model does not have any ancestors.

This model does not have any descendants.