Gorilla versus Man
Model was written in NetLogo 6.4.0
•
Viewed 23 times
•
Downloaded 3 times
•
Run 0 times
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
globals [ the-gorilla gorilla-hp] breed [ gorillas gorilla ] breed [ humans human ] humans-own [ coward? ] ;; New turtle variable to track cowardice to setup clear-all clear-all-plots set gorilla-hp 50 ;; Initial hit points for the gorilla ;;set initial-human-count 100 ;; Store the initial number of humans create-gorillas 1 [ setxy 0 (max-pycor - 5) set size 3 set shape "gorilla" set color green set the-gorilla self ] create-humans initial-human-count [ set xcor random-xcor let bottom-boundary (min-pycor + (world-height * 0.25)) let top-boundary min-pycor set ycor random-float (bottom-boundary - top-boundary) + top-boundary set size 1.5 set shape "person" set color blue set coward? false ;; Initially, all humans are brave (or at least not cowardly) ] reset-ticks end to go if gorilla-hp <= 0 [ ask the-gorilla [ set color red ] stop ] move-gorilla ;; Humans' behavior ask humans with [color != red] [ if coward? [ flee-from-gorilla ] if not coward? [ approach-gorilla ] ] ;; Combat check ask humans with [not coward? and color != red] [ if distance the-gorilla < 1 [ set gorilla-hp gorilla-hp - 1 trigger-cowardice set color red set coward? true ;; prevent further movement ] ] ;; Update plot set-current-plot "Simulation Stats" set-current-plot-pen "Gorilla HP" plot gorilla-hp set-current-plot-pen "Casualties" plot count humans with [color = red] set-current-plot-pen "Cowards" plot count humans with [color = grey] tick end to approach-gorilla let speed random-float 0.2 + 0.2 ;; random between 0.2 and 0.4 face the-gorilla fd speed end to flee-from-gorilla face the-gorilla rt 180 fd 0.3 end to trigger-cowardice ask humans with [not coward? and distance myself < 5] [ let dist distance myself ;;let coward-chance (0.2 - (dist / 10)) ;; closer = more likely let max-cowardice (0.1 + (cowardice-slider / 100) * 0.2) ;; maps 0–100 to 0.1–0.3 let coward-chance max (list 0 (max-cowardice - (dist / 10))) ;; never go below 0 if random-float 1 < coward-chance [ set coward? true set color gray ] ] end to move-gorilla ask the-gorilla [ ;; Occasionally jump (~5% chance) if random-float 1 < 0.05 [ jump-randomly ] ;; Otherwise, small random walk rt random 60 - 35 fd 0.3 ;; Stay within top 25% vertical range let y-limit max-pycor let lower-bound max-pycor - (world-height * 0.25) if ycor < lower-bound [ set ycor lower-bound + 1 ] if ycor > y-limit [ set ycor y-limit - 1 ] ;; Stay within horizontal bounds if xcor > max-pxcor [ set xcor max-pxcor - 1 ] if xcor < min-pxcor [ set xcor min-pxcor + 1 ] ] end to jump-randomly rt random 360 fd 0.2 ;; jump distance end to-report live-humans report count humans end to-report dead-humans report count humans with [color = red] end to-report coward-humans report count humans with [color = grey] end
There is only one version of this model, created 19 days ago by Avrian Pradiptya.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Gorilla versus Man.png | preview | Preview for 'Gorilla versus Man' | 19 days ago, by Avrian Pradiptya | Download |
This model does not have any ancestors.
This model does not have any descendants.