44
55from codeclash .agents import get_agent
66from codeclash .agents .abstract import Player
7+ from codeclash .agents .utils import GameContext
8+ from codeclash .constants import DIR_WORK
79from codeclash .games import get_game
810from codeclash .games .abstract import CodeGame
911from codeclash .tournaments .abstract import AbstractTournament
@@ -24,13 +26,38 @@ def __init__(
2426 )
2527 self .agents : list [Player ] = []
2628 for agent_conf in self .config ["players" ]:
27- self .agents .append (get_agent (agent_conf , self .config ["prompts" ], self . game ))
29+ self .agents .append (self . get_agent (agent_conf , self .config ["prompts" ]))
2830 self .logger = get_logger (self .game .name )
31+ self .scoreboard : list [tuple [int , str ]] = []
32+
33+ @property
34+ def rounds (self ) -> int :
35+ return self .config ["game" ]["rounds" ]
36+
37+ def get_agent (self , agent_config : dict , prompts : dict ) -> Player :
38+ """Create an agent with environment and game context."""
39+ environment = self .game .get_environment (
40+ f"{ self .game .game_id } .{ agent_config ['name' ]} "
41+ )
42+
43+ game_context = GameContext (
44+ id = self .game .game_id ,
45+ log_env = self .game .log_env ,
46+ log_local = self .game .log_local ,
47+ name = self .game .name ,
48+ player_id = agent_config ["name" ],
49+ prompts = prompts ,
50+ round = 1 ,
51+ rounds = self .rounds ,
52+ working_dir = str (DIR_WORK ),
53+ )
54+
55+ return get_agent (agent_config , game_context , environment )
2956
3057 def run (self ) -> None :
3158 """Main execution function that runs all rounds."""
3259 try :
33- for round_num in range (1 , self .game . rounds + 1 ):
60+ for round_num in range (1 , self .rounds + 1 ):
3461 self .run_training_round (round_num )
3562 finally :
3663 self .cleanup ()
@@ -44,7 +71,7 @@ def run_training_round(self, round_num: int) -> None:
4471 winner = result ["winner" ]
4572
4673 # Handle bookkeeping that was previously in the game
47- self .game . scoreboard .append ((round_num , winner ))
74+ self .scoreboard .append ((round_num , winner ))
4875 self .logger .info (f"Round { round_num } winner: { winner } " )
4976
5077 # Write log to file
0 commit comments