-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStateSetters.py
1762 lines (1484 loc) · 73.4 KB
/
StateSetters.py
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
import math
import random
from collections import namedtuple
import numpy as np
from rlgym_sim.utils.common_values import CAR_MAX_SPEED, SIDE_WALL_X, BACK_WALL_Y, CEILING_Z, BALL_RADIUS, \
CAR_MAX_ANG_VEL, \
BALL_MAX_SPEED, BLUE_TEAM, ORANGE_TEAM, BOOST_LOCATIONS
from rlgym_sim.utils.gamestates import PhysicsObject
from rlgym_sim.utils.math import rand_vec3
from rlgym_sim.utils.state_setters import StateSetter
from rlgym_sim.utils.state_setters import StateWrapper
from rlgym_sim.utils.state_setters.wrappers import CarWrapper
from rlgym_tools.extra_state_setters.replay_setter import ReplaySetter
LIM_X = SIDE_WALL_X - 1152 / 2 - BALL_RADIUS * 2 ** 0.5
LIM_Y = BACK_WALL_Y - 1152 / 2 - BALL_RADIUS * 2 ** 0.5
LIM_Z = CEILING_Z - BALL_RADIUS
PITCH_LIM = np.pi / 2
YAW_LIM = np.pi
ROLL_LIM = np.pi
GOAL_X_MAX = 800.0
GOAL_X_MIN = -800.0
PLACEMENT_BOX_X = 5000
PLACEMENT_BOX_Y = 2000
PLACEMENT_BOX_Y_OFFSET = 3000
GOAL_LINE = 5100
YAW_MAX = np.pi
DEG_TO_RAD = np.pi / 180
def mirror(car: CarWrapper, ball_x, ball_y):
my_car = namedtuple('my_car', 'pos lin_vel rot ang_vel')
if ball_x == ball_y == 0:
my_car.pos = -car.position[0], -car.position[1], car.position[2]
my_car.lin_vel = -car.linear_velocity[0], -car.linear_velocity[1], car.linear_velocity[2]
my_car.rot = car.rotation[0], -car.rotation[1], car.rotation[2]
my_car.ang_vel = -car.angular_velocity[0], -car.angular_velocity[1], car.angular_velocity[2]
elif ball_x == 0:
my_car.pos = -car.position[0], car.position[1], car.position[2]
my_car.lin_vel = -car.linear_velocity[0], car.linear_velocity[1], car.linear_velocity[2]
my_car.rot = car.rotation[0], -car.rotation[1], car.rotation[2]
my_car.ang_vel = -car.angular_velocity[0], -car.angular_velocity[1], car.angular_velocity[2]
elif ball_y == 0:
my_car.pos = car.position[0], -car.position[1], car.position[2]
my_car.lin_vel = -car.linear_velocity[0], car.linear_velocity[1], car.linear_velocity[2]
my_car.rot = car.rotation[0], -car.rotation[1], car.rotation[2]
my_car.ang_vel = -car.angular_velocity[0], -car.angular_velocity[1], car.angular_velocity[2]
elif ball_x == ball_y and car.position[0] > car.position[1]:
my_car.pos = -car.position[0], -car.position[1], car.position[2]
my_car.lin_vel = car.linear_velocity[1], car.linear_velocity[0], car.linear_velocity[2]
my_car.rot = car.rotation[0] - np.pi / 2, car.rotation[1], car.rotation[2]
my_car.ang_vel = -car.angular_velocity[0], -car.angular_velocity[1], car.angular_velocity[2]
else:
return None
return my_car
def set_pos(end_object: PhysicsObject, x: float = None, y: float = None, z: float = None):
"""
Sets position.
:param end_object: object to set
:param x: Float indicating x position value.
:param y: Float indicating y position value.
:param z: Float indicating z position value.
"""
if x is not None and y is not None and z is not None:
if x == y == z == -1:
end_object.position[0] = -1
end_object.position[1] = -1
end_object.position[2] = -1
return
if x is not None:
end_object.position[0] = max(min(x, 4096), -4096)
if y is not None:
end_object.position[1] = max(min(y, 3800), -3800)
if z is not None:
end_object.position[2] = max(min(z, 1700), 350)
def random_valid_loc() -> np.ndarray:
rng = np.random.default_rng()
rand_x = rng.uniform(-4000, 4000)
if abs(rand_x) > (4096 - 1152):
rand_y = rng.uniform(-5120 + 1152, 5120 - 1152)
else:
rand_y = rng.uniform(-5020, 5020)
rand_z = rng.uniform(20, 2000)
return np.asarray([rand_x, rand_y, rand_z])
class AerialStateSetter(StateSetter):
MID_AIR = 900
LOW_AIR = 150
HIGH_AIR = 1500
CEILING = CEILING_Z
def compare_arrays_inferior(arr1: np.array, arr2: np.array) -> bool:
return all(arr1[0:2] < arr2[0:2])
def _check_positions(state: StateWrapper) -> bool:
CAR_DIM = np.array((50, 50, 50))
# Checking all others for each car
for car in state.cars:
current_car = car
for other in state.cars:
if other == current_car:
continue
if compare_arrays_inferior(abs(current_car.position - other.position), CAR_DIM):
print("Car too close, resetting")
return False
if compare_arrays_inferior(abs(current_car.position - state.ball.position), CAR_DIM):
return False
return True
class CustomStateSetter(StateSetter):
"""def reset(self, state_wrapper: StateWrapper):
# Set up our desired spawn location and orientation. Here, we will only change the yaw, leaving the remaining
for car in state_wrapper.cars:
desired_car_pos = [random.randint(-4000, 4000), random.randint(-5000, 5000), random.randint(50, int(CEILING_Z) - int(BALL_RADIUS) * 2)]
desired_yaw = np.pi / 2
#print(desired_car_pos)
if car.team_num == BLUE_TEAM:
pos = desired_car_pos
yaw = desired_yaw
elif car.team_num == ORANGE_TEAM: # invert
pos = [-1 * coord for coord in desired_car_pos]
yaw = -1 * desired_yaw
car.set_pos(*pos)
car.set_rot(yaw=yaw)
car.boost = random.randint(0, 100)
state_wrapper.ball.set_pos(random.randint(-3000, 3000), random.randint(-3000, 3000),
random.randint(0 + int(BALL_RADIUS) * 2, int(CEILING_Z) - int(BALL_RADIUS) * 2))"""
def __init__(self):
super().__init__()
def reset(self, state_wrapper: StateWrapper):
state_wrapper.ball.set_pos(
x=np.random.uniform(-LIM_X, LIM_X),
y=np.random.uniform(-LIM_Y, LIM_Y),
z=np.random.triangular(BALL_RADIUS, BALL_RADIUS, LIM_Z),
)
# 99.9% chance of below ball max speed
ball_speed = np.random.exponential(-BALL_MAX_SPEED / np.log(1 - 0.999))
vel = rand_vec3(min(ball_speed, BALL_MAX_SPEED))
state_wrapper.ball.set_lin_vel(*vel)
ang_vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_ANG_VEL + 0.5))
state_wrapper.ball.set_ang_vel(*ang_vel)
for car in state_wrapper.cars:
# On average 1 second at max speed away from ball
ball_dist = np.random.exponential(BALL_MAX_SPEED)
ball_car = rand_vec3(ball_dist)
car_pos = state_wrapper.ball.position + ball_car
if abs(car_pos[0]) < LIM_X \
and abs(car_pos[1]) < LIM_Y \
and 0 < car_pos[2] < LIM_Z:
car.set_pos(*car_pos)
else: # Fallback on fully random
car.set_pos(
x=np.random.uniform(-LIM_X, LIM_X),
y=np.random.uniform(-LIM_Y, LIM_Y),
z=np.random.triangular(BALL_RADIUS, BALL_RADIUS, LIM_Z),
)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
car.set_rot(
pitch=np.random.triangular(-PITCH_LIM, 0, PITCH_LIM),
yaw=np.random.uniform(-YAW_LIM, YAW_LIM),
roll=np.random.triangular(-ROLL_LIM, 0, ROLL_LIM),
)
ang_vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_ANG_VEL))
car.set_ang_vel(*ang_vel)
car.boost = np.random.uniform(0, 1)
class ShotState(StateSetter):
def __init__(self):
super().__init__()
def reset(self, state_wrapper: StateWrapper):
for car in state_wrapper.cars:
if car.team_num == BLUE_TEAM:
car.set_pos(
random.uniform(-4096, 4096),
random.uniform(0, 3000),
17
)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
car.set_rot(
pitch=np.random.triangular(-PITCH_LIM, 0, PITCH_LIM),
yaw=np.random.uniform(-YAW_LIM, YAW_LIM),
roll=np.random.triangular(-ROLL_LIM, 0, ROLL_LIM),
)
ang_vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_ANG_VEL))
car.set_ang_vel(*ang_vel)
car.boost = np.random.uniform(0, 1)
state_wrapper.ball.set_pos(
x=np.random.uniform(max(car.position.item(0) - 1000, -LIM_X),
min(car.position.item(0) + 1000, LIM_X)),
y=np.random.uniform(car.position.item(1) + 1000, car.position.item(1) + 100),
z=np.random.triangular(BALL_RADIUS, BALL_RADIUS, LIM_Z / 2),
)
ball_speed = np.random.exponential(-(BALL_MAX_SPEED / 3) / np.log(1 - 0.999))
vel = rand_vec3(min(ball_speed, BALL_MAX_SPEED / 3))
state_wrapper.ball.set_lin_vel(*vel)
ang_vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_ANG_VEL + 0.5))
state_wrapper.ball.set_ang_vel(*ang_vel)
if car.team_num == ORANGE_TEAM:
car.set_pos(
random.randint(-2900, 2900),
random.randint(3000, 5120),
17
)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
car.set_rot(
pitch=np.random.triangular(-PITCH_LIM, 0, PITCH_LIM),
yaw=np.random.uniform(-YAW_LIM, YAW_LIM),
roll=np.random.triangular(-ROLL_LIM, 0, ROLL_LIM),
)
ang_vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_ANG_VEL))
car.set_ang_vel(*ang_vel)
car.boost = np.random.uniform(0, 1)
class JumpShotState(StateSetter):
def __init__(self):
super().__init__()
def reset(self, state_wrapper: StateWrapper):
for car in state_wrapper.cars:
if car.team_num == BLUE_TEAM:
car.set_pos(
random.uniform(-4096, 4096),
random.uniform(0, 2500),
17
)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
car.set_rot(
pitch=0,
yaw=90,
roll=0
)
ang_vel = (0, 0, 0) # rand_vec3(np.random.triangular(0, 0, CAR_MAX_ANG_VEL))
car.set_ang_vel(*ang_vel)
car.boost = np.random.uniform(0, 1)
state_wrapper.ball.set_pos(
x=np.random.uniform(max(car.position.item(0) - 1000, -LIM_X),
min(car.position.item(0) + 1000, LIM_X)),
y=np.random.uniform(car.position.item(1) + 1500, car.position.item(1) + 500),
z=CEILING_Z / 2
)
ball_speed = np.random.uniform(100, BALL_MAX_SPEED / 2)
vel = rand_vec3(min(ball_speed, BALL_MAX_SPEED / 2))
state_wrapper.ball.set_lin_vel(*vel)
ang_vel = (0, 0, 0)
state_wrapper.ball.set_ang_vel(*ang_vel)
if car.team_num == ORANGE_TEAM:
car.set_pos(
random.randint(-2900, 2900),
random.randint(3000, 5120),
17
)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
car.set_rot(
pitch=np.random.triangular(-PITCH_LIM, 0, PITCH_LIM),
yaw=np.random.uniform(-YAW_LIM, YAW_LIM),
roll=np.random.triangular(-ROLL_LIM, 0, ROLL_LIM),
)
ang_vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_ANG_VEL))
car.set_ang_vel(*ang_vel)
car.boost = np.random.uniform(0, 1)
class SaveState(StateSetter):
def __init__(self):
super().__init__()
def reset(self, state_wrapper: StateWrapper):
for car in state_wrapper.cars:
if car.team_num == ORANGE_TEAM:
car.set_pos(
random.uniform(-4096, 4096),
random.uniform(0, -3000),
17
)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
car.set_rot(
pitch=np.random.triangular(-PITCH_LIM, 0, PITCH_LIM),
yaw=np.random.uniform(-YAW_LIM, YAW_LIM),
roll=np.random.triangular(-ROLL_LIM, 0, ROLL_LIM),
)
ang_vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_ANG_VEL))
car.set_ang_vel(*ang_vel)
car.boost = np.random.uniform(0, 1)
state_wrapper.ball.set_pos(
x=np.random.uniform(max(car.position.item(0) - 1000, -LIM_X),
min(car.position.item(0) + 1000, LIM_X)),
y=np.random.uniform(car.position.item(1) - 1000, car.position.item(1) - 100),
z=np.random.triangular(BALL_RADIUS, BALL_RADIUS, LIM_Z / 2),
)
ball_speed = np.random.exponential(-(BALL_MAX_SPEED / 3) / np.log(1 - 0.999))
vel = rand_vec3(min(ball_speed, BALL_MAX_SPEED / 3))
state_wrapper.ball.set_lin_vel(*vel)
ang_vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_ANG_VEL + 0.5))
state_wrapper.ball.set_ang_vel(*ang_vel)
if car.team_num == BLUE_TEAM:
car.set_pos(
random.randint(-2900, 2900),
-random.randint(3000, 5120),
17
)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
car.set_rot(
pitch=np.random.triangular(-PITCH_LIM, 0, PITCH_LIM),
yaw=np.random.uniform(-YAW_LIM, YAW_LIM),
roll=np.random.triangular(-ROLL_LIM, 0, ROLL_LIM),
)
ang_vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_ANG_VEL))
car.set_ang_vel(*ang_vel)
car.boost = np.random.uniform(0, 1)
class AirDribble2Touch(StateSetter):
def __init__(self):
super().__init__()
def reset(self, state_wrapper: StateWrapper):
for car in state_wrapper.cars:
if car.team_num == BLUE_TEAM:
car_x = random.randint(-3500, 3500)
car_y = random.randint(-2000, 4000)
car_z = np.random.uniform(500, LIM_Z)
car.set_pos(
car_x,
car_y,
car_z
)
car_pitch_rot = random.uniform(-1, 1) * math.pi
car_yaw_rot = random.uniform(-1, 1) * math.pi
car_roll_rot = random.uniform(-1, 1) * math.pi
car.set_rot(
car_pitch_rot,
car_yaw_rot,
car_roll_rot
)
car_lin_y = np.random.uniform(300, CAR_MAX_SPEED)
car.set_lin_vel(
0 + random.uniform(-150, 150),
car_lin_y,
0 + random.uniform(-150, 150)
)
state_wrapper.ball.set_pos(
car_x + random.uniform(-150, 150),
car_y + random.uniform(0, 150),
car_z + random.uniform(0, 150)
)
ball_lin_y = car_lin_y + random.uniform(-150, 150)
state_wrapper.ball.set_lin_vel(
0 + random.uniform(-150, 150),
ball_lin_y,
0 + random.uniform(-150, 150)
)
car.boost = np.random.uniform(0.4, 1)
else:
car.set_pos(
random.randint(-2900, 2900),
random.randint(3000, 5120),
17
)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
car.set_rot(
pitch=np.random.triangular(-PITCH_LIM, 0, PITCH_LIM),
yaw=np.random.uniform(-YAW_LIM, YAW_LIM),
roll=np.random.triangular(-ROLL_LIM, 0, ROLL_LIM),
)
ang_vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_ANG_VEL))
car.set_ang_vel(*ang_vel)
car.boost = np.random.uniform(0, 1)
class DefaultState(StateSetter):
SPAWN_BLUE_POS = [[-2048, -2560, 17], [2048, -2560, 17],
[-256, -3840, 17], [256, -3840, 17], [0, -4608, 17]]
SPAWN_BLUE_YAW = [0.25 * np.pi, 0.75 * np.pi,
0.5 * np.pi, 0.5 * np.pi, 0.5 * np.pi]
SPAWN_ORANGE_POS = [[2048, 2560, 17], [-2048, 2560, 17],
[256, 3840, 17], [-256, 3840, 17], [0, 4608, 17]]
SPAWN_ORANGE_YAW = [-0.75 * np.pi, -0.25 *
np.pi, -0.5 * np.pi, -0.5 * np.pi, -0.5 * np.pi]
def __init__(self):
super().__init__()
def reset(self, state_wrapper: StateWrapper):
rand_default_or_diff = random.randint(0, 3)
# rand_default_or_diff = 0
# DEFAULT KICKOFFS POSITIONS
if rand_default_or_diff == 0:
# possible kickoff indices are shuffled
spawn_inds = [0, 1, 2, 3, 4]
random.shuffle(spawn_inds)
blue_count = 0
orange_count = 0
for car in state_wrapper.cars:
pos = [0, 0, 0]
yaw = 0
# team_num = 0 = blue team
if car.team_num == 0:
# select a unique spawn state from pre-determined values
pos = self.SPAWN_BLUE_POS[spawn_inds[blue_count]]
yaw = self.SPAWN_BLUE_YAW[spawn_inds[blue_count]]
blue_count += 1
# team_num = 1 = orange team
elif car.team_num == 1:
# select a unique spawn state from pre-determined values
pos = self.SPAWN_ORANGE_POS[spawn_inds[orange_count]]
yaw = self.SPAWN_ORANGE_YAW[spawn_inds[orange_count]]
orange_count += 1
# set car state values
car.set_pos(*pos)
car.set_rot(yaw=yaw)
car.boost = 0.33
else:
"""SPAWN POS RANGE
Y = CENTER BACK KICKOFF [-4608, 0], [4608, 0]; BACK LEFT/RIGHT KICKOFFS [-3000, 0], [3000,0]"""
# print("Advanced Kickoffs")
# SPAWN POSITION
spawn_inds = [0, 1, 2, 3, 4]
spawn_pos = np.random.choice(spawn_inds)
same_pos = random.randint(0, 1)
# print(f"Same position = {same_pos}")
# RIGHT CORNER
if spawn_pos == 0:
# print("Right Corner")
# SAME POS
if same_pos == 1:
slope = -2560 / -2048
posX = np.random.uniform(-2048, 0)
posY = slope * posX
posZ = np.random.uniform(17, 200)
blue_spawn_pos = (posX, posY, posZ)
orange_spawn_pos = (abs(posX), abs(posY), posZ)
# print(f"Blue Spawn: {blue_spawn_pos} | Orange Spawn {orange_spawn_pos}")
for car in state_wrapper.cars:
final_pos = [0, 0, 0]
final_yaw = 0
if car.team_num == BLUE_TEAM:
final_pos = blue_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Blue Final Spawn: {final_pos} | Yaw: {final_yaw}")
elif car.team_num == ORANGE_TEAM:
final_pos = orange_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Orange Final Spawn: {final_pos} | Yaw: {final_yaw}")
car.set_pos(*final_pos)
car.set_rot(final_yaw)
car.boost = np.random.uniform(0, 0.4)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
else:
for car in state_wrapper.cars:
final_pos = [0, 0, 0]
final_yaw = 0
slope = -2560 / -2048
blue_posX = np.random.uniform(-2048, 0)
blue_posY = slope * blue_posX
posZ = np.random.uniform(17, 500)
blue_spawn_pos = (blue_posX, blue_posY, posZ)
slope = 2560 / 2048
orange_posX = np.random.uniform(2048, 0)
orange_posY = slope * orange_posX
posZ = np.random.uniform(17, 500)
orange_spawn_pos = (orange_posX, orange_posY, posZ)
if car.team_num == BLUE_TEAM:
final_pos = blue_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Blue Final Spawn: {final_pos} | Yaw: {final_yaw}")
elif car.team_num == ORANGE_TEAM:
final_pos = orange_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Orange Final Spawn: {final_pos} | Yaw: {final_yaw}")
car.set_pos(*final_pos)
car.set_rot(final_yaw)
car.boost = np.random.uniform(0, 0.4)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
# LEFT CORNER
elif spawn_pos == 1:
# print("Left Corner")
# SAME POS
if same_pos == 1:
slope = -2560 / 2048
posX = np.random.uniform(2048, 0)
posY = slope * posX
posZ = np.random.uniform(17, 500)
blue_spawn_pos = (posX, posY, posZ)
orange_spawn_pos = (-abs(posX), abs(posY), posZ)
# print(f"Blue Spawn: {blue_spawn_pos} | Orange Spawn {orange_spawn_pos}")
for car in state_wrapper.cars:
final_pos = [0, 0, 0]
final_yaw = 0
if car.team_num == BLUE_TEAM:
final_pos = blue_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Blue Final Spawn: {final_pos} | Yaw: {final_yaw}")
elif car.team_num == ORANGE_TEAM:
final_pos = orange_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Orange Final Spawn: {final_pos} | Yaw: {final_yaw}")
car.set_pos(*final_pos)
car.set_rot(final_yaw)
car.boost = np.random.uniform(0, 0.4)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
else:
for car in state_wrapper.cars:
final_pos = [0, 0, 0]
final_yaw = 0
slope = -2560 / 2048
blue_posX = np.random.uniform(2048, 0)
blue_posY = slope * blue_posX
posZ = np.random.uniform(17, 500)
blue_spawn_pos = (blue_posX, blue_posY, posZ)
slope = 2560 / -2048
orange_posX = np.random.uniform(-2048, 0)
orange_posY = slope * orange_posX
posZ = np.random.uniform(17, 500)
orange_spawn_pos = (orange_posX, orange_posY, posZ)
if car.team_num == BLUE_TEAM:
final_pos = blue_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Blue Final Spawn: {final_pos} | Yaw: {final_yaw}")
elif car.team_num == ORANGE_TEAM:
final_pos = orange_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Orange Final Spawn: {final_pos} | Yaw: {final_yaw}")
car.set_pos(*final_pos)
car.set_rot(final_yaw)
car.boost = np.random.uniform(0, 0.4)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
elif spawn_pos == 2:
# print("Back Right")
# SAME POS
if same_pos == 1:
slope = -3840 / -256
posX = np.random.uniform(-256, 0)
posY = slope * posX
posZ = np.random.uniform(17, 500)
if posY < -3000:
blue_spawn_pos = (posX, posY, posZ)
orange_spawn_pos = (abs(posX), abs(posY), posZ)
else:
blue_spawn_pos = (0, posY, posZ)
orange_spawn_pos = (0, abs(posY), posZ)
# print(f"Blue Spawn: {blue_spawn_pos} | Orange Spawn {orange_spawn_pos}")
for car in state_wrapper.cars:
final_pos = [0, 0, 0]
final_yaw = 0
if car.team_num == BLUE_TEAM:
final_pos = blue_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Blue Final Spawn: {final_pos} | Yaw: {final_yaw}")
elif car.team_num == ORANGE_TEAM:
final_pos = orange_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Orange Final Spawn: {final_pos} | Yaw: {final_yaw}")
car.set_pos(*final_pos)
car.set_rot(final_yaw)
car.boost = np.random.uniform(0, 0.4)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
else:
for car in state_wrapper.cars:
final_pos = [0, 0, 0]
final_yaw = 0
slope = -3840 / -256
blue_posX = np.random.uniform(-256, 0)
blue_posY = slope * blue_posX
posZ = np.random.uniform(17, 500)
if blue_posY < -3000:
blue_spawn_pos = (blue_posX, blue_posY, posZ)
else:
blue_spawn_pos = (0, blue_posY, posZ)
slope = 3840 / 256
orange_posX = np.random.uniform(256, 0)
orange_posY = slope * orange_posX
if orange_posX > 3000:
orange_spawn_pos = (orange_posX, orange_posY, posZ)
else:
orange_spawn_pos = (0, orange_posY, posZ)
if car.team_num == BLUE_TEAM:
final_pos = blue_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Blue Final Spawn: {final_pos} | Yaw: {final_yaw}")
elif car.team_num == ORANGE_TEAM:
final_pos = orange_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Orange Final Spawn: {final_pos} | Yaw: {final_yaw}")
car.set_pos(*final_pos)
car.set_rot(final_yaw)
car.boost = np.random.uniform(0, 0.4)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
elif spawn_pos == 3:
# print("Back Left")
# SAME POS
if same_pos == 1:
slope = -3840 / 256
posX = np.random.uniform(256, 0)
posY = slope * posX
posZ = np.random.uniform(17, 500)
if posY < -3000:
blue_spawn_pos = (posX, posY, posZ)
orange_spawn_pos = (-abs(posX), abs(posY), posZ)
else:
blue_spawn_pos = (posX, 0, 17)
orange_spawn_pos = (0, abs(posY), posZ)
# print(f"Blue Spawn: {blue_spawn_pos} | Orange Spawn {orange_spawn_pos}")
for car in state_wrapper.cars:
final_pos = [0, 0, 0]
final_yaw = 0
if car.team_num == BLUE_TEAM:
final_pos = blue_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Blue Final Spawn: {final_pos} | Yaw: {final_yaw}")
elif car.team_num == ORANGE_TEAM:
final_pos = orange_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Orange Final Spawn: {final_pos} | Yaw: {final_yaw}")
car.set_pos(*final_pos)
car.set_rot(final_yaw)
car.boost = np.random.uniform(0, 0.4)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
else:
for car in state_wrapper.cars:
final_pos = [0, 0, 0]
final_yaw = 0
slope = -3840 / 256
blue_posX = np.random.uniform(256, 0)
blue_posY = slope * blue_posX
posZ = np.random.uniform(17, 500)
if blue_posY < -3000:
blue_spawn_pos = (blue_posX, blue_posY, posZ)
else:
blue_spawn_pos = (0, blue_posY, posZ)
slope = 3840 / -256
orange_posX = np.random.uniform(-256, 0)
orange_posY = slope * orange_posX
posZ = np.random.uniform(17, 500)
if orange_posX > 3000:
orange_spawn_pos = (orange_posX, orange_posY, posZ)
else:
orange_spawn_pos = (0, orange_posY, posZ)
if car.team_num == BLUE_TEAM:
final_pos = blue_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Blue Final Spawn: {final_pos} | Yaw: {final_yaw}")
elif car.team_num == ORANGE_TEAM:
final_pos = orange_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Orange Final Spawn: {final_pos} | Yaw: {final_yaw}")
car.set_pos(*final_pos)
car.set_rot(final_yaw)
car.boost = np.random.uniform(0, 0.4)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
elif spawn_pos == 4:
# print("Far Back Center")
# SAME POS
if same_pos == 1:
posX = 0
posY = np.random.uniform(-4608, 0)
posZ = np.random.uniform(17, 500)
blue_spawn_pos = (posX, posY, posZ)
orange_spawn_pos = (posX, abs(posY), posZ)
# print(f"Blue Spawn: {blue_spawn_pos} | Orange Spawn {orange_spawn_pos}")
for car in state_wrapper.cars:
final_pos = [0, 0, 0]
final_yaw = 0
if car.team_num == BLUE_TEAM:
final_pos = blue_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Blue Final Spawn: {final_pos} | Yaw: {final_yaw}")
elif car.team_num == ORANGE_TEAM:
final_pos = orange_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Orange Final Spawn: {final_pos} | Yaw: {final_yaw}")
car.set_pos(*final_pos)
car.set_rot(final_yaw)
car.boost = np.random.uniform(0, 0.4)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
else:
for car in state_wrapper.cars:
final_pos = [0, 0, 0]
final_yaw = 0
blue_posX = 0
blue_posY = np.random.uniform(-4608, 0)
posZ = np.random.uniform(17, 500)
blue_spawn_pos = (blue_posX, blue_posY, posZ)
orange_posX = 0
orange_posY = np.random.uniform(4608, 0)
posZ = np.random.uniform(17, 500)
orange_spawn_pos = (orange_posX, orange_posY, posZ)
if car.team_num == BLUE_TEAM:
final_pos = blue_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Blue Final Spawn: {final_pos} | Yaw: {final_yaw}")
elif car.team_num == ORANGE_TEAM:
final_pos = orange_spawn_pos
final_yaw = random.uniform(-1, 1)
# print(f"Orange Final Spawn: {final_pos} | Yaw: {final_yaw}")
car.set_pos(*final_pos)
car.set_rot(final_yaw)
car.boost = np.random.uniform(0, 0.4)
vel = rand_vec3(np.random.triangular(0, 0, CAR_MAX_SPEED))
car.set_lin_vel(*vel)
class AirDribbleSetup(StateSetter):
def __init__(self):
super().__init__()
def reset(self, state_wrapper: StateWrapper):
axis_inverter = 1 if random.randrange(2) == 1 else -1
team_side = 0 if random.randrange(2) == 1 else 1
team_inverter = 1 if team_side == 0 else -1
# if only 1 play, team is always 0
ball_x_pos = 3000 * axis_inverter
ball_y_pos = random.randrange(7600) - 3800
ball_z_pos = BALL_RADIUS
state_wrapper.ball.set_pos(ball_x_pos, ball_y_pos, ball_z_pos)
ball_x_vel = (2000 + (random.randrange(1000) - 500)) * axis_inverter
ball_y_vel = random.randrange(1000) * team_inverter
ball_z_vel = 0
state_wrapper.ball.set_lin_vel(ball_x_vel, ball_y_vel, ball_z_vel)
chosen_car = [car for car in state_wrapper.cars if car.team_num == team_side][0]
# if randomly pick, chosen_car is from orange instead
car_x_pos = 2500 * axis_inverter
car_y_pos = ball_y_pos
car_z_pos = 27
yaw = 0 if axis_inverter == 1 else 180
car_pitch_rot = 0 * DEG_TO_RAD
car_yaw_rot = (yaw + (random.randrange(40) - 20)) * DEG_TO_RAD
car_roll_rot = 0 * DEG_TO_RAD
chosen_car.set_pos(car_x_pos, car_y_pos, car_z_pos)
chosen_car.set_rot(car_pitch_rot, car_yaw_rot, car_roll_rot)
chosen_car.boost = 100
for car in state_wrapper.cars:
if car is chosen_car:
continue
# set all other cars randomly in the field
car.set_pos(random.randrange(2944) - 1472, random.randrange(3968) - 1984, 0)
car.set_rot(0, (random.randrange(360) - 180) * (3.1415927 / 180), 0)
class NaNState(StateSetter):
def __init__(self):
super().__init__()
def reset(self, state_wrapper: StateWrapper):
state_wrapper.ball.set_pos(
x=1943.54,
y=-776.12,
z=406.78,
)
vel = (122.79422, -234.43246, 259.7227)
state_wrapper.ball.set_lin_vel(*vel)
ang_vel = (-0.11868675, 0.10540164, -0.05797875)
state_wrapper.ball.set_ang_vel(*ang_vel)
for car in state_wrapper.cars:
if car.team_num == 0:
car.set_pos(
x=1943.54,
y=-776.12,
z=406.78,
)
vel = (-303.3699951171875, -214.94998168945312, -410.7699890136719)
car.set_lin_vel(*vel)
car.set_rot(
pitch=np.random.triangular(-PITCH_LIM, 0, PITCH_LIM),
yaw=np.random.uniform(-YAW_LIM, YAW_LIM),
roll=np.random.triangular(-ROLL_LIM, 0, ROLL_LIM),
)
ang_vel = (-0.91367, -1.7385, 0.28524998)
car.set_ang_vel(*ang_vel)
car.boost = 0.593655776977539
else:
car.set_pos(
x=1917.4401,
y=-738.27997,
z=462.01,
)
vel = (142.98796579, 83.07732574, -20.63784965)
car.set_lin_vel(*vel)
car.set_rot(
pitch=np.random.triangular(-PITCH_LIM, 0, PITCH_LIM),
yaw=np.random.uniform(-YAW_LIM, YAW_LIM),
roll=np.random.triangular(-ROLL_LIM, 0, ROLL_LIM),
)
ang_vel = (-0.22647299, 0.10713767, 0.24121591)
car.set_ang_vel(*ang_vel)
car.boost = 0.8792996978759766
class SideHighRoll(StateSetter):
def __init__(self):
super().__init__()
def reset(self, state_wrapper: StateWrapper):
sidepick = random.randrange(2)
side_inverter = 1
if sidepick == 1:
# change side
side_inverter = -1
# MAGIC NUMBERS ARE FROM MANUAL CALIBRATION AND WHAT FEELS RIGHT
ball_x_pos = 3000 * side_inverter
ball_y_pos = random.randrange(1500) - 750
ball_z_pos = BALL_RADIUS
state_wrapper.ball.set_pos(ball_x_pos, ball_y_pos, ball_z_pos)
ball_x_vel = (2000 + random.randrange(1000) - 500) * side_inverter
ball_y_vel = random.randrange(1500) - 750
ball_z_vel = random.randrange(300)
state_wrapper.ball.set_lin_vel(ball_x_vel, ball_y_vel, ball_z_vel)
wall_car_blue = [car for car in state_wrapper.cars if car.team_num == 0][0]
# blue car setup
blue_pitch_rot = 0 * DEG_TO_RAD
blue_yaw_rot = 90 * DEG_TO_RAD
blue_roll_rot = 90 * side_inverter * DEG_TO_RAD
wall_car_blue.set_rot(blue_pitch_rot, blue_yaw_rot, blue_roll_rot)
blue_x = 4096 * side_inverter
blue_y = -2500 + (random.randrange(500) - 250)
blue_z = 600 + (random.randrange(400) - 200)
wall_car_blue.set_pos(blue_x, blue_y, blue_z)
wall_car_blue.boost = 100
# orange car setup
wall_car_orange = None
if len(state_wrapper.cars) > 1:
wall_car_orange = [car for car in state_wrapper.cars if car.team_num == 1][0]
# orange car setup
orange_pitch_rot = 0 * DEG_TO_RAD
orange_yaw_rot = -90 * DEG_TO_RAD
orange_roll_rot = -90 * side_inverter * DEG_TO_RAD
wall_car_orange.set_rot(orange_pitch_rot, orange_yaw_rot, orange_roll_rot)
orange_x = 4096 * side_inverter
orange_y = 2500 + (random.randrange(500) - 250)
orange_z = 400 + (random.randrange(400) - 200)
wall_car_orange.set_pos(orange_x, orange_y, orange_z)
wall_car_orange.boost = 100