|
| 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