feat(snake): modularize engine and add tournament tools
- Split active strategies, reusable engine code, core classes, and legacy snakes. - Replace implicit snake imports with explicit module registrations. - Extract Prism duel, spatial, and survival behavior into focused mixins. - Improve duel scoring with food races, pressure, caches, and depth metrics. - Add deterministic arena scenarios and paired seeded engine tournaments. - Expand benchmark telemetry and bump Prism to version 1.3.0. - Update documentation and tests for the new package layout and tooling.
This commit is contained in:
+46
-25
@@ -1,40 +1,61 @@
|
||||
import importlib
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class SnakeRegistration:
|
||||
module: str
|
||||
version: str
|
||||
|
||||
SNAKE_REGISTRATIONS = {
|
||||
"TemplateSnake": SnakeRegistration("snakes.core.template", "1.0.0"),
|
||||
"ApexBattleSnake": SnakeRegistration("snakes.strategies.apex", "1.0.0"),
|
||||
"PrismBattleSnake_GPT_5_6_Sol": SnakeRegistration(
|
||||
"snakes.strategies.prism", "1.3.0"
|
||||
),
|
||||
"DummSnake": SnakeRegistration("snakes.legacy.DummSnake", "1.0.0"),
|
||||
"LogicSnake": SnakeRegistration("snakes.legacy.LogicSnake", "1.1.0"),
|
||||
"MasterSnake": SnakeRegistration("snakes.legacy.MasterSnake", "1.2.0"),
|
||||
"BetterMasterSnake": SnakeRegistration("snakes.legacy.BetterMasterSnake", "1.3.0"),
|
||||
"BestBattleSnake": SnakeRegistration("snakes.legacy.BestBattleSnake", "2.6.0"),
|
||||
"TrainedBattleSnake": SnakeRegistration(
|
||||
"snakes.legacy.TrainedBattleSnake", "0.1.0"
|
||||
),
|
||||
"UltimateBattleSnake": SnakeRegistration(
|
||||
"snakes.legacy.UltimateBattleSnake", "4.5.0"
|
||||
),
|
||||
"SupremeBattleSnake_ClaudeOpus4_6": SnakeRegistration(
|
||||
"snakes.legacy.SupremeBattleSnake_ClaudeOpus4_6",
|
||||
"1.0.0",
|
||||
),
|
||||
}
|
||||
|
||||
# Backward-compatible public version map.
|
||||
SNAKE_REGISTRY = {
|
||||
"TemplateSnake": "1.0.0",
|
||||
"DummSnake": "1.0.0",
|
||||
"LogicSnake": "1.1.0",
|
||||
"MasterSnake": "1.2.0",
|
||||
"BetterMasterSnake": "1.3.0",
|
||||
"BestBattleSnake": "2.6.0",
|
||||
"TrainedBattleSnake": "0.1.0",
|
||||
"UltimateBattleSnake": "4.5.0",
|
||||
"ApexBattleSnake": "1.0.0",
|
||||
"SupremeBattleSnake_ClaudeOpus4_6": "1.0.0",
|
||||
"PrismBattleSnake_GPT_5_6_Sol": "1.2.0",
|
||||
name: registration.version for name, registration in SNAKE_REGISTRATIONS.items()
|
||||
}
|
||||
|
||||
DEFAULT_SNAKE_CONFIG = {
|
||||
'apiversion': '1',
|
||||
'author': '',
|
||||
'color': '#888888',
|
||||
'head': 'default',
|
||||
'tail': 'default',
|
||||
"apiversion": "1",
|
||||
"author": "",
|
||||
"color": "#888888",
|
||||
"head": "default",
|
||||
"tail": "default",
|
||||
}
|
||||
|
||||
def build_snake(selected_snake:str):
|
||||
if selected_snake not in SNAKE_REGISTRY:
|
||||
|
||||
def build_snake(selected_snake: str):
|
||||
registration = SNAKE_REGISTRATIONS.get(selected_snake)
|
||||
if registration is None:
|
||||
raise ValueError(f"Unknown snake: {selected_snake}")
|
||||
|
||||
snake_module = importlib.import_module(f"snakes.{selected_snake}")
|
||||
snake_module = importlib.import_module(registration.module)
|
||||
snake_class = getattr(snake_module, selected_snake)
|
||||
return snake_class()
|
||||
|
||||
def get_snake_version(selected_snake:str) -> str|None:
|
||||
version = SNAKE_REGISTRY.get(selected_snake)
|
||||
if version is None:
|
||||
return None
|
||||
return str(version)
|
||||
def get_snake_version(selected_snake: str) -> str | None:
|
||||
registration = SNAKE_REGISTRATIONS.get(selected_snake)
|
||||
return registration.version if registration is not None else None
|
||||
|
||||
|
||||
class SnakeBuilder:
|
||||
@classmethod
|
||||
@@ -42,5 +63,5 @@ class SnakeBuilder:
|
||||
return build_snake(selected_snake)
|
||||
|
||||
@classmethod
|
||||
def get_version(self, selected_snake:str) -> str|None:
|
||||
def get_version(self, selected_snake: str) -> str | None:
|
||||
return get_snake_version(selected_snake)
|
||||
|
||||
Reference in New Issue
Block a user