-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcedure.py
73 lines (47 loc) · 2.39 KB
/
Procedure.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
from util import *
def pre_process(self, game): #Turns gamepacket into more useful values
self.game = game
self.player = game.gamecars[self.index]
self.ball = game.gameball
# converting vector3 and rotator classes into numpy arrays
self.player_loc = a3(self.player.Location)
self.player_vel = a3(self.player.Velocity)
self.player_rot = a3(self.player.Rotation)
self.player_angvel = a3(self.player.AngularVelocity)
self.ball_loc = a3(self.ball.Location)
self.ball_vel = a3(self.ball.Velocity)
if not hasattr(self, 'counter'):
self.counter = 0
self.throttle = self.steer = self.pitch = self.yaw = self.roll = self.jump = self.boost = self.powerslide = 0
self.target_loc = self.player_loc
self.desired_speed = MAX_CAR_SPEED
self.throttle_type = "point"
feedback(self)
# converting the veloctites to local coordinates
self.pitch_vel, self.roll_vel, self.yaw_vel = local(self.player_angvel, ZEROS3, self.player_rot)
self.player_local_vel = local(self.player_vel, ZEROS3, self.player_rot)
self.player_vel_mag, self.player_vel_yaw_ang, self.player_vel_pitch_ang = spherical(*self.player_local_vel)
# approximate turning radius
self.player_radius = turning_radius(dist2d(self.player_local_vel))
self.color = -sign(self.player.Team)
self.goal = a3([0, FIELD_LENGTH / 2 * self.color, 0])
def feedback(self):
self.last_throttle, self.last_steer = self.throttle, self.steer
self.last_pitch, self.last_yaw, self.last_roll = self.pitch, self.yaw, self.roll
self.last_jump, self.last_boost, self.last_powersilde = self.jump, self.boost, self.powerslide
self.counter += 1
def finish(self):
if self.counter % 2:#Just throttles the GUI to maintain FPS of the actual bot code
self.gui.update(self.game, self)
#Some paths are dynamic, meaning they change depending on the game conditions
#This is where the path is updated from
self.path.update(self)
#An old method for deleting a user-drawn path after it has been completed
'''
if len(self.path.lines) != 0 and hasattr(self, "line"):
if dist3d(self.player_loc, self.line.start) < 99:
self.line.started = True
if self.line.started and dist2d(self.player_loc, self.line.end) < 99:
self.line.finished = True
self.path.delete(self)
'''