-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
64 lines (53 loc) · 1.89 KB
/
Copy pathrun.py
File metadata and controls
64 lines (53 loc) · 1.89 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import logging
import multiprocessing
import json
import importlib
from match import run_api_match
def load_agent_class(file_path):
"""
Dynamically imports and returns an agent class from a string path.
Example: 'agents.test_agents.AllInAgent' -> AllInAgent class
"""
module_path, class_name = file_path.rsplit('.', 1)
module = importlib.import_module(module_path)
return getattr(module, class_name)
def main():
# Load configuration
with open('agent_config.json', 'r') as f:
config = json.load(f)
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)
# Load agent classes dynamically
bot0_class = load_agent_class(config['bot0']['file_path'])
bot1_class = load_agent_class(config['bot1']['file_path'])
# Create processes using the configuration (stream=True so agent logs appear in console)
# To disable agent logs, set stream=False
process0 = multiprocessing.Process(
target=bot0_class.run,
args=(True, config['bot0']['port']),
kwargs={"player_id": config['bot0']['player_id']}
)
process1 = multiprocessing.Process(
target=bot1_class.run,
args=(True, config['bot1']['port']),
kwargs={"player_id": config['bot1']['player_id']}
)
process0.start()
process1.start()
logger.info("Starting API-based match")
result = run_api_match(
f"http://localhost:{config['bot0']['port']}",
f"http://localhost:{config['bot1']['port']}",
logger,
csv_path=config['match_settings']['csv_output_path'],
team_0_name=bot0_class.__name__,
team_1_name=bot1_class.__name__
)
logger.info(f"Match result: {result}")
# Clean up processes
process0.terminate()
process1.terminate()
process0.join()
process1.join()
if __name__ == "__main__":
main()