Files
coorl-lost-cities/setup.py
T
coolguyandClaude Opus 4.7 05de0e2a81 Port safe-heuristic bots to Cython with Python reference fallback
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>
2026-05-07 20:03:53 +09:00

45 lines
1.3 KiB
Python

from __future__ import annotations
from setuptools import Extension, setup
try:
from Cython.Build import cythonize
except ImportError as exc: # pragma: no cover
raise RuntimeError("Cython is required to build coolrl-lost-cities") from exc
extensions = cythonize(
[
Extension(
"coolrl_lost_cities.games.classic.game",
["src/coolrl_lost_cities/games/classic/game.pyx"],
),
Extension(
"coolrl_lost_cities.games.classic.deep_cfr.cfr_math",
["src/coolrl_lost_cities/games/classic/deep_cfr/cfr_math.pyx"],
),
Extension(
"coolrl_lost_cities.games.classic.deep_cfr.encoding",
["src/coolrl_lost_cities/games/classic/deep_cfr/encoding.pyx"],
),
Extension(
"coolrl_lost_cities.games.classic.deep_cfr.traversal",
["src/coolrl_lost_cities/games/classic/deep_cfr/traversal.pyx"],
),
Extension(
"coolrl_lost_cities.games.classic.bots.heuristic_cy",
["src/coolrl_lost_cities/games/classic/bots/heuristic_cy.pyx"],
),
],
language_level=3,
compiler_directives={
"boundscheck": False,
"wraparound": False,
"cdivision": True,
"initializedcheck": False,
},
)
setup(ext_modules=extensions)