-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basketball_ABM.nlogo3d
1660 lines (1462 loc) · 38.7 KB
/
Basketball_ABM.nlogo3d
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
extensions [gis]
;;;; globals
globals [
home_half away_half home_key away_key home_ok away_ok home_3 away_3 home_restrict away_restrict shot_clock home_board away_board
s%3 ;; 3 point fg%
s%r ;; Restricted fg%
s%mr ;; Mid court fg%
s%hc ;; Half court fg%
s%k ;; Key fg%
s%bc ;; back court fg%
three_pointer
home_score
away_score
home_poss ;; CAREFUL With this. confused it will player variable of teamposs?
status
inb1
inb
tover
callPass
check
shot? ; global to say player has taken a shot
pass? ; global to say player has passed
intercept_options
interceptor
threshold
steals
scalled
max_lead
s_diff
lead_changes
leading_s leading_e
max_streak
]
;;;; breeds
patches-own [scoring% location_des]
breed [players player ]
;;;; ownership
players-own [
home? ;; home team
spot ;; position for player
spotx ;; x on court for your offenseive position
spoty ;; y on court for your offenseive position
spotz ;; z on court for your offenseive position
location
distance_to_location
speed
opp_location
hoop
opp_hoop
shooting_location
shooting_color
shooting_prob
teamposs? ;; home team
poss? ;; home team
score_history
score ;; home team
attempts
fg%
made ;; home team
passes ;; home team
hot_streak ;; home team
pressure ;; home team
opponent ;; who you have to guard
gun_player
shoot_pass
time_left
players_in_prox
team_mate_performance
pass_options
called ;; checked if procedure called
pass_to
attract_to_pass ;;;need to de decided on something else
offrebound
defrebound
tov
team%
oppy
hh
]
to set-up
clear-all
ask patches [draw_court]
des
score%
hatch_players
ask players [court_coords]
ask players [set_oppenents]
random_possession
reset-ticks
end
to draw_court
if pxcor <= 50 and pxcor >= -50 and pycor <= 0 and pycor > -18 and pzcor = -6 [set pcolor white - 2] ;; mid court white 9.9 (home)
if pxcor >= -8 and pxcor <= 8 and pycor < -28 and pzcor = -6 [set pcolor yellow ] ;; the key yellow 45
if pxcor >= -2 and pxcor <= 2 and pycor < -42 and pzcor = -6 [set pcolor yellow - 1 ] ;; the restricted
if pxcor >= -8 and pxcor <= 8 and pycor > -29 and pycor < -22 and pzcor = -6 [set pcolor yellow + 3] ;; mid
if pxcor < -8 and pxcor >= -22 and pycor < -28 and pzcor = -6 [set pcolor yellow + 3] ;; mid range
if pxcor <= 22 and pxcor > 8 and pycor < -28 and pzcor = -6 [set pcolor yellow + 3] ;; mid
if pxcor < -8 and pxcor >= -22 and pycor > -29 and pycor < -22 and pzcor = -6 [set pcolor yellow + 2] ;; 3 point
if pxcor <= 22 and pxcor > 8 and pycor > -29 and pycor < -22 and pzcor = -6 [set pcolor yellow + 2] ;; 3 point
if pxcor < -22 and pxcor >= -35 and pycor < -22 and pzcor = -6 [set pcolor yellow + 2] ;; 3 point
if pxcor <= 50 and pxcor > 22 and pycor < -22 and pzcor = -6 [set pcolor yellow + 2] ;; 3 point
if pxcor <= 50 and pxcor >= -50 and pycor <= -18 and pycor > -23 and pzcor = -6 [set pcolor yellow + 2] ;; 3 point
if pxcor <= 50 and pxcor >= -50 and pycor > 0 and pycor < 18 and pzcor = -6 [set pcolor white - 1] ;; mid court white 9.9 away
if pxcor >= -8 and pxcor <= 8 and pycor > 28 and pzcor = -6 [set pcolor cyan ] ;; the key cyan 85
if pxcor >= -2 and pxcor <= 2 and pycor > 42 and pzcor = -6 [set pcolor cyan + 1] ;; the restricted
if pxcor < -8 and pxcor >= -22 and pycor > 28 and pzcor = -6 [set pcolor cyan - 1] ;; mid
if pxcor <= 22 and pxcor > 8 and pycor > 28 and pzcor = -6 [set pcolor cyan - 1] ;; mid
if pxcor >= -8 and pxcor <= 8 and pycor < 29 and pycor > 22 and pzcor = -6 [set pcolor cyan - 1 ] ;; mid
if pxcor < -8 and pxcor >= -22 and pycor < 30 and pycor > 18 and pzcor = -6 [set pcolor cyan + 2] ; 3
if pxcor <= 22 and pxcor > 8 and pycor < 30 and pycor > 18 and pzcor = -6 [set pcolor cyan + 2] ; 3
if pxcor < -22 and pxcor >= -35 and pycor > 22 and pzcor = -6 [set pcolor cyan + 2] ; 3
if pxcor <= 50 and pxcor > 22 and pycor > 22 and pzcor = -6 [set pcolor cyan + 2] ; 3
if pxcor <= 50 and pxcor >= -50 and pycor >= 18 and pycor < 23 and pzcor = -6 [set pcolor cyan + 2] ; 3
if pzcor > 2 and pxcor >= -2 and pxcor <= 2 and pycor = -47 [set pcolor grey - 1 ] ;; back board
if pzcor > 2 and pxcor >= -2 and pxcor <= 2 and pycor = 47 [set pcolor grey + 1] ;; back board
end
to des
set home_half patches with [pcolor = white - 2 ] ;; I think this can go
set away_half patches with [pcolor = white - 1 ] ;; I think this can go
set home_key patches with [pcolor = yellow ]
set away_key patches with [pcolor = cyan]
set home_ok patches with [pcolor = yellow + 3 ]
set away_ok patches with [pcolor = cyan - 1 ]
set home_3 patches with [pcolor = yellow + 2]
set away_3 patches with [pcolor = cyan + 2 ]
set home_restrict patches with [pcolor = yellow - 1 ]
set away_restrict patches with [pcolor = cyan + 1 ]
set home_board patches with [pcolor = grey + 1 ]
set away_board patches with [pcolor = grey - 1 ]
end
to score%
set three_pointer false
set s%3 .33
set s%r .7
set s%mr .43
set s%hc .02
set s%bc 0
set s%k .50
end
to hatch_players
set shot_clock 24
let p 0
while [p < 10 ]
[
create-players 1 [
set shape "person"
set spot p
set poss? false
set teamposs? false
set shot? false
set speed 5 ;;; should be 22 for 4 minute mile pace
set score_history []
set score 0
set attempts 0
set made 0
set fg% 0
set passes 0
set hot_streak 0
set pressure 0
set gun_player 0
set players_in_prox []
ifelse hot_hand_factor = 0
[set hh 0 ]
[set hh 1 / hot_hand_factor ]
ifelse p < 5
[
set home? true
setxyz (0 + p) 2 -4
set color red
set size 3
set hoop [0 -45 3]
set opp_hoop [0 45 3 ]
]
[
set home? false
setxyz (0 + p) -2 -4
set color blue
set size 3
set hoop [0 45 3 ]
set opp_hoop [0 -45 3 ]
]
]
set p (p + 1)
]
ask players [
if spot = home_gun or spot = away_gun [set gun_player true] ;;;;
]
end
to court_coords
if spot = 0 [ set spotx 7 set spoty -33 set spotz -4 ]
if spot = 1 [ set spotx -7 set spoty -33 set spotz -4 ]
if spot = 2 [ set spotx 6 set spoty -39 set spotz -4 ]
if spot = 3 [ set spotx -6 set spoty -39 set spotz -4 ]
if spot = 4 [ set spotx 5 set spoty -42 set spotz -4 ]
if spot = 5 [ set spotx 7 set spoty 33 set spotz -4 ]
if spot = 6 [ set spotx -7 set spoty 33 set spotz -4 ]
if spot = 7 [ set spotx 6 set spoty 39 set spotz -4 ]
if spot = 8 [ set spotx -6 set spoty 39 set spotz -4 ]
if spot = 9 [ set spotx 4 set spoty 42 set spotz -4 ]
set location []
set location lput spotx location
set location lput spoty location
set location lput spotz location
end
to random_possession
ask one-of players [
set poss? true
set shape "bballer"
ifelse spot < 5
[
ask players with [home? = true] [set teamposs? true set home_poss true]
ask players with [home? = false] [set teamposs? false]
]
[
ask players with [home? = true] [set teamposs? false set home_poss false]
ask players with [home? = false] [set teamposs? true ]
]
]
end
to set_oppenents
ifelse home? = true
[set opponent spot + 5]
[set opponent spot - 5]
set opp_location []
end
to step
ifelse home_score - away_score > 0
[set leading_s 0]
[set leading_s 1]
strategy
stats
tick
end
to strategy
let ch count players with [poss? = true]
if ch > 1 [stop]
; set shot_clock shot_clock - 1
set shot_clock shot_clock - .5
let stealchance random-float 10
if stealchance < .03 [
steal
ifelse home_poss = true
[set home_poss false]
[set home_poss true ]
; stop
]
set status 0
if shot_clock < 2 or shot? = true
[
ask players with [poss? = true]
[ shoot
set shot_clock 24
]
]
ask players with [teamposs? = true ]
[
;; set attract_to_pass random 5 ;;;;;; change
ifelse gun_player = true
[set attract_to_pass fg% + team% + ((hot_streak / streak_size) * hh) + (bias_to_gun)]
[set attract_to_pass fg% + team% + ((hot_streak / streak_size) * hh)]
;; fg%
;; hot sreak
;; gun player
;; score
]
if status = 1 [ask players [inbound]
ifelse home_poss = true ; must call it here and not in the procedure
[set home_poss false]
[set home_poss true ]
stop]
if status = -1 [rebound ] ;; added stop
if status = -2 [ask players [rebound_turnover]
ifelse home_poss = true
[set home_poss false]
[set home_poss true ]
stop ]
if status = 0 [
ask players with [teamposs? = true ]
[offense]
ask players with [teamposs? = false ]
[defense]
ask players with [teamposs? = true ]
[pass_or_shoot]
]
if pass? = true [pass]
end
to steal
set intercept_options []
ask players with [poss? = true] [
let y get_pass_to_opp opponent
set intercept_options lput y intercept_options
]
set interceptor one-of intercept_options
ifelse home_poss = false
[
set steals steals + 1
ask players with [home? = true]
[ set teamposs? true
set pitch towards-pitch-xyz-nowrap spotx spoty -4
set heading towardsxy-nowrap spotx spoty
facexyz spotx spoty -4
]
ask players with [spot = interceptor]
[ set shape "bballer"
set poss? true]
ask players with [home? = false]
[set teamposs? false
set poss? false]
]
[ set steals steals + 1
ask players with [home? = true]
[set teamposs? false
set poss? false ]
ask players with [home? = false]
[set teamposs? true
set pitch towards-pitch-xyz-nowrap spotx spoty -4
set heading towardsxy-nowrap spotx spoty
facexyz spotx spoty -4
]
ask players with [spot = interceptor]
[set poss? true
set shape "bballer"]
]
end
to offense
let x (random 30) - 15 ;random ((n*2) +1) - n
let y (random 8) - 4
;;; add check to stop running through.....
set pitch towards-pitch-xyz-nowrap (spotx + x) (spoty + y) -4
set heading towardsxy-nowrap (spotx + x) (spoty + y)
forward speed
set location []
set location lput xcor location
set location lput ycor location
set location lput zcor location
set distance_to_location distancexyz-nowrap (spotx + x) (spoty + y) -4
;;; need to look to drive
end
to pass_or_shoot
ask players with [poss? = true]
[ set shooting_location []
set shooting_location get_my_location spot
set shooting_location but-last shooting_location
let tempx item 0 shooting_location
let tempy item 1 shooting_location
let tempz -6
set shooting_color [pcolor] of patch tempx tempy tempz
ifelse spot < 5 [
if shooting_color = 9.9 - 1 or shooting_color = 85 - 1 or shooting_color = 85 + 2 or shooting_color = 85 or shooting_color = 85 + 1 ; defines back court
[set shooting_prob s%bc]
if shooting_color = 9.9 - 2 [set shooting_prob s%hc set three_pointer true ] ; half court
if shooting_color = 45 + 3 [set shooting_prob s%mr set three_pointer false ] ; mid range
if shooting_color = 45 + 2 [set shooting_prob s%3 set three_pointer true] ; 3 point
if shooting_color = 45 [set shooting_prob s%k set three_pointer false ]; key
if shooting_color = 45 - 1 [set shooting_prob s%r set three_pointer false]
]
[
if shooting_color = 9.9 - 2 or shooting_color = 45 + 3 or shooting_color = 45 + 2 or shooting_color = 45 or shooting_color = 45 - 1 ; defines back court
[set shooting_prob s%bc]
if shooting_color = 9.9 - 1 [set shooting_prob s%hc set three_pointer true ] ; half court
if shooting_color = 85 - 1 [set shooting_prob s%mr set three_pointer false ] ; mid range
if shooting_color = 85 + 2 [set shooting_prob s%3 set three_pointer true] ; 3 point
if shooting_color = 85 [set shooting_prob s%k set three_pointer false ]; key
if shooting_color = 85 + 1 [set shooting_prob s%r set three_pointer false]
]
set time_left shot_clock
ifelse gun_player = true [let fran 1
set shoot_pass log ((( 1 / (time_left * .2)) + (shooting_prob * 2)) ^ (1 + ((hot_streak / streak_size) * (hh)) + (bias_to_gun * fran))) 10
; set shoot_pass ((( 1 / (time_left * .1)) + (hot_streak * hot_hand_factor) + (bias_to_gun * fran) + (shooting_prob * 4))) ^ 2 / 10
][
let fran 0
set shoot_pass log ((( 1 / (time_left * .2)) + (shooting_prob * 2)) ^ (1 + ((hot_streak / streak_size) * (hh)) + (bias_to_gun * fran))) 10
;set shoot_pass ((( 1 / (time_left * .1)) + (hot_streak * hot_hand_factor) + (bias_to_gun * fran) + (shooting_prob * 4)) ^ 2) / 10
]
if shooting_prob != s%bc ;; stops back court stupidity
[
set threshold random-float 2 / (1 / time_left) ;; needs to be tighter
ifelse shoot_pass > threshold ;;;
[set shot? true
set shoot_pass 0]
[set pass? true
set shoot_pass 0]
]
]
end
to pass
ask players with [poss? = true]
[ set called called + 1 ;;; seeing how often called
let team home?
set players_in_prox other players with [home? = team and distance_to_location < 3] in-cone 6 310 ;;;; sets sensensitivity of whether to pass or shoot
if any? players_in_prox
[
; set pass_to one-of players_in_prox
set pass_to max-one-of players_in_prox [attract_to_pass]
set intercept_options []
let y get_pass_to_opp opponent
set intercept_options lput y intercept_options
ask pass_to [
let x get_pass_to_opp opponent
set intercept_options lput x intercept_options
]
set interceptor one-of intercept_options
let ps random-float 1
ifelse ps > .05 [
ask pass_to [
set shape "bballer"
set poss? true
]
set shape "person"
set poss? false
set passes passes + 1
]
[
set shape "person"
set poss? false
set tov tov + 1
set passes passes + 1
in_playto ]
]
]
set pass? false
end
to-report get_pass_to_opp [opp_spot]
report [spot] of player opponent
end
to in_playto
ifelse home_poss = false
[
set tover tover + 1
set home_poss true ;;; bug fix August 28 -> flag not changed
ask players with [home? = true]
[ set teamposs? true
set pitch towards-pitch-xyz-nowrap spotx spoty -4
set heading towardsxy-nowrap spotx spoty
facexyz spotx spoty -4
]
ask players with [spot = interceptor]
[ set shape "bballer"
set poss? true]
ask players with [home? = false]
[set teamposs? false
]
]
[ set tover tover + 1
set home_poss false ;; bug fix August 28 -> flag not changed
ask players with [home? = true]
[set teamposs? false]
ask players with [home? = false]
[set teamposs? true
set pitch towards-pitch-xyz-nowrap spotx spoty -4
set heading towardsxy-nowrap spotx spoty
facexyz spotx spoty -4
]
ask players with [spot = interceptor]
[set poss? true
set shape "bballer"]
]
end
to shoot
ifelse home_poss = true
[
let hoopx item 0 hoop
let hoopy item 1 hoop
let hoopz item 2 hoop
facexyz hoopx hoopy hoopz]
[
let hoopx item 0 opp_hoop
let hoopy item 1 opp_hoop
let hoopz item 2 opp_hoop
facexyz hoopx hoopy hoopz]
set shooting_location []
set shooting_location get_my_location spot
set shooting_location but-last shooting_location
let tempx item 0 shooting_location
let tempy item 1 shooting_location
let tempz -6
set shooting_color [pcolor] of patch tempx tempy tempz
if shooting_color = 9.9 - 2 or shooting_color = 9.9 - 1 [set shooting_prob s%hc ] ; half court
if shooting_color = 45 + 3 or shooting_color = 85 - 1 [set shooting_prob s%mr ] ; mid range
if shooting_color = 45 + 2 or shooting_color = 85 + 2 [set shooting_prob s%3 set three_pointer true] ; 3 point
if shooting_color = 45 or shooting_color = 85 [set shooting_prob s%k ]; key
if shooting_color = 45 - 1 or shooting_color = 85 + 1 [set shooting_prob s%r ] ; restricted
let prob random-float 1
;let prob random-float 0
set attempts attempts + 1
if three_pointer = true and prob <= shooting_prob
[ set status 1
set made made + 1
set hot_streak hot_streak + 1
if hot_streak > max_streak [set max_streak hot_streak]
set poss? false
set shape "person"
set score_history lput 3 score_history
ifelse home_poss = true
[ set home_score home_score + 3 ]
[ set away_score away_score + 3 ]
]
if three_pointer = false and prob <= shooting_prob
[ set status 1
set made made + 1
set hot_streak hot_streak + 1
if hot_streak > max_streak [set max_streak hot_streak]
set poss? false
set shape "person"
set score_history lput 2 score_history
ifelse home_poss = true
[ set home_score home_score + 2]
[ set away_score away_score + 2]
]
if prob > shooting_prob [
set status -1
set hot_streak 0
set poss? false
set shape "person"
set score_history lput 0 score_history
]
set score sum score_history
set fg% made / attempts
if prob <= shooting_prob
[
ifelse home? = true
[ set team% score / home_score]
[ set team% score / away_score]
]
set pitch 0 ;; check
set shot? false
end
to-report get_my_location [my_spot]
report [location] of player spot
end
to inbound
ifelse home_poss = false
[
set inb inb + 1
ask players with [home? = true]
[ set teamposs? true
let x random 5
setxyz x (47 - x) -4
set pitch towards-pitch-xyz-nowrap spotx spoty -4
set heading towardsxy-nowrap spotx spoty
facexyz spotx spoty -4
]
ask players with [spot = 0]
[ set shape "bballer"
set poss? true]
ask players with [home? = false]
[set teamposs? false
]
]
[ set inb1 inb1 + 1
ask players with [home? = true]
[set teamposs? false]
ask players with [home? = false]
[set teamposs? true
let x (1 + random 5 )
setxyz x (-47 + x) -4
set pitch towards-pitch-xyz-nowrap spotx spoty -4
set heading towardsxy-nowrap spotx spoty
facexyz spotx spoty -4
]
ask players with [spot = 5]
[set poss? true
set shape "bballer"]
]
end
to rebound
ask players [
ifelse home_poss = true
[
let hoopx item 0 hoop
let hoopy item 1 hoop
let hoopz item 2 hoop
facexyz hoopx hoopy -4
set pitch towards-pitch-xyz-nowrap hoopx hoopy -4
set heading towardsxy-nowrap hoopx hoopy
forward 1
]
[
let hoopx item 0 opp_hoop
let hoopy item 1 opp_hoop
let hoopz item 2 opp_hoop
facexyz hoopx hoopy -4
set pitch towards-pitch-xyz-nowrap hoopx hoopy -4
set heading towardsxy-nowrap hoopx hoopy
forward 1
]
]
let off_chance random-float 1
ifelse off_chance < .24
[ set check check + 1
ask one-of players with [teamposs? = true]
[set poss? true
set shape "bballer"
set offrebound offrebound + 1]
]
[ ask one-of players with [teamposs? = false]
[
set defrebound defrebound + 1]
set status -2
]
end
to rebound_turnover
ifelse home_poss = false
[
set inb inb + 1
; set home_poss true ;;;; bug fix August 28 isuue related to not changing home_poss
ask players with [home? = true]
[ set teamposs? true
let x random 5
setxyz x (45 - x) -4
set pitch towards-pitch-xyz-nowrap spotx spoty -4
set heading towardsxy-nowrap spotx spoty
facexyz spotx spoty -4
]
ask players with [spot = 0]
[ set shape "bballer"
set poss? true]
ask players with [home? = false]
[set teamposs? false
]
]
[ set inb1 inb1 + 1
; set home_poss false ;;;; bug fix August 28
ask players with [home? = true]
[set teamposs? false]
ask players with [home? = false]
[set teamposs? true
let x (1 + random 5 )
setxyz x (-45 + x) -4
set pitch towards-pitch-xyz-nowrap spotx spoty -4
set heading towardsxy-nowrap spotx spoty
facexyz spotx spoty -4
]
ask players with [spot = 5]
[set poss? true
set shape "bballer"]
]
set status 0
end
to defense
set opp_location get_opponent_location opponent
let oppx item 0 opp_location
ifelse home? = true [set oppy (item 1 opp_location) + 1 ][set oppy (item 1 opp_location) - 1 ]
set pitch towards-pitch-xyz-nowrap oppx oppy -4
set heading towardsxy-nowrap oppx oppy
forward speed
end
to-report get_opponent_location [opp_spot]
report [location] of player opponent
end
to stats
let x abs ( home_score - away_score)
if x > max_lead [ set max_lead x]
ifelse home_score - away_score > 0
[set leading_e 0]
[set leading_e 1]
if leading_s != leading_e [ set lead_changes lead_changes + 1 ]
end
to go
; if ticks > 2879 [stop]
if ticks > 5759 [stop]
step
end
@#$#@#$#@
GRAPHICS-WINDOW
0
0
673
1292
-1
-1
13.0
1
10
1
1
1
0
1
1
1
-25
25
-48
48
-6
6
1
0
1
ticks
30.0
BUTTON
20
15
93
48
NIL
set-up
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
95
15
158
48
NIL
step
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
159
15
222
48
NIL
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
MONITOR
528
10
608
55
shot clock
shot_clock
17
1
11
MONITOR
608
10
694
55
home score
home_score
17
1
11
MONITOR
694
10
775
55
away score
away_score
17
1
11
PLOT
391
124
644
298
Score
NIL
NIL
0.0
5760.0
0.0
150.0
false
true
"" ""
PENS
"home" 1.0 0 -16777216 true "" "plot home_score"
"away" 1.0 0 -7500403 true "" "plot away_score"
PLOT
644
125
871
298
Score difference
NIL
NIL
0.0
5760.0
-30.0
30.0
false
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "plot home_score - away_score"
PLOT
392
453
641
605
Player Field Goal Percentage (Home)
NIL
fg%
0.0
5760.0
0.0
1.0
false
false
"ask players with [home? = true] [\n create-temporary-plot-pen (word who)\n set-plot-pen-color color\n]" "ask players with [home? = true ][\n set-current-plot-pen (word who)\n plot (fg%)\n]"
PENS
PLOT
654
454
885
604
Player Field Goal Percentage (Away)
NIL
fg%
0.0
5760.0
0.0
1.0
false
false
"ask players with [home? = false] [\n create-temporary-plot-pen (word who)\n set-plot-pen-color color\n]" "ask players with [home? = false] [\n set-current-plot-pen (word who)\n plot (fg%)\n]"
PENS
SLIDER
19
78
191
111
hot_hand_factor
hot_hand_factor
0
1
0.4
.1
1
NIL
HORIZONTAL
SLIDER
19
146
191
179
bias_to_gun
bias_to_gun
0
1
0.0
.1
1
NIL
HORIZONTAL
SLIDER
19
112
191
145
streak_size
streak_size
1