Skip to content

ADR-0013: The chess world has its own rules engine instead of depending on python-chess

  • Status: Accepted
  • Date: 2026-12-02

Context

SPEC-024 makes chess a built-in world, available to everyone who installs agentplaykit. The obvious way to get the rules right is the python-chess package. It is excellent and well tested, but it is licensed under the GPL-3.0. AgentPlay is MIT-licensed. If agentplaykit depended on python-chess by default, every program that uses agentplaykit would also load GPL code, and many companies and projects cannot accept that. An optional extra (agentplaykit[chess]) would avoid the licence problem, but chess would then not work "by default", which is the point of a built-in world.

Decision

  • Write a small chess rules engine in AgentPlay itself (agentplaykit/envs/chess.py, about 300 lines, MIT). It covers every rule: castling, en passant, promotion, check, checkmate, stalemate, threefold repetition, the fifty-move rule and insufficient material, plus SAN and FEN.
  • Prove it correct the standard way, with perft: the number of positions reachable at a given depth from well-known test positions, compared with the published counts (CHS-002). Perft catches any missing or extra move, including the rare rules.
  • Keep the engine a rules engine only. It does not search for good moves; a stronger scripted opponent is an open question in SPEC-024.

Consequences

  • world: {use: chess} works on every install, with no extra package and no licence change.
  • AgentPlay maintains the rules code. The rules of chess do not change, and the perft tests protect it from regressions.
  • The engine is slower than python-chess, which is fine: a game against a model spends almost all its time waiting for the model's replies.
  • People who prefer python-chess can still write their own world with it as a file or plugin.