Skip to content

Commit 68c3909

Browse files
committed
Infinite match series testing
1 parent 239215a commit 68c3909

File tree

3 files changed

+91
-18
lines changed

3 files changed

+91
-18
lines changed

tests/atba/atba.bot.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ root_dir = ""
1414
run_command = "..\\..\\venv\\Scripts\\python atba.py"
1515
# The command RLBot will call to start your bot on linux
1616
# If this isn't set, RLBot may attempt to run the Windows command under Wine
17-
run_command_linux = "../../venv/bin/python atba.py"
17+
run_command_linux = "../../.venv/bin/python atba.py"
1818

1919
[details]
2020
description = "Made possible by RLBot"

tests/atba/atba.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import math
4-
from typing import Optional
54

65
from rlbot import flat
76
from rlbot.managers import Bot
@@ -67,9 +66,9 @@ def __init__(self):
6766

6867
def initialize(self):
6968
self.logger.info("Initializing agent!")
70-
71-
num_boost_pads = len(self.field_info.boost_pads)
72-
self.logger.info(f"There are {num_boost_pads} boost pads on the field.")
69+
self.logger.info(
70+
f"There are {len(self.field_info.boost_pads)} boost pads and {len(self.field_info.goals)} goals on the field."
71+
)
7372

7473
if self.rendering:
7574
self.renderer.begin_rendering("custom one-time rendering group")
@@ -83,16 +82,6 @@ def initialize(self):
8382
)
8483
self.renderer.end_rendering()
8584

86-
def handle_match_comm(
87-
self,
88-
index: int,
89-
team: int,
90-
content: bytes,
91-
display: Optional[str],
92-
team_only: bool,
93-
):
94-
self.logger.info(f"Received match communication from index {index}! {display}")
95-
9685
def get_output(self, packet: flat.GamePacket) -> flat.ControllerState:
9786
if self.rendering:
9887
self.test_rendering(packet)
@@ -110,10 +99,10 @@ def get_output(self, packet: flat.GamePacket) -> flat.ControllerState:
11099
if self.state_setting:
111100
self.test_state_setting(packet)
112101

113-
if self.match_comms:
102+
if self.match_comms and packet.match_info.match_phase == flat.MatchPhase.Active:
114103
# Limit packet spam
115104
if packet.match_info.frame_num - self.last_send >= 360:
116-
self.send_match_comm(b"", "Hello world!", True)
105+
self.send_match_comm(b"", "Hello world!", False)
117106
self.last_send = packet.match_info.frame_num
118107

119108
ball_location = Vector2(packet.balls[0].physics.location)
@@ -145,7 +134,7 @@ def test_state_setting(self, packet: flat.GamePacket):
145134
i: flat.DesiredCarState(
146135
flat.DesiredPhysics(rotation=flat.RotatorPartial(yaw=0))
147136
)
148-
for i, car in enumerate(packet.players)
137+
for i in range(len(packet.players))
149138
},
150139
)
151140

tests/many_match.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from pathlib import Path
2+
from time import sleep
3+
4+
from rlbot import flat
5+
from rlbot.config import load_player_config
6+
from rlbot.managers import MatchManager
7+
8+
DIR = Path(__file__).parent
9+
10+
BOT_PATH = DIR / "atba/atba.bot.toml"
11+
RLBOT_SERVER_FOLDER = DIR / "../../core/RLBotCS/bin/Release/"
12+
13+
num_comms = set()
14+
15+
16+
def handle_match_comm(comm: flat.MatchComm):
17+
global num_comms
18+
if comm.team < 2:
19+
num_comms.add(comm.index)
20+
21+
22+
if __name__ == "__main__":
23+
match_manager = MatchManager(RLBOT_SERVER_FOLDER)
24+
match_manager.rlbot_interface.match_comm_handlers.append(handle_match_comm)
25+
match_manager.ensure_server_started()
26+
match_manager.connect(
27+
wants_match_communications=True,
28+
wants_ball_predictions=False,
29+
close_between_matches=False,
30+
)
31+
32+
current_map = -1
33+
34+
blue_bot = load_player_config(BOT_PATH, 0)
35+
orange_bot = load_player_config(BOT_PATH, 1)
36+
37+
match_settings = flat.MatchConfiguration(
38+
launcher=flat.Launcher.Steam,
39+
auto_start_agents=True,
40+
wait_for_agents=True,
41+
existing_match_behavior=flat.ExistingMatchBehavior.Restart,
42+
game_map_upk="Stadium_P",
43+
instant_start=True,
44+
enable_state_setting=True,
45+
player_configurations=[
46+
blue_bot,
47+
blue_bot,
48+
blue_bot,
49+
blue_bot,
50+
blue_bot,
51+
orange_bot,
52+
orange_bot,
53+
orange_bot,
54+
orange_bot,
55+
orange_bot,
56+
],
57+
)
58+
59+
num_games = 0
60+
paused = False
61+
62+
while not paused:
63+
num_games += 1
64+
print(f"Starting match # {num_games}")
65+
66+
match_manager.start_match(match_settings, ensure_server_started=False)
67+
# when calling start_match, by default it will wait for the first packet
68+
assert match_manager.packet is not None
69+
70+
sleep(2)
71+
num_comms.clear()
72+
while len(num_comms) < 10:
73+
# give an extra 5 seconds for the match to start before calling it a failure
74+
if (
75+
match_manager.packet.match_info.match_phase == flat.MatchPhase.Active
76+
and match_manager.packet.match_info.game_time_remaining < 60 * 4 + 55
77+
):
78+
match_manager.set_game_state(commands=["Pause"])
79+
paused = True
80+
break
81+
sleep(1)
82+
83+
print("Failed to start match. Paused and exiting.")
84+
match_manager.disconnect()

0 commit comments

Comments
 (0)