File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import os
22import subprocess
3+ import time
34import traceback
45from abc import ABC , abstractmethod
56from collections import Counter
67from pathlib import Path
78from typing import Any
8- from uuid import uuid4
99
1010from minisweagent .environments .docker import DockerEnvironment
1111
@@ -26,7 +26,7 @@ def __init__(self, config: dict):
2626 self .config : dict = config ["game" ]
2727 self .rounds : int = self .config .get ("rounds" , 1 )
2828 self .round : int = 0
29- self .game_id : str = f"{ self .name } { uuid4 (). hex [: 6 ] } "
29+ self .game_id : str = f"{ self .name } { time . strftime ( '%y%m%d%H%M' ) } "
3030 self .log_path : Path = (DIR_WORK / DIR_LOGS / self .game_id ).resolve ()
3131 self .logger = get_logger (
3232 self .name , log_path = DIR_LOGS / self .game_id / "game.log" , emoji = "🏓"
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ def __init__(self, config):
1212 super ().__init__ (config )
1313 assert len (config ["players" ]) == 2 , "BattleCode is a two-player game"
1414 self .run_cmd_round : str = "python run.py run"
15- for arg , val in config .get ("args" , {}).items ():
15+ for arg , val in self . config .get ("args" , {}).items ():
1616 if isinstance (val , bool ):
1717 if val :
1818 self .run_cmd_round += f" --{ arg } "
@@ -36,6 +36,6 @@ def execute_round(self, agents: list[Any]):
3636 for idx , agent in enumerate (agents )
3737 ]
3838 cmd = f"{ self .run_cmd_round } { ' ' .join (args )} > { self .round_log_path } "
39- print (f"Running command: { cmd } " )
39+ self . logger . info (f"Running command: { cmd } " )
4040 response = self .environment .execute (cmd )
4141 assert response ["returncode" ] == 0 , response
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ class BattleSnakeGame(CodeGame):
1212 def __init__ (self , config ):
1313 super ().__init__ (config )
1414 self .run_cmd_round : str = "./battlesnake play"
15- for arg , val in config .get ("args" , {}).items ():
15+ for arg , val in self . config .get ("args" , {}).items ():
1616 if isinstance (val , bool ):
1717 if val :
1818 self .run_cmd_round += f" --{ arg } "
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ class CoreWarGame(CodeGame):
1010 def __init__ (self , config ):
1111 super ().__init__ (config )
1212 self .run_cmd_round : str = "./src/pmars"
13- for arg , val in config .get ("args" , {}).items ():
13+ for arg , val in self . config .get ("args" , {}).items ():
1414 if isinstance (val , bool ):
1515 if val :
1616 self .run_cmd_round += f" -{ arg } "
@@ -31,6 +31,6 @@ def determine_winner(self, agents: list[Player]):
3131 def execute_round (self , agents : list [Player ]):
3232 args = [f"/{ agent .name } /warriors/warrior.red" for agent in agents ]
3333 cmd = f"{ self .run_cmd_round } { ' ' .join (args )} > { self .round_log_path } "
34- print (f"Running command: { cmd } " )
34+ self . logger . info (f"Running command: { cmd } " )
3535 response = self .environment .execute (cmd )
3636 assert response ["returncode" ] == 0 , response
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ class RoboCodeGame(CodeGame):
1111 def __init__ (self , config ):
1212 super ().__init__ (config )
1313 self .run_cmd_round : str = "./robocode.sh"
14- for arg , val in config .get ("args" , {}).items ():
14+ for arg , val in self . config .get ("args" , {}).items ():
1515 if isinstance (val , bool ):
1616 if val :
1717 self .run_cmd_round += f" -{ arg } "
@@ -84,6 +84,6 @@ def execute_round(self, agents: list[Player]):
8484 cmd = (
8585 f"{ self .run_cmd_round } -battle { battle_file } -results { self .round_log_path } "
8686 )
87- print (f"Running command: { cmd } " )
87+ self . logger . info (f"Running command: { cmd } " )
8888 response = self .environment .execute (cmd )
8989 assert response ["returncode" ] == 0 , response
Original file line number Diff line number Diff line change @@ -23,6 +23,6 @@ def determine_winner(self, agents: list[Player]):
2323 def execute_round (self , agents : list [Player ]):
2424 args = [f"/{ agent .name } /robot.py" for agent in agents ]
2525 cmd = f"{ self .run_cmd_round } { ' ' .join (args )} > { self .round_log_path } "
26- print (f"Running command: { cmd } " )
26+ self . logger . info (f"Running command: { cmd } " )
2727 response = self .environment .execute (cmd )
2828 assert response ["returncode" ] == 0 , response
You can’t perform that action at this time.
0 commit comments