88
99from minisweagent .environments .docker import DockerEnvironment
1010
11+ from codeclash .agents .abstract import Player
1112from codeclash .constants import DIR_LOGS , DIR_WORK , GH_ORG
1213from codeclash .games .utils import copy_between_containers
14+ from codeclash .utils .environment import assert_zero_exit_code
1315
1416
1517class CodeGame (ABC ):
@@ -84,13 +86,10 @@ def get_environment(self, branch_name: str | None = None) -> DockerEnvironment:
8486 'git config --global user.name "Player"' ,
8587 "git config --global commit.gpgsign false" ,
8688 ]:
87- out = environment .execute (cmd )
88- if out .get ("returncode" , 0 ) != 0 :
89- msg = f"Failed to execute command: { cmd } . Output so far:\n { out .get ('output' )} "
90- raise RuntimeError (msg )
89+ assert_zero_exit_code (environment .execute (cmd ))
9190 return environment
9291
93- def _pre_round_setup (self , agents : list [Any ]):
92+ def _pre_round_setup (self , agents : list [Player ]):
9493 """Copy agent codebases into game's container and make round log file"""
9594 self .round += 1
9695 print (f"▶️ Running { self .name } round { self .round } ..." )
@@ -105,20 +104,20 @@ def _pre_round_setup(self, agents: list[Any]):
105104 )
106105
107106 # Ensure the log path + file exists
108- self .environment .execute (f"mkdir -p { self .log_path } " )
109- self .environment .execute (f"touch { self .round_log_path } " )
107+ assert_zero_exit_code ( self .environment .execute (f"mkdir -p { self .log_path } " ) )
108+ assert_zero_exit_code ( self .environment .execute (f"touch { self .round_log_path } " ) )
110109
111110 @abstractmethod
112- def determine_winner (self , agents : list [Any ]) -> Any :
111+ def determine_winner (self , agents : list [Player ]) -> Any :
113112 """Determine the winner of the game based on the round results, updates scoreboard"""
114113 pass
115114
116115 @abstractmethod
117- def execute_round (self , agents : list [Any ]):
116+ def execute_round (self , agents : list [Player ]):
118117 """Subclasses implement their game-specific logic here, must write results to round_log_path"""
119118 pass
120119
121- def _post_round_setup (self , agents : list [Any ]):
120+ def _post_round_setup (self , agents : list [Player ]):
122121 for agent in agents :
123122 copy_between_containers (
124123 self .environment ,
@@ -129,7 +128,7 @@ def _post_round_setup(self, agents: list[Any]):
129128 print (f"Copied round log to { agent .name } 's container." )
130129 print (f"Round { self .round } completed." )
131130
132- def run_round (self , agents : list [Any ]):
131+ def run_round (self , agents : list [Player ]):
133132 """
134133 Run a single round of the game with the given agents.
135134
0 commit comments