Source code in codeclash/arenas/huskybench/huskybench.py
242526272829303132333435363738
def__init__(self,config,**kwargs):super().__init__(config,**kwargs)self.num_players:int=len(config["players"])self.run_engine:str=(f"python engine/main.py --port {HB_PORT} --players {self.num_players} "f"--sim --sim-rounds {self.game_config['sims_per_round']}")# Game timeout is number of sims * bot timeoutself.timeout=self.game_config["sims_per_round"]*HB_BOT_TIMEOUTforarg,valinself.game_config.get("args",self.default_args).items():ifisinstance(val,bool):ifval:self.run_engine+=f" --{arg}"else:self.run_engine+=f" --{arg}{val}"
nameclass-attributeinstance-attribute
name:str='HuskyBench'
descriptionclass-attributeinstance-attribute
description:str=f'In this game, you will write code to control a poker-playing bot, aiming to outsmart your opponents and win chips.Victorycomesfromcraftingcleverstrategies—bluffing,readingopponents,andmanagingyourchipstackeffectively.Bemindfulofyourbot's efficiency - your code should complete a simulation within 10 seconds to avoid forfeiting the round.Youcanuse{HB_SCRIPT}tocheckifyourbotrunsintime.'
defget_results(self,agents:list[Player],round_num:int,stats:RoundStats):map_id_to_agent={}foragentinagents:withopen(self.log_round(round_num)/f"{agent.name}.log")asf:forlineinf:if"Connected with player ID: "inline:agent_id=line.strip().split()[-1]map_id_to_agent[agent_id]=agent.namebreakself.logger.info("Agent IDs: "+str(map_id_to_agent))withopen(self.log_round(round_num)/HB_LOG_ENGINE)asf:score_updates=[(match.group(1),int(match.group(2)))forlinf.readlines()if(match:=HB_REGEX_SCORE.search(l))]map_id_to_score={k:vfork,vinscore_updates[-self.num_players:]}self.logger.info("Final Scores: "+str(map_id_to_score))scores={map_id_to_agent[agent_id]:scoreforagent_id,scoreinmap_id_to_score.items()}stats.winner=max(scores,key=scores.get)stats.scores=scoresforplayer,scoreinscores.items():stats.player_stats[player].score=score
defvalidate_code(self,agent:Player)->tuple[bool,str|None]:assets=agent.environment.execute("ls client")["output"]if"main.py"notinassets:returnFalse,"There should be a `client/main.py` file"if"player.py"notinassets:returnFalse,"There should be a `client/player.py` file"# Make sure bot can run (check against itself)run_engine=(self.run_engine.replace(f"--sim-rounds {self.game_config['sims_per_round']}","--sim-rounds 1")+" &")run_client="python client/main.py --port {port} &"script=self._construct_game_script([agent,agent],run_client,run_engine,verbose=False)self.logger.info(f"Validating agent {agent.name} with script:\n{script}")create_file_in_container(container=agent.environment,content=script,dest_path=DIR_WORK/HB_SCRIPT)try:agent.environment.execute(f"chmod +x {HB_SCRIPT}; ./{HB_SCRIPT}",timeout=HB_BOT_TIMEOUT)exceptsubprocess.TimeoutExpired:return(False,f"Your submission did not successfully complete a single round of poker within "f"the {HB_BOT_TIMEOUT} second time limit.\n\n""Please reduce your bot's computation time. ""It might also be possible that your code has compilation errors.\n\n"f"Validation command run: `./{HB_SCRIPT}`",)returnTrue,None