generated from nobleans-playground/coding-challenge-racer-bot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
36 lines (28 loc) · 910 Bytes
/
bot.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
from typing import Tuple
from pygame import Vector2
from ...bot import Bot
from ...linear_math import Transform
class PaulBot(Bot):
@property
def name(self):
return "ReverseEngineer"
@property
def contributor(self):
return "Paul"
def compute_commands(self, next_waypoint: int, position: Transform, velocity: Vector2) -> Tuple:
target = self.track.lines[next_waypoint]
# calculate the target in the frame of the robot
target = position.inverse() * target
# calculate the angle to the target
angle = target.as_polar()[1]
# calculate the throttle
target_velocity = 50
if velocity.length() < target_velocity:
throttle = -1
else:
throttle = 1
# calculate the steering
if angle > 0:
return throttle, -1
else:
return throttle, 1