33from typing import Any
44
55from codeclash .games .abstract import CodeGame
6+ from codeclash .utils .environment import assert_zero_exit_code
67
78
89class BattleSnakeGame (CodeGame ):
@@ -19,7 +20,9 @@ def __init__(self, config):
1920 self .run_cmd_round += f" --{ arg } { val } "
2021
2122 def determine_winner (self , agents : list [Any ]):
22- response = self .environment .execute (f"tail -1 { self .round_log_path } " )
23+ response = assert_zero_exit_code (
24+ self .environment .execute (f"tail -1 { self .round_log_path } " )
25+ )
2326 winner = json .loads (response ["output" ].strip ("\n " ))["winnerName" ]
2427 self .scoreboard .append ((self .round , winner ))
2528
@@ -39,12 +42,14 @@ def execute_round(self, agents: list[Any]):
3942 cmd = " " .join (cmd )
4043 print (f"Running command: { cmd } " )
4144
45+ # todo: should probably keep output somewhere?
4246 try :
43- response = self .environment .execute (
44- f"{ self .run_cmd_round } { cmd } " ,
45- cwd = f"{ self .environment .config .cwd } /game" ,
47+ assert_zero_exit_code (
48+ self .environment .execute (
49+ f"{ self .run_cmd_round } { cmd } " ,
50+ cwd = f"{ self .environment .config .cwd } /game" ,
51+ )
4652 )
47- assert response ["returncode" ] == 0 , response
4853 finally :
4954 # Kill all python servers when done
5055 self .environment .execute ("pkill -f 'python main.py' || true" )
0 commit comments