FinalProcess3

No 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 127 times • Downloaded 17 times • Run 0 times
Download the 'FinalProcess3' 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

What should I upload for the Hubnet clients? (Question)

Is the HTML file produced by the project should be uploaded?

Posted almost 11 years ago

HTML?

I'm not sure what HTML file you're talking about? I think the answer is no, but I'm not sure, where did the HTML file come from? did you generate it? what is it called?

Posted almost 11 years ago

Click to Run Model

globals
[
  shape-names        ;; list that holds the names of the non-sick shapes a student's turtle can have
  colorsl             ;; list that holds the colors used for students' turtles
  color-names        ;; list that holds the names of the colors used for students' turtles
  used-shape-colors  ;; list that holds the shape-color pairs that are already being used
  max-possible-codes ;; total number of possible unique shape/color combinations
                            ;; number of turtles that had infected? = true the last time we plotted.
]
breed [fishes fish]
breed [predators predator]
breed [boats boat]
breed [detritus detritu]

boats-own
[
  user-id
  step-size
  base-shape 
]


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

to startup
  hubnet-reset

   reset-ticks
end 

to setup
  clear-all
  clear-drawing
  clear-patches
  ask patches [  
    set seagrass random-float 10.0
    set pcolor scale-color blue seagrass 0 20
  ]
  
  ask turtles
  [
    set step-size 1
    hubnet-send user-id "step-size" step-size
  ]
  
  create-fishes number-of-fish [  
    setxy random-xcor random-ycor
    set color red
    set shape "fish"  
    set age random 3
    set energy random 20
  ]
  
  create-detritus 50 [  
    setxy random-xcor random-ycor
    set color green
    set shape "molecule hydrogen"    
    set energy random 10
  ]
  
  create-predators number-of-predator [ 
    setxy random-xcor random-ycor
    set color yellow
    set shape "shark"
    set age random 5
    set energy random 60
    set size 2 ;; increase their size so they are a little easier to see
  ]
 if human-involoved?
   [ ask boats[
      set shape base-shape
    ]]
;  [ 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
      set energy energy - 1
      
    ]
    [ avoid
      fd 1
      set age age + 1
      set energy energy - 2
    ]
    check-fish-dead
    eat-what
    fish-reproduce
  ]
  
  ask detritus[
    move
  ]
  
  
  ask predators [
    chase
    eat-fish
    predator-reproduce
    check-if-dead
    set age age + 1
  ]
  
  
  ifelse human-involoved?
  [
    listen-clients
    every 0.1
    [
      tick
    ]
;;    ask boats [
;;      move
;;      
;;      fishing
;;    ]
    regrow-seagrass
    my-update-plots
  ]
    
  [ regrow-seagrass
    tick  
    my-update-plots]
end 

;;
;; HubNet Procedures
;;

to listen-clients
  while [hubnet-message-waiting?]
  [
    hubnet-fetch-message
    ifelse hubnet-enter-message?
    [ create-new-boat ]
    [
      ifelse hubnet-exit-message?
      [ remove-boat ]
      [ ask boats with [user-id = hubnet-message-source]
        [ execute-command hubnet-message-tag ]
      ]
    ]
  ]
end 

to create-new-boat
  create-boats 1
  [
    set user-id hubnet-message-source
     set-unique-shape-and-color
    set label user-id
    set step-size 1
    pen-down
    send-info-to-clients
    set-plot-y-range plot-y-min plot-y-max
    set-plot-x-range plot-x-min plot-x-max
  ]
end 

to set-unique-shape-and-color
  
  set colorsl      (list white brown green yellow
                        (violet + 1) (sky + 1))
  set shape "boat"
  set size 2
  set color one-of colorsl
end 

to remove-boat
  ask boats with [user-id = hubnet-message-source]
  [ die ]
end 

to execute-command [command]
  if command = "step-size"
  [
    set step-size hubnet-message
    stop
  ]
  if command = "up"
  [ execute-move 0
    fishing
     stop 
    ]
  if command = "down"
  [ execute-move 180 
    fishing
    stop ]
  if command = "right"
  [ execute-move 90 
    fishing
    stop ]
  if command = "left"
  [ execute-move 270 
    fishing
    stop ]
end 

to send-info-to-clients ;; turtle procedure
  hubnet-send user-id "location" (word "(" pxcor "," pycor ")")
end 

to execute-move [new-heading]
  set heading new-heading
  fd step-size
  send-info-to-clients
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
      set energy energy - 3]
    [ if random 100 < predator-fight-percent
      [fight ]]
end 

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

to eat-what
  ifelse any? detritus-here
  [ let candidates one-of detritus 
    set energy energy + 2
    ask candidates [ die ]
  ]
  [
    eat-seagrass
  ]
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
    ]
    set energy energy + 10
  ]
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  set energy random 10]
      
      die
      ask detritus [hatch 1]
    ]
  ]
end 

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

to check-if-dead
  if age > 8 or energy < 1 [
    die
    ask detritus [hatch 2]
  ]
end 

to check-fish-dead
  if energy < 1 [
    die
    ask detritus [hatch 1]
  ]
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 Report3.pdf pdf Final project3 almost 11 years ago, by Yun Zhou Download

This model does not have any ancestors.

This model does not have any descendants.