33
44from codeclash .agents .player import Player
55from codeclash .games .game import CodeGame , RoundStats
6- from codeclash .utils .environment import copy_from_container
76
8- HB_LOG_DIR = Path ( "/testbed/ engine/logs/" )
7+ HB_LOG_ENGINE = " engine.log"
98HB_REGEX_SCORE = re .compile (r"Player\s(\d+)\sdelta\supdated\:[\d\s\-\+\=]+,\smoney\:\s\d+\s\-\>\s(\d+)" )
109
1110
@@ -26,26 +25,17 @@ def __init__(self, config, *, tournament_id: str, local_output_dir: Path):
2625 else :
2726 self .run_cmd_round += f" --{ arg } { val } "
2827
29- def copy_logs_from_env (self , round_num ):
30- super ().copy_logs_from_env (round_num )
31- log_path = self .log_round (round_num )
32- copy_from_container (
33- container = self .environment ,
34- src_path = HB_LOG_DIR ,
35- dest_path = log_path ,
36- )
37-
38- def get_stats (self , agents : list [Player ], round_num : int ) -> RoundStats :
28+ def get_results (self , agents : list [Player ], round_num : int ) -> RoundStats :
3929 map_id_to_agent = {}
4030 for agent in agents :
41- with open (self .log_round (round_num ) / f"logs/ { agent .name } .log" ) as f :
31+ with open (self .log_round (round_num ) / f"{ agent .name } .log" ) as f :
4232 for line in f :
4333 if line .startswith ("My id:" ):
4434 agent_id = line .strip ().split ()[- 1 ]
4535 map_id_to_agent [agent_id ] = agent .name
4636 self .logger .info ("Agent IDs: " + str (map_id_to_agent ))
4737
48- with open (self .log_round (round_num ) / "logs/engine.log" ) as f :
38+ with open (self .log_round (round_num ) / HB_LOG_ENGINE ) as f :
4939 score_updates = [
5040 (match .group (1 ), int (match .group (2 ))) for l in f .readlines () if (match := HB_REGEX_SCORE .search (l ))
5141 ]
@@ -55,13 +45,12 @@ def get_stats(self, agents: list[Player], round_num: int) -> RoundStats:
5545 return RoundStats (winner = max (agent_to_score , key = agent_to_score .get ), scores = agent_to_score )
5646
5747 def execute_round (self , agents : list [Player ]):
58- self .environment .execute (f"rm -rf { HB_LOG_DIR } ; mkdir -p { HB_LOG_DIR } " )
5948 try :
60- cmd = f"{ self .run_cmd_round } > { HB_LOG_DIR / 'engine.log' } &"
49+ cmd = f"{ self .run_cmd_round } > { self . log_env / HB_LOG_ENGINE } &"
6150 self .logger .debug (f"Starting game engine with command: { cmd } " )
6251 self .environment .execute (cmd )
6352 for agent in agents :
64- cmd = f"python client/main.py --port 8000 > { HB_LOG_DIR / f'{ agent .name } .log' } &"
53+ cmd = f"python client/main.py --port 8000 > { self . log_env / f'{ agent .name } .log' } &"
6554 self .logger .debug (f"Adding agent with command: { cmd } " )
6655 self .environment .execute (cmd , cwd = f"/{ agent .name } " )
6756 finally :
0 commit comments