-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhuntingBout.nlogo
More file actions
6810 lines (6121 loc) · 186 KB
/
Copy pathhuntingBout.nlogo
File metadata and controls
6810 lines (6121 loc) · 186 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
globals
[
;;; constants
patch-width
max-perception-distance
track-maximum
good-daylight-duration
starting-point
wind-spread-angle
;;; parameters
;;;; contextual
starting-point-buffer-distance
obstacle-damage
track-mark-probability
track-pregeneration-period
wind-speed
wind-direction
;;;; hunters (population)
num-hunters
num-planned-waypoints
hunters_height_stealth
hunters_height_min
hunters_height_max
hunters_visualacuity_mean
hunters_visualacuity_sd
hunters_speed_stealth
hunters_speed_min
hunters_speed_max
hunters_speed_avmax
hunters_tte_min
hunters_tte_max
hunters_reactiontime_min
hunters_reactiontime_max
hunters_cooldowntime_min
hunters_cooldowntime_max
max-shooting-distance
hunters_hearing_radius
hunters_fov
;;;; preys (population)
num-preys
preys_group_max_size
preys_safe-distance
preys_height_min
preys_height_max
preys_visualacuity_mean
preys_visualacuity_sd
preys_speed_min
preys_speed_max
preys_speed_avmax
preys_tte_min
preys_tte_max
preys_reactiontime_min
preys_reactiontime_max
preys_cooldowntime_min
preys_cooldowntime_max
preys_hearing_radius
preys_fov
;;;; environment
init-obstacle-scale
init-obstacle-frequency
init-obstacle-diffuse-times
init-obstacle-diffuse-rate
prey-attractor-probability
attractiveness-diffuse-times
attractiveness-diffuse-rate
fires-number
fires-radius
;;; variables
attractiveness-to-prey-max
planned-waypoints
visited-waypoints
discarded-waypoints
hunter-prey-detections
prey-hunter-detections
sneaks
pursues
shots
was-bout-successful
is-bout-finished
hunter-who-shot
prey-who-got-shot
]
breed [ hunters hunter ]
breed [ preys prey ]
breed [ track-makers track-maker ]
hunters-own
[
height
stealth-height
visual-acuity
speed-max
time-to-exhaustion
reaction-time
cooldown-time
any-detection
any-unseen-target
stealth
success
hunters-detected
preys-detected
unseen-target-location
follow-track-target
approaching-target
pursuing-target
;;; internal/private
approach-path
reaction-counter
relax-counter
exhaustion-counter
cooldown-counter
moved-this-turn
;;; measurements
distance-moved
hunting-mode-series
position-series-x
position-series-y
]
preys-own
[
height
visual-acuity
speed-max
time-to-exhaustion
reaction-time
cooldown-time
group_id
group-leader
any-detection
any-unseen-target
;;; internal/private
hunters-detected
preys-detected
unseen-target-location
reaction-counter
relax-counter
exhaustion-counter
cooldown-counter
moved-this-turn
]
track-makers-own
[
owner
maximum-track-antiquity
]
patches-own
[
elevation
obstacle
attractiveness-to-prey
tracks
;;; path-finding related
parent-patch ; patch's predecessor
f ; the value of knowledge plus heuristic cost function f()
g ; the value of knowledge cost function g()
h ; the value of heuristic cost function h()
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; SETUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
clear-all
set-input
setup-environment
setup-prey-groups
setup-hunting-party
initialise-perceptions
generate-recent-tracks
initialise-output
reset-ticks
update-display
end
to set-input
set-constants
set-parameters
end
to set-constants
set patch-width 50 ;;; meters
set max-perception-distance 1000 * 5 / patch-width ;;; patch-width unit (default: 1000 * 5 / patch-width, i.e. 5 km approximation on person standing on flat terrain on Earth)
set track-maximum 5
set good-daylight-duration 8 * 60 * 60 ;;; default: 8 hours in seconds
;;; NOTE: the range in Namibia study areas of total daylight 9-10 hours; discouting an hour to get back to camp
set starting-point patch (min-pxcor + floor (world-width / 2)) (min-pycor + floor (world-height / 2))
set wind-spread-angle 30 ; degrees, each side of main direction
end
to set-parameters
random-seed SEED
;;; parameters
set-scenario-environment-parameters
set obstacle-damage par_obstacle-damage ;;; damage (m obstacle) / 1 (m height) * 1 (sec)
set track-mark-probability par_track-mark-probability ;;; prob. / 1 (m height) * 1 (sec)
set track-pregeneration-period par_track-pregeneration-period
set wind-speed convert-kmperh-to-patchpersec par_wind-speed ; patch width (m) per second
set wind-direction par_wind-direction ; degrees, from default NetLogo's (North = 0)
;;;; hunters
set num-hunters par_num-hunters
set hunters_height_min par_hunters_height_min ; meters
set hunters_height_max par_hunters_height_max
set hunters_height_stealth par_hunters_height_stealth ; metre
set hunters_visualacuity_mean par_hunters_visualacuity_mean ; % of maximum perception distance
set hunters_visualacuity_sd par_hunters_visualacuity_sd
set hunters_speed_min convert-kmperh-to-patchpersec par_hunters_speed_min ; patch width (m) per second
set hunters_speed_max convert-kmperh-to-patchpersec par_hunters_speed_max
set hunters_speed_avmax convert-kmperh-to-patchpersec par_hunters_speed_avmax
set hunters_speed_stealth hunters_speed_min * (par_hunters_speed_stealth / 100)
set hunters_tte_min par_hunters_tte_min ; minutes
set hunters_tte_max par_hunters_tte_max
set hunters_reactiontime_min par_hunters_reactiontime_min
set hunters_reactiontime_max par_hunters_reactiontime_max
set hunters_cooldowntime_min par_hunters_cooldowntime_min
set hunters_cooldowntime_max par_hunters_cooldowntime_max
set max-shooting-distance par_max-shooting-distance / patch-width ;;; metres
set hunters_hearing_radius par_hunters_hearing_radius / patch-width
set hunters_fov par_hunters_fov ;;; degrees
set num-planned-waypoints par_num-planned-waypoints
;;;; preys
set num-preys par_num-preys
set preys_group_max_size par_preys_group_max_size
set preys_safe-distance par_preys_safe-distance / patch-width
set preys_height_min par_preys_height_min ; meters
set preys_height_max par_preys_height_max
set preys_visualacuity_mean par_preys_visualacuity_mean ; % of maximum perception distance
set preys_visualacuity_sd par_preys_visualacuity_sd
set preys_speed_min convert-kmperh-to-patchpersec par_preys_speed_min ; patch width (m) per second
set preys_speed_max convert-kmperh-to-patchpersec par_preys_speed_max
set preys_speed_avmax convert-kmperh-to-patchpersec par_preys_speed_avmax
set preys_tte_min par_preys_tte_min ; minutes
set preys_tte_max par_preys_tte_max
set preys_reactiontime_min par_preys_reactiontime_min
set preys_reactiontime_max par_preys_reactiontime_max
set preys_cooldowntime_min par_preys_cooldowntime_min
set preys_cooldowntime_max par_preys_cooldowntime_max
set preys_hearing_radius par_preys_hearing_radius / patch-width
set preys_fov par_preys_fov ;;; degrees
set starting-point-buffer-distance par_starting-point-buffer-distance ; km
end
to set-scenario-environment-parameters
if (scenario-environment = "user-defined")
[
set init-obstacle-scale par_init-obstacle-scale
set init-obstacle-frequency par_init-obstacle-frequency
set init-obstacle-diffuse-times par_init-obstacle-diffuse-times
set init-obstacle-diffuse-rate par_init-obstacle-diffuse-rate
set prey-attractor-probability par_prey-attractor-probability
set attractiveness-diffuse-times par_attractiveness-diffuse-times
set attractiveness-diffuse-rate par_attractiveness-diffuse-rate
set fires-number par_fires-number
set fires-radius par_fires-radius
]
if (scenario-environment = "default")
[
set init-obstacle-scale 5
set init-obstacle-frequency 5
set init-obstacle-diffuse-times 10
set init-obstacle-diffuse-rate 0.3
set prey-attractor-probability 1
set attractiveness-diffuse-times 10
set attractiveness-diffuse-rate 0.3
;;; no fires
set fires-number 0
set fires-radius 0
]
if (scenario-environment = "wet and no fires")
[
set init-obstacle-scale 10
set init-obstacle-frequency 10
set init-obstacle-diffuse-times 5
set init-obstacle-diffuse-rate 0.3
set prey-attractor-probability 20
set attractiveness-diffuse-times 10
set attractiveness-diffuse-rate 0.3
;;; no fires
set fires-number 0
set fires-radius 0
]
if (scenario-environment = "dry and no fires")
[
set init-obstacle-scale 2
set init-obstacle-frequency 5
set init-obstacle-diffuse-times 5
set init-obstacle-diffuse-rate 0.3
set prey-attractor-probability 0.1
set attractiveness-diffuse-times 10
set attractiveness-diffuse-rate 0.3
;;; no fires
set fires-number 0
set fires-radius 0
]
if (scenario-environment = "wet with fires")
[
set init-obstacle-scale 10
set init-obstacle-frequency 10
set init-obstacle-diffuse-times 5
set init-obstacle-diffuse-rate 0.3
set prey-attractor-probability 20
set attractiveness-diffuse-times 10
set attractiveness-diffuse-rate 0.3
;;; with fires
set fires-number 20
set fires-radius 100
]
if (scenario-environment = "dry with fires")
[
set init-obstacle-scale 2
set init-obstacle-frequency 5
set init-obstacle-diffuse-times 5
set init-obstacle-diffuse-rate 0.3
set prey-attractor-probability 0.1
set attractiveness-diffuse-times 10
set attractiveness-diffuse-rate 0.3
;;; with fires
set fires-number 20
set fires-radius 100
]
end
to set-parameters-to-default
set scenario-environment "default"
set par_wind-direction 0
set par_wind-speed 20
set par_track-pregeneration-period 7
set par_starting-point-buffer-distance 1.5
set par_obstacle-damage 0.01
set par_track-mark-probability 0.1
set par_num-planned-waypoints 5
set waypoints-to-prey-attractors true
set par_num-hunters 2
set par_hunters_reactiontime_min 5
set par_hunters_reactiontime_max 30
set par_hunters_tte_min 5
set par_hunters_tte_max 30
set par_hunters_cooldowntime_min 300
set par_hunters_cooldowntime_max 600
set par_hunters_fov 200
set par_hunters_visualacuity_mean 65
set par_hunters_visualacuity_sd 15
set par_hunters_hearing_radius 50
set par_hunters_height_min 1.5
set par_hunters_height_max 2
set par_hunters_height_stealth 50
set par_hunters_speed_min 5
set par_hunters_speed_avmax 15
set par_hunters_speed_stealth 50
set par_hunters_speed_max 30
set par_max-shooting-distance 50
set par_num-preys 25
set par_preys_group_max_size 5
set par_preys_reactiontime_min 60
set par_preys_reactiontime_max 120
set par_preys_tte_min 60
set par_preys_tte_max 100
set par_preys_cooldowntime_min 200
set par_preys_cooldowntime_max 600
set par_preys_fov 300
set par_preys_visualacuity_mean 33
set par_preys_visualacuity_sd 20
set par_preys_hearing_radius 300
set par_preys_height_min 1
set par_preys_height_max 2.5
set par_preys_safe-distance 500
set par_preys_speed_min 5
set par_preys_speed_avmax 30
set par_preys_speed_max 75
set par_preys_safe-distance 500
end
to initialise-output
set hunter-prey-detections 0
set prey-hunter-detections 0
set sneaks 0
set pursues 0
set shots 0
set was-bout-successful false
set hunter-who-shot ""
set prey-who-got-shot ""
set is-bout-finished false
end
to setup-environment
ask patches
[
set elevation random-float 10
set tracks []
]
repeat 10 [ diffuse elevation 0.5 ]
; ask patches with [pxcor = floor (world-width / 2) and (pycor < floor ((world-height / 2) - 10) or pycor > floor ((world-height / 2) + 10))]
; [
; set obstacle 5
; ]
let num-patches-with-init-obstacle ((init-obstacle-frequency / 100) * count patches)
ask n-of num-patches-with-init-obstacle patches [ set obstacle init-obstacle-scale ]
repeat init-obstacle-diffuse-times [ diffuse obstacle init-obstacle-diffuse-rate ]
ask patches [ if (random-float 100 < prey-attractor-probability) [ set attractiveness-to-prey 100 ] ]
repeat attractiveness-diffuse-times [ diffuse attractiveness-to-prey attractiveness-diffuse-rate ]
set attractiveness-to-prey-max max [attractiveness-to-prey] of patches
ask n-of fires-number patches
[
set obstacle 0
set attractiveness-to-prey 100
ask patches in-radius floor (fires-radius / patch-width)
[
set obstacle 0
set attractiveness-to-prey 100
]
]
set attractiveness-to-prey-max max [attractiveness-to-prey] of patches
end
to setup-prey-groups
create-preys num-preys
[
set height preys_height_min + random-float (preys_height_max - preys_height_min)
set visual-acuity min list (random-normal preys_visualacuity_mean preys_visualacuity_sd) 100
set speed-max sample-skewed-speed preys_speed_min preys_speed_max preys_speed_avmax
set time-to-exhaustion (preys_tte_min + random (preys_tte_max - preys_tte_min)) * 60
set reaction-time preys_reactiontime_min + random (preys_reactiontime_max - preys_reactiontime_min)
set cooldown-time preys_cooldowntime_min + random (preys_cooldowntime_max - preys_cooldowntime_min)
set group-leader false
set any-unseen-target false
set unseen-target-location no-patches
set moved-this-turn false
set shape "sheep"
]
;; Initialize variables for grouping
let unassigned preys
let currentID 0
let buffer-distance starting-point-buffer-distance * 1000 / patch-width ;;; km -> m -> patch widths
let valid-initial-positions patches with [distance starting-point > buffer-distance]
;; Group assignment loop
while [any? unassigned]
[
let groupSize min list preys_group_max_size (count unassigned)
let newGroupMembers n-of (1 + random groupSize) unassigned
ask newGroupMembers
[
set group_id currentID
]
;; Assign group leader
ask one-of newGroupMembers
[
set group-leader true
]
;; Position the group
let preyPosition one-of valid-initial-positions
ask preys with [group_id = currentID]
[
move-to preyPosition
if (not group-leader)
[
;;; shuffle initial position around leader
move-to one-of neighbors
]
]
set unassigned unassigned with [not member? self newGroupMembers]
set currentID currentID + 1
]
end
to generate-recent-tracks
let trackPregenerationPeriodInSeconds convert-hours-to-seconds track-pregeneration-period
ask preys
[
hatch-track-makers 1
[
let me self
set owner [group_id] of myself
set maximum-track-antiquity trackPregenerationPeriodInSeconds
set heading (mean [heading] of preys with [group_id = [owner] of me]) - 180
]
]
ask track-makers
[
let me self
let previousTrackMarkProbability track-mark-probability * 100 * (mean [height] of preys with [group_id = [owner] of me]) * (count preys with [group_id = [owner] of me])
let obstacleDamage obstacle-damage * (mean [height] of preys with [group_id = [owner] of me]) * (count preys with [group_id = [owner] of me])
let trackAntiquity 0
;;; shuffle within neighbors to emulate group distribution
;move-to one-of neighbors
while [ trackAntiquity < maximum-track-antiquity ]
[
set obstacle max (list 0 (obstacle - obstacleDamage))
if (previousTrackMarkProbability > random-float 100)
[
let preyLeavingTrack one-of preys with [group_id = [owner] of me]
add-track-from preyLeavingTrack (heading) (0 - trackAntiquity)
]
if (count neighbors < 8) [ die ] ;;; delete once it reaches the edges of the area
;;; get a relative measure of how attractive is the current patch
let patch-pull 0
if (attractiveness-to-prey-max > 0)
[ set patch-pull 100 * ([attractiveness-to-prey] of patch-here) / attractiveness-to-prey-max ]
if (random-float 100 > patch-pull)
[
rt (- 30 + random 60) ;;; add random direction biased by default heading
fd 1
]
set trackAntiquity trackAntiquity + 1
]
die
]
end
to setup-hunting-party
ask starting-point
[
set obstacle 0 ;;; clear starting point
sprout-hunters num-hunters
[
set height hunters_height_min + random-float (hunters_height_max - hunters_height_min)
set stealth-height height * (hunters_height_stealth / 100)
set visual-acuity clamp0100 (random-normal hunters_visualacuity_mean hunters_visualacuity_sd)
set speed-max sample-skewed-speed hunters_speed_min hunters_speed_max hunters_speed_avmax
set time-to-exhaustion hunters_tte_min + random (hunters_tte_max - hunters_tte_min)
set time-to-exhaustion time-to-exhaustion * 60 ; convert minutes to seconds
set reaction-time hunters_reactiontime_min + random (hunters_reactiontime_max - hunters_reactiontime_min)
set cooldown-time hunters_cooldowntime_min + random (hunters_cooldowntime_max - hunters_cooldowntime_min)
set any-unseen-target false
set unseen-target-location no-patches
set follow-track-target nobody
set approaching-target nobody
set pursuing-target nobody
set approach-path []
set stealth false
set success false
set moved-this-turn false
set shape "person"
set distance-moved 0
set hunting-mode-series []
set position-series-x []
set position-series-y []
]
]
;;; hunters group movement planning
set planned-waypoints get-planned-waypoints num-planned-waypoints
set visited-waypoints []
set discarded-waypoints []
end
to-report get-planned-waypoints [ numPoints ]
let valid-candidates patches with [count neighbors = 8]
; NOTE: ignore edge patches that might peak because of the use of the diffuse command in setup-environment
let selected-waypoints n-of numPoints valid-candidates
;;; filter candidates with the most prey attractiveness (known points of interest)
if (waypoints-to-prey-attractors)
[
set selected-waypoints max-n-of numPoints valid-candidates [attractiveness-to-prey]
]
;;; TO-DO - better definition/representation of previous planning
;;; (e.g., interesting points, attractors?, must be "economic", knowledge of area, movement patterns, wind direction of the day)
report selected-waypoints
end
to initialise-perceptions
ask (turtle-set preys hunters)
[
set any-detection false
set hunters-detected (turtle-set)
set preys-detected (turtle-set)
initialise-perception-links
]
end
to initialise-perception-links
ifelse (breed = preys)
[
create-links-from other hunters [ set color red set hidden? true ]
create-links-from other preys [ set color violet set hidden? true ]
]
[
create-links-from other hunters [ set color cyan set hidden? true ]
create-links-from other preys [ set color yellow set hidden? true ]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; GO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
ask (turtle-set preys hunters with [cooldown-counter = 0])
[
ifelse (any-detection)
[
ifelse (breed = preys)
[
prey-detection-move
]
[
hunter-detection-move
]
set moved-this-turn true
]
[
;;; if there are no detection, reaction counter is reset
set reaction-counter 0
]
]
ask (turtle-set preys hunters) with [not moved-this-turn and cooldown-counter = 0]
[
ifelse (any-unseen-target)
[
ifelse (breed = preys)
[
prey-memory-move
]
[
hunter-memory-move
]
]
[
ifelse (breed = preys)
[
prey-default-move
]
[
hunter-default-move
]
]
]
ask (turtle-set preys hunters) with [has-message]
[
ifelse (breed = preys)
[
prey-communicate
]
[
hunter-communicate
]
]
ask preys
[
check-escape-condition
]
ask hunters
[
update-waypoints
]
ask (turtle-set preys hunters)
[
check-cooldown-condition
update-perception
impact-vegetation
]
ask (turtle-set preys hunters)
[
update-alertness
set moved-this-turn false
]
ask hunters [ save-position ]
clear-older-tracks
update-display
if (print-messages) [ print "second has passed." ]
if (was-bout-successful or is-bout-finished) [ stop ] ;;; interrupt simulation once there is a successful shot or a hunter arrives back to camp
tick
end
to prey-detection-move
if (print-messages) [ print (word "prey " who " sees hunter" ([who] of hunters-detected)) ]
ifelse (reaction-counter > 0)
[
if (print-messages) [ print (word "thinking... " reaction-counter " secs to reaction") ]
;;; PROCESS REACTION
set reaction-counter reaction-counter - 1
]
[
;;; FLEE
move-away-from hunters-detected
]
end
to prey-message-move
let fleeing-preys preys-detected with [ any-detection and exhaustion-counter > 0 ]
if (any? fleeing-preys)
[
;;; FOLLOW FLEEING PREYS
move-along-with fleeing-preys
]
;;; else, STAY ALERT
;;; message received, but the emmiting part is still not reacting.
end
to hunter-detection-move
if (print-messages) [ print (word "hunter " who " sees prey" ([who] of preys-detected)) ]
;;; reset follow-track-target (detection takes priority)
set follow-track-target nobody
ifelse (reaction-counter > 0)
[
if (print-messages) [ print (word "thinking... " reaction-counter " secs to reaction") ]
;;; PROCESS REACTION
set reaction-counter reaction-counter - 1
]
[
let me self
let alerted-preys preys-detected with [any-detection and member? me hunters-detected]
ifelse (any? alerted-preys)
[
;;; prey becomes aware of this hunter, if not already before
ask min-one-of alerted-preys [distance myself]
[
set hunters-detected (turtle-set myself hunters-detected)
]
ifelse (min [distance myself] of alerted-preys < max-shooting-distance)
[
;;; SHOOT
save-hunting-mode "SHOOT"
set shots shots + 1
hunter-shoot (min-one-of alerted-preys [distance myself])
]
[
;;; TO-DO: STANDING-LIKE-A-BUSH
;;; PURSUE
save-hunting-mode "PURSUE"
set pursues pursues + 1
hunter-pursue (min-one-of alerted-preys [distance myself])
]
]
[
;;; STEALTH APPROACH
save-hunting-mode "APPROACH-STEALTH"
set sneaks sneaks + 1
hunter-approach (min-one-of preys-detected [distance myself])
]
]
end
to hunter-shoot [ aPrey ]
if (print-messages) [ print (word "hunter " who " shoots prey " ([who] of aPrey)) ]
let me self
;;; stand, if stealth
set stealth false
;;; reset approaching-target
set approaching-target nobody
set approach-path []
;;; reset pursuing-target
set pursuing-target nobody
ifelse (random-float 100 < (1 - ( (distance aPrey) / max-shooting-distance )) * 100)
[
;;; SUCCESS
;;; signal successful hunt and head back to camp
set discarded-waypoints planned-waypoints
set planned-waypoints (patch-set starting-point)
save-hunting-mode "SUCCESSFUL-SHOT"
save-hunting-mode "BACK-TO-CAMP"
if (print-messages) [ print "success!" ]
set success true
set was-bout-successful true
;;; keep successful hunt information
set prey-who-got-shot (word prey-who-got-shot " " aPrey)
set hunter-who-shot (word hunter-who-shot " " self)
;;; mark the spot
ask [patch-here] of aPrey
[
sprout-track-makers 1
[
;;; prey is shot
set shape "x"
set size 5
set color red
]
]
;;; the prey agent is alerted and will start to flee
ask aPrey
[
;die
set any-unseen-target true
set unseen-target-location (patch-set ([patch-here] of me))
]
]
[
;;; FAIL
if (print-messages) [ print "fail!" ]
]
end
to hunter-pursue [ aPrey ]
if (print-messages) [ print (word "hunter " who " pursues prey " ([who] of aPrey)) ]
;;; stand, if stealth
set stealth false
;;; reset approaching-target
set approaching-target nobody
set approach-path []
set pursuing-target aPrey
let MoveDistance (get-speed-in-patch hunters_speed_max patch-here)
face aPrey