2424class CodeGame (ABC ):
2525 name : str
2626
27- def __init__ (self , config : dict ):
27+ def __init__ (self , config : dict , * , push_agent : bool = False ):
2828 self .url_gh : str = f"git@github.com:{ GH_ORG } /{ self .name } .git"
2929 self .artifacts : list [Path ] = []
3030 """Artifact objects that we might want to clean up after the game."""
3131 self .scoreboard : list [tuple [int , str ]] = []
3232 """List of (round number, winner (player id))"""
3333 self .game_config : dict = config ["game" ]
3434 self .config : dict = config
35+ self .push_agent : bool = push_agent
3536 self .rounds : int = self .game_config .get ("rounds" , 1 )
3637 self .round : int = 0
3738 self .game_id : str = f"{ self .name } { time .strftime ('%y%m%d%H%M%S' )} "
@@ -43,6 +44,13 @@ def __init__(self, config: dict):
4344 self .environment : DockerEnvironment = self .get_environment ()
4445 assert len (config ["players" ]) >= 2 , "At least two players are required"
4546
47+ # Initialize agents
48+ from codeclash .agents import get_agent
49+
50+ self .agents : list [Player ] = []
51+ for agent_conf in config ["players" ]:
52+ self .agents .append (get_agent (agent_conf , config ["prompts" ], self ))
53+
4654 @property
4755 def image_name (self ) -> str :
4856 return f"codeclash/{ self .name .lower ()} "
@@ -192,6 +200,21 @@ def _post_round_setup(self, agents: list[Player]):
192200 )
193201 self .logger .info (f"Round { self .round } completed." )
194202
203+ def run (self , cleanup : bool = False ):
204+ """
205+ Run the full game with all configured agents.
206+ """
207+ try :
208+ for _ in range (self .rounds ):
209+ self .run_round (self .agents )
210+ for agent in self .agents :
211+ agent .run ()
212+ finally :
213+ self .end (cleanup )
214+ if self .push_agent :
215+ for agent in self .agents :
216+ agent .push ()
217+
195218 def run_round (self , agents : list [Player ]):
196219 """
197220 Run a single round of the game with the given agents.
0 commit comments