05de0e2a811a2599d286dc2b3553fad3d779d851
Cython implementation in heuristic_cy.pyx achieves ~2.55× speedup on opponent_act_seconds (200-game eval: 59.20s → 23.24s). Original Python implementation preserved verbatim in heuristic_py.py as the equivalence reference. Action-sequence equivalence is verified by test_safe_heuristic_equivalence.py against seeded game corpora. Key implementation notes: - File-local wraparound=True override required for negative discard indexing; Cython global wraparound=False would segfault. - annotation_typing=False preserves verbatim Python semantics. - _CachedState materializes hands/expeditions/discards/deck once per act() call — this is the dominant performance win. Further C-array optimization of _card_value_for_me / _card_value_for_opponent / _color_commitment / _bonus_potential is deferred. The current 2.55× delivers most of the dense-eval future benefit; further work is gated on actually adopting denser eval schedules (eval_every=5, games=1000). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
coolrl-lost-cities
Focused Lost Cities extraction from the legacy coolrl repository.
The current implementation starts with the classic two-player card game:
- classic 5-expedition rules by default
- Python/Cython game engine
- env wrapper
- random, passive-discard, and safe-heuristic bots
- core rule, scoring, mask, env, canonical-state, bot, and GUI smoke tests
Training code, Deep CFR, learned-policy evaluation, GUI, and web client are intentionally outside the first port.
Development
uv run pytest tests/games/classic
uv run lost-cities-classic
For future GUI work, install the optional GUI dependencies:
uv sync --extra gui
Run the classic pygame GUI:
uv run lost-cities-classic-gui --mode pvc --bot safe-heuristic
The GUI uses the in-process Cython game engine.
Basic Usage
from coolrl_lost_cities.games.classic import GameState, build_bot, classic_config
state = GameState.new_game(classic_config(seed=1))
bot = build_bot("random", seed=1)
while not state.terminal:
state.apply_action(bot.act(state))
print(state.total_score(0), state.total_score(1))
See classic port notes for the current direction.
Languages
Python
73.3%
Cython
21.7%
Julia
4.8%
Shell
0.2%