-
Notifications
You must be signed in to change notification settings - Fork 1
/
agent.py
78 lines (57 loc) · 2.65 KB
/
agent.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
import math
import random
from rlbot.agents.base_agent import BaseAgent, SimpleControllerState
from rlbot.utils.structures.game_data_struct import GameTickPacket
from rlbot.utils.game_state_util import GameState, BallState, CarState, Physics, Vector3, Rotator
from RLUtilities.GameInfo import GameInfo
from RLUtilities.Simulation import Car, Ball
from RLUtilities.LinearAlgebra import vec3, dot
from RLUtilities.Maneuvers import AerialTurn
class Agent(BaseAgent):
def __init__(self, name, team, index):
self.index = index
self.info = GameInfo(index, team)
self.controls = SimpleControllerState()
self.timer = 0.0
self.action = None
def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
self.info.read_packet(packet)
self.controls = SimpleControllerState()
if self.timer < 0.05:
position = Vector3(random.uniform(-4000, 4000),
random.uniform(-3000, 3000),
random.uniform( 500, 2000))
velocity = Vector3(random.uniform(-1500, 1500),
random.uniform(-1500, 1500),
random.uniform(-1000, -500))
rotation = Rotator(random.uniform(-1.5, 1.5),
random.uniform(-1.5, 1.5),
random.uniform(-1.5, 1.5))
angular_velocity = Vector3(random.uniform(-3.0, 3.0),
random.uniform(-3.0, 3.0),
random.uniform(-3.0, 3.0))
car_state = CarState(physics=Physics(
location=position,
velocity=velocity,
rotation=rotation,
angular_velocity=angular_velocity
))
self.set_game_state(GameState(cars={self.index: car_state}))
if self.timer > 0.10:
if self.action == None:
self.action = AerialTurn(self.info.my_car)
self.renderer.begin_rendering()
red = self.renderer.create_color(255, 255, 30, 30)
self.renderer.draw_polyline_3d(self.action.trajectory, red)
self.renderer.end_rendering()
self.action.step(1.0 / 60.0)
self.controls = self.action.controls
self.timer += 1.0 / 60.0
if self.action.finished or self.timer > 5.0:
print("target:\n", self.action.target)
print("theta:\n", self.action.car.theta)
print()
self.timer = 0.0
self.action = None
self.timer += 1.0 / 60.0
return self.controls