;;;;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 @#$#@#$#@ GRAPHICS-WINDOW 78 10 479 432 8 8 23.0 1 24 1 1 1 0 0 0 1 -8 8 -8 8 CC-WINDOW 5 446 488 541 Command Center 0 BUTTON 9 11 72 44 NIL setup NIL 1 T OBSERVER T NIL BUTTON 9 49 72 82 NIL go T 1 T OBSERVER T NIL @#$#@#$#@ 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 @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 link true 0 Line -7500403 true 150 0 150 300 link direction true 0 Line -7500403 true 150 150 30 225 Line -7500403 true 150 150 270 225 0 false 0 Polygon -7500403 true true 60 77 93 76 93 242 119 257 185 255 193 282 120 285 64 260 Polygon -7500403 true true 74 41 213 281 243 262 96 25 Polygon -7500403 true true 127 59 182 60 200 76 204 185 226 218 229 77 201 36 111 35 1 false 0 Polygon -7500403 true true 76 272 78 237 119 236 121 59 73 61 116 15 167 15 166 243 216 237 206 287 10 false 0 Polygon -7500403 true true 41 88 62 109 98 72 95 255 47 254 50 282 150 285 159 253 129 249 135 53 109 26 Polygon -7500403 true true 168 77 191 52 264 50 293 82 290 241 265 275 229 279 228 243 265 235 267 88 210 88 195 233 215 246 214 279 179 269 164 240 2 false 0 Rectangle -7500403 true true 223 223 223 225 Polygon -7500403 true true 224 238 225 271 62 268 59 220 142 146 173 110 171 55 128 53 100 74 97 100 60 99 56 66 96 16 147 3 214 21 233 76 232 137 172 190 117 220 226 202 3 false 0 Polygon -7500403 true true 108 87 132 53 176 57 191 88 160 125 113 130 112 169 163 171 191 209 190 227 152 257 124 254 91 212 53 228 91 282 150 297 217 275 244 216 228 162 191 147 229 115 231 68 207 30 163 9 107 7 56 50 4 false 0 Polygon -7500403 true true 124 16 32 142 34 176 129 176 122 253 93 255 91 285 211 283 217 249 166 248 174 178 235 177 241 135 178 141 198 13 161 12 129 148 76 140 147 13 5 false 0 Polygon -7500403 true true 214 29 214 74 121 68 101 150 143 133 195 134 232 173 239 208 231 258 180 294 111 289 60 254 35 232 73 200 115 235 165 245 194 212 175 185 127 186 91 185 45 172 102 27 6 false 0 Polygon -7500403 true true 222 95 256 68 212 28 170 13 97 18 53 66 20 157 40 230 88 277 166 289 223 260 267 221 250 159 193 123 127 114 95 125 91 139 117 170 145 150 206 172 207 218 160 235 94 217 70 164 74 112 103 69 144 39 197 65 218 85 7 false 0 Polygon -7500403 true true 81 27 242 35 131 286 88 284 188 68 58 76 8 true 0 Polygon -7500403 true true 99 84 177 215 181 258 147 260 105 240 101 180 117 164 92 127 63 153 38 197 88 276 159 296 232 269 218 195 183 146 142 74 140 31 185 35 196 85 179 94 194 133 229 102 243 51 188 7 121 0 85 25 81 63 9 false 0 Polygon -7500403 true true 180 134 123 133 96 114 95 58 129 34 185 35 205 55 205 212 168 260 106 258 85 231 56 242 72 266 94 278 155 291 224 266 254 211 251 47 221 23 169 1 122 4 83 21 49 52 50 100 57 129 78 153 141 170 186 171 bang true 0 Polygon -2674135 true false 230 152 275 167 305 152 305 122 275 107 230 122 Polygon -955883 true false 80 90 95 90 95 45 65 15 50 30 50 60 Polygon -955883 true false 191 93 176 93 176 48 206 18 221 33 221 63 Polygon -1184463 true false 209 83 239 38 254 38 269 53 269 68 224 98 Polygon -1184463 true false 76 111 46 66 31 66 16 81 16 96 61 126 Polygon -2674135 true false 148 230 133 275 148 305 178 305 193 275 178 230 Polygon -2674135 true false 152 70 167 25 152 -5 122 -5 107 25 122 70 Polygon -2674135 true false 70 148 25 133 -5 148 -5 178 25 193 70 178 Polygon -1184463 true false 224 189 254 234 269 234 284 219 284 204 239 174 Polygon -1184463 true false 91 217 61 262 46 262 31 247 31 232 76 202 Polygon -955883 true false 109 207 124 207 124 252 94 282 79 267 79 237 Polygon -955883 true false 220 210 205 210 205 255 235 285 250 270 250 240 Circle -6459832 true false 90 90 120 bullet false 0 Circle -16777216 true false 90 90 120 Circle -1184463 false false 90 90 120 dead-pilgrim false 0 Polygon -1 true false 105 90 105 150 150 165 195 150 195 90 Circle -1 true false 90 0 120 Polygon -1 true false 270 150 285 120 225 120 240 150 60 210 45 180 15 225 60 225 45 255 90 255 75 225 255 165 270 195 300 150 270 150 Polygon -1 true false 30 150 15 120 75 120 60 150 240 210 255 180 285 225 240 225 255 255 210 255 225 225 45 165 30 195 0 150 30 150 Circle -16777216 true false 159 39 42 Circle -16777216 true false 99 39 42 Line -16777216 false 105 120 150 135 Line -16777216 false 150 135 195 120 Line -16777216 false 120 105 120 135 Line -16777216 false 135 105 135 150 Line -16777216 false 150 105 150 150 Line -16777216 false 165 105 165 150 Line -16777216 false 180 105 180 135 Polygon -16777216 true false 150 60 165 90 150 105 135 90 Line -1 false 150 45 150 105 pilgrim-left false 0 Polygon -16777216 true false 180 90 240 150 225 165 165 105 Polygon -16777216 true false 135 90 165 90 240 225 165 240 195 300 150 300 180 285 150 240 135 300 90 300 135 285 135 240 75 225 Rectangle -955883 true false 135 75 165 94 Circle -955883 true false 120 30 60 Polygon -16777216 true false 120 90 60 150 75 165 135 105 Polygon -16777216 true false 90 60 120 45 135 0 165 0 180 45 210 60 Rectangle -1 true false 120 30 180 45 Rectangle -1184463 true false 135 22 165 52 Polygon -1 true false 135 90 120 105 135 120 150 90 165 120 180 105 165 90 Polygon -1184463 true false 30 60 0 120 45 120 150 180 165 165 60 105 Polygon -6459832 true false 165 165 210 195 210 240 180 240 180 210 150 180 Polygon -1 true false 60 165 30 120 45 120 90 165 Polygon -1 true false 210 150 180 195 195 195 240 150 pilgrim-right false 0 Polygon -16777216 true false 120 90 60 150 75 165 135 105 Polygon -16777216 true false 165 90 135 90 60 225 135 240 105 300 150 300 120 285 150 240 165 300 210 300 165 285 165 240 225 225 Rectangle -955883 true false 135 75 165 94 Circle -955883 true false 120 30 60 Polygon -16777216 true false 180 90 240 150 225 165 165 105 Polygon -16777216 true false 210 60 180 45 165 0 135 0 120 45 90 60 Rectangle -1 true false 120 30 180 45 Rectangle -1184463 true false 135 22 165 52 Polygon -1 true false 165 90 180 105 165 120 150 90 135 120 120 105 135 90 Polygon -1184463 true false 270 60 300 120 255 120 150 180 135 165 240 105 Polygon -6459832 true false 135 165 90 195 90 240 120 240 120 210 150 180 Polygon -1 true false 240 165 270 120 255 120 210 165 Polygon -1 true false 90 150 120 195 105 195 60 150 pilgrim-thin false 0 Rectangle -955883 true false 135 75 165 94 Circle -955883 true false 120 30 60 Polygon -16777216 true false 165 90 180 195 180 285 210 300 165 300 150 225 135 285 165 300 120 300 120 195 135 90 Polygon -16777216 true false 135 90 90 165 105 165 150 105 Polygon -16777216 true false 165 90 210 165 195 165 150 105 Polygon -16777216 true false 210 60 180 45 165 0 135 0 120 45 90 60 Rectangle -1 true false 120 30 180 45 Rectangle -1184463 true false 135 22 165 52 Polygon -1 true false 165 90 180 105 165 120 150 90 135 120 120 105 135 90 Polygon -1184463 true false 270 60 300 120 255 120 150 180 135 165 240 105 Polygon -6459832 true false 135 165 90 195 90 240 120 240 120 210 150 180 Polygon -1 true false 105 165 150 180 120 195 90 165 Polygon -1 true false 195 165 225 120 240 135 210 165 tree1 false 0 Circle -7500403 true true 118 -42 94 Rectangle -6459832 true false 120 135 180 300 Circle -7500403 true true 65 -24 108 Circle -7500403 true true 116 -19 127 Circle -7500403 true true 45 45 120 Circle -7500403 true true 119 14 152 tree2 false 0 Rectangle -6459832 true false 120 150 180 300 Polygon -7500403 true true 60 180 105 105 75 120 105 45 90 60 150 -90 210 60 195 45 225 120 195 105 240 180 150 150 tree3 false 0 Rectangle -7500403 true true 135 90 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 tree4 false 0 Rectangle -7500403 true true 135 165 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 Polygon -7500403 true true 135 165 120 120 150 90 180 120 165 165 tree5 false 0 Rectangle -7500403 true true 135 240 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 240 120 195 150 165 180 195 165 240 tree6 false 0 Polygon -7500403 true true 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 Polygon -7500403 true true 189 233 219 188 249 173 279 188 234 218 Polygon -7500403 true true 180 255 150 210 105 210 75 240 135 240 Polygon -7500403 true true 180 150 180 120 165 97 135 84 128 121 147 148 165 165 Polygon -7500403 true true 170 155 131 163 175 167 196 136 turkey true 0 Circle -6459832 true false 90 90 120 Circle -6459832 true false 120 45 60 Polygon -2674135 true false 133 170 118 215 133 245 163 245 178 215 163 170 Polygon -955883 true false 175 165 160 165 160 210 190 240 205 225 205 195 Polygon -955883 true false 124 162 139 162 139 207 109 237 94 222 94 192 Polygon -1184463 true false 121 172 91 217 76 217 61 202 61 187 106 157 Polygon -1184463 true false 179 174 209 219 224 219 239 204 239 189 194 159 Polygon -955883 true false 135 60 150 30 165 60 Circle -16777216 true false 155 59 16 Circle -16777216 true false 129 59 16 @#$#@#$#@ NetLogo 3.1.3 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@