-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathsequence.py
More file actions
49 lines (38 loc) · 1.45 KB
/
sequence.py
File metadata and controls
49 lines (38 loc) · 1.45 KB
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
from dataclasses import dataclass
from typing import List
from rlbot.agents.base_agent import SimpleControllerState
from rlbot.utils.structures.game_data_struct import GameTickPacket
@dataclass
class StepResult:
controls: SimpleControllerState
done: bool
class Step:
def tick(self, packet: GameTickPacket) -> StepResult:
raise NotImplementedError
class ControlStep(Step):
def __init__(self, duration: float, controls: SimpleControllerState):
self.duration = duration
self.controls = controls
self.start_time: float = None
def tick(self, packet: GameTickPacket) -> StepResult:
if self.start_time is None:
self.start_time = packet.game_info.seconds_elapsed
elapsed_time = packet.game_info.seconds_elapsed - self.start_time
return StepResult(controls=self.controls, done=elapsed_time > self.duration)
class Sequence:
def __init__(self, steps: List[Step]):
self.steps = steps
self.index = 0
self.done = False
def tick(self, packet: GameTickPacket):
while True:
if self.index >= len(self.steps):
self.done = True
return SimpleControllerState()
step = self.steps[self.index]
result = step.tick(packet)
if result.done:
self.index += 1
if self.index >= len(self.steps):
self.done = True
return result.controls