turkey-hunter_2009


Information

Created with NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.


WHAT IS IT?


-------
A silly simulation themed for the American "Thanksgiving" holiday.
A "pilgrim" man stalks the woods hunting for wild turkeys.
But what he doesn't know is that the turkeys can stalk him too!
When he sees a turkey, he shoots at it, but it takes a few seconds to reload his blunderbuss.
When 3 or more turkeys are near each other, they become brave, and head straight for the pilgrim and start to peck him!
When all the turkeys are gone, the hunter walks to a new part of the forest.
When the pilgrim has been pecked to death, a new pilgrim arrives to keep up the hunt.
Futher, as fall turns to winter, the ground slowly fades from green grass to white snow... when winter comes, the pilgrim dies. That's just the way it is, and that counts as one for the turkeys!

EXTENDING THE MODEL


---------------

  • Modidy the behavior of the hunter or prey

  • Enable to hunter and prey to select from different strategies for pursuit or flight

  • Make it more interactive, make it a game

  • Procedures

    NetLogo Version: NetLogo 4.0.4

    ;;;;SUMMARY
    ;; The Hunter and the Hunted--which is which?
    ;;;; COPYRIGHT
    ;; Copyright (C) 2006 James P.Steiner
    ;;
    ;;
    ;;
    
    globals
    [ turkey-score-patch ;; the patch that is responsible for displaying the turkeys' score
      pilgrim-score-patch ;; the patch that is responsible for displaying the pilgrims score 
      turkey-score ;; the turkeys' score
      pilgrim-score ;; the pilgrim's score
    ]
    
    breed [ pilgrims pilgrim ]
    breed [ dead-pilgrims dead-pilgrim ] ;; used to display dead pilgrim remains 
    breed [ turkeys turkey ]
    breed [ trees tree ]
    breed [ bullets bullet ]
    breed [ after-bullets after-bullet ] ;; when the bullet hits a turkey, it turns into an after-bullet
    
    
    pilgrims-own
    [ vision ;; the patches that the pilgrim can see
      reload ;; the count-down to the next shot
      health ;; the pilgrims health--when it gets to zero, the pilgrim dies!
      target ;; a turkey the pilgrim is stalking
    ]
    bullets-own
    [ expire ;; the count-up to when the shot stops
    ]
    
    after-bullets-own
    [ expire ;; the count-up to when the after-bullet disappears
    ]
    
    
    to setup
       ca
       setup-after-bullets
       setup-patches
       setup-trees
       setup-turkeys
       setup-pilgrims
       update-pilgrim-score
       update-turkey-score
    end
    
    to go
       
       every (1 / 30) ;; tries to do 30 frames per second
       [ ;; freeze display while all this is going on
         no-display
         ;; if all turkeys gone, 
         ;; show the pilgrim walking to a new field
         if not any? turkeys and not any? after-bullets
         [ new-trees&turkeys ]
         ;; do all the stuff that needs doing...
         go-after-bullets
         go-bullets
         go-turkeys
         go-pilgrims
         ;; now update the display with the results
         display
       ]
    end
      
    
    to setup-patches
       ;; make the patches green, like grass, to start.
       ask patches
       [ set pcolor green ]
    end
    
    
    to setup-trees
       ;; setup a number of trees
       set-default-shape trees "tree1"
       ask n-of 35 ( patches with [ pycor != max-pycor ] )
       [ setup-1-tree
       ]
    end
    
    to setup-1-tree
       ;; a patch creates (sprouts) a single tree
       sprout 1
       [ set breed trees
         ;; select one color from the choices, make it darker (- 3), then randomize that color a little
         set color (one-of [ red orange yellow lime ]) - 3 + random-float 2
         ;; select one of the "tree" shapes
         let shape# random 6
         set shape item shape# [ "tree1" "tree2" "tree3" "tree4" "tree5" "tree6" ]
         set size  1.1 ; item shape# [  2.5     2.5     1       .75      .5      .5    ]
       ]
    end
    
    to setup-turkeys
       ;; make a number of turkeys
       set-default-shape turkeys "turkey"
       ask n-of 5 patches with [ not any? turtles-here ]
       [ setup-1-turkey 
       ]
    end
    
    to setup-1-turkey
       ;; ask a patch to create (sprout) a turkey
       sprout 1
       [ set breed turkeys
       ]
    end     
    
    to setup-pilgrims
       ;; make a pilgrim
       set-default-shape pilgrims "pilgrim-left"
       ask one-of patches with [ not any? turtles-here ]
       [ sprout 1
         [ set breed pilgrims
           set size 1.1
           set health 10
           set heading -90
         ]
       ]
    end
    
    to setup-bullets
       set-default-shape bullets "bullet"
    end
    
    to setup-after-bullets
       set-default-shape after-bullets "bang"
    end
    
    to new-trees&turkeys
       ;; slides everything to the side, looks like pilgrim is travelling
       ;; to a new field
       
       ;; as things slide of one side, new things pop-up on the other side!
       
       ;; usually, a few new turkeys appear
       let new-turkey-prob 5
       ;; but sometimes, many more than usual turkeys appear!
       if random 100 < 50
       [ set new-turkey-prob 50
       ]
       ;; by repeating the shift the same as the number of columns,
       ;; we can be sure to shift every column off the screen
       repeat world-width
       [  no-display
           ;; everybody but the pilgrim shifts one patch to the left!
           ask turtles with [ breed != pilgrims ]
           [ ;; if shifting would take you off the left edge, just die
             ifelse xcor < min-pxcor + 1
             [ die ]
             [ set xcor xcor - 1
             ]
           ]
           ;; every shift a new column is exposed!
           ;; maybe make some new turkeys on that column
           if random world-width < new-turkey-prob
           [ ask one-of patches with [ pxcor = max-pxcor ]
             [ setup-1-turkey
             ]
           ]
           ;; maybe make a number of trees on that column
           if random world-width < 15
           [ ask n-of (1 + random 3) patches with [ pxcor = max-pxcor and pycor != max-pycor]
             [ setup-1-tree
             ]
           ]
           ;; update the display
           display
           ;;pause for a moment
           ;; (3 / world-width) makes the shift take 3 seconds!
         wait (3 / world-width)
       ]
    end      
    
    to go-pilgrims
       ;; do allthe things that pilgrims do (walk, hunt, shoot, get attacked
       ask pilgrims
       [ ;; if waiting to reload, 
         ;; decrement the reload countdown
         if reload > 0
         [ set reload reload - 1 ]
         ;; if 3 or more turkeys here, they are pecking pilgrim
         ;; and he is fleeing
         let pecks count turkeys-here
         ifelse pecks >= 3
         [ ;; ouch! lose 1 health point for each turkey pecking!
           set health health - pecks
           ;; if health is less than zero, pilgrim.... (weep) ...dies!
           ifelse health <= 0
           [ go-pilgrim-death ]
           ;; if not dead...
           [ ;; jump away from turkeys!
             rt random 360
             jump 1
             ;; turkeys get flung in all directions
             ask turkeys-here
             [ rt random 360
               jump 2 
             ]
           ]
         ]
         [ ;; if not too many turkeys right here, attacking
           ;; see if any turkeys in sight to stalk and shoot at!
           ifelse is-turtle? target
           [ face target
           ]
           [  
             let turkeys-nearby turkeys in-radius 7 with [ distance myself > 1 ]
             ifelse any? turkeys-nearby
             [ set target one-of turkeys-nearby
               face target
             ]
             [ rt 2 - random-float 4.0
             ]
           ]
           ifelse not can-move? 2
           [ rt 115
           ]
           [ jump .2
             ;; after moving, is a turkey in sight?
              set vision patches in-cone 14 12
              ifelse reload <= 0
              [ if any? vision with [ any? turkeys-here ]
                ;; yes! the gun is fired, and a bullet flies!
                ;; (here, since the pilgrim is already in the right place
                ;; facing the right direction, we just copy the pilgrim
                ;; and turn him into a bullet!)
                [ hatch 1
                  [ set breed bullets
                    set shape "bullet"
                    set expire 0
                    jump 1
                    set color black
                  ]
                  ;; start the reload timer! 
                  set reload 20
                ]
              ]
              [ set reload reload - 1
              ]
            ]
          ]
          ifelse heading < 180
          [ if shape != "pilgrim-right"
            [ set shape "pilgrim-right" ]
          ]
          [ if shape != "pilgrim-left"
            [ set shape "pilgrim-left" ]
          ]
        ]
    end
       
    to go-turkeys
       ;; do all the turkey things
       ;; turkeys try, though not very hard, to avoid standing on other turkeys
       ask turkeys
       [ if any? turkeys-here with [ who < [who] of myself ]
         [ rt random 360
           jump 1
         ]
       ]
       
       ask turkeys
       [ ;; when in a group, turkeys get brave, stalk pilgrim
         ;; if enough turkeys gathered close, approach the hunter!
         ;; (some (random 100 < 75) turkeys will defect)
         ifelse count turkeys in-radius 2 >= 3 and random 100 < 75
         [ face one-of pilgrims
           jump .5
         ]
         [
           ;; otherwise, turkeys look for and avoid nearby pilgrims
           if random 10 = 0 or any? pilgrims in-radius 5
           [ rt 15 - random-float 30
             ifelse can-move? .5
             [ jump .5 ]
             [ ;; flee the area
               die
             ]
             if any? turkeys-here with [ self != myself ]
             [ if can-move? -1 [ jump -1 ]
             ]
           ]
         ]
       ]
    end
    
    to go-bullets
       ;; do bullet things
       ask bullets
       [ ;; increment bullet wear-out timer
         ;; since bullets can only go so far, in this simulation
         set expire expire + 1
         if expire > 25 or any? trees-here
         [ die ]
         
         ;; if the bullet is still there...
         ;; see if the bullet hit a turkey
         ifelse any? turkeys-here
         [ ;; it did... make one turkey die (...sniffle).
           ask one-of turkeys-here
           [ go-turkey-death
           ]
           ;; turn the bullet into an "after-bullet"
           ;; this could be an explosion or a score number, or anything.
           ;; here, it is a spinning could of feathers
           set breed after-bullets
           set shape "bang"
           set expire 0 ;; reset count-up expiration timer (tells us when after-bullet is done)
           set color red ;; not really needed, since all colors are defined in this shape
         ]
         [ ;; no, didn't hit a turkey.
           ;; if the bullet isn't hitting a wall, move
           ifelse can-move? 1
           [ jump 1 ]
           [ die ]
         ]
       ]
    end
    
    to go-after-bullets
       ;; does after-bullet things
       ask after-bullets
       [ set expire expire + 1
         ;; while the after-bullet hasn't left the screen and hasn't expired
         ;; do something with it
         ifelse can-move? .25 and expire <= 5
         [ 
           jump .5 
           rt 115
         ]
         [ ;; when it has left the screen, or expired, remove it
           die
         ]
       ]
    end
    
    to go-pilgrim-death
       ;; to be defined
       set turkey-score turkey-score + 1
       update-turkey-score
       hatch 1
       [ set breed dead-pilgrims
         set shape "dead-pilgrim"
       ]
       set health 10
       setxy one-of (list min-pxcor max-pxcor)
             one-of (list min-pycor max-pycor)
    end
    
    to update-pilgrim-score
       if not is-patch? pilgrim-score-patch
       [ set pilgrim-score-patch patch 0 max-pycor
       ]
       ask pilgrim-score-patch
       [ set plabel (word "Pilgrim: " int pilgrim-score )
       ]
    end
    
    to go-turkey-death
       set pilgrim-score pilgrim-score + 1
       update-pilgrim-score
       die
    end
    
    to update-turkey-score
       if not is-patch? turkey-score-patch
       [ set turkey-score-patch patch max-pxcor max-pycor
       ]
       ask turkey-score-patch
       [ set plabel (word "Turkeys: " int turkey-score )
       ]
    end
    
       
         
         
        
            
    to startup setup end
    
                        


    Download Link

    View or download the complete model file (to download: right-click, save-link-as):
    -- Download turkey-hunter_2009 --