MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / PvPMatrixEvaluator

Class PvPMatrixEvaluator

codeclash/analysis/matrix.py:21–320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19
20
21class PvPMatrixEvaluator:
22 def __init__(self, pvp_output_dir: Path, n_repetitions: int = 3, max_workers: int = 4):
23 self.pvp_output_dir = Path(pvp_output_dir)
24 self.n_repetitions = n_repetitions
25 self.max_workers = max_workers
26 self.metadata = json.loads((self.pvp_output_dir / "metadata.json").read_text())
27
28 assert len(self.players) == 2, f"Expected exactly 2 players, got {len(self.players)}"
29
30 # Set up logging with thread safety
31 self.logger = get_logger("MatrixEvaluator", log_path=self.pvp_output_dir / "matrix_eval.log", emoji="📊")
32 add_root_file_handler(self.pvp_output_dir / "matrix_everything.log")
33
34 # Thread safety for progress saving
35 self._save_lock = Lock()
36
37 # Initialize metadata similar to tournament class
38 self._metadata = {
39 "name": "MatrixEvaluator",
40 "pvp_output_dir": str(self.pvp_output_dir),
41 "p1_name": self.players[0],
42 "p2_name": self.players[1],
43 "rounds": self.rounds,
44 "n_repetitions": n_repetitions,
45 "max_workers": max_workers,
46 "created_timestamp": int(time.time()),
47 "matrices": {},
48 }
49
50 # Load existing progress if available
51 self._load_existing_progress()
52
53 # Initialize game pool and agent pools
54 self._initialize_game_pool()
55 self._initialize_agent_pools()
56
57 self.logger.info(f"Initialized matrix evaluator for {self.players[0]} vs {self.players[1]}")
58 self.logger.info(f"Will evaluate {self.rounds + 1} rounds with {n_repetitions} repetitions each")
59 self.logger.info(f"Using {max_workers} parallel workers")
60
61 # Quick access properties
62 # -----------------------
63
64 @property
65 def config(self) -> dict:
66 """Game configuration from PvP metadata."""
67 return self.metadata["config"]
68
69 @property
70 def rounds(self) -> int:
71 """Number of rounds actually evaluated, determined from round_stats in metadata."""
72 return len(self.metadata["round_stats"])
73
74 @property
75 def players(self) -> list[str]:
76 """List of player names from metadata."""
77 return [agent["name"] for agent in self.metadata["agents"]]
78

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected