Skip to content

[Chess] from_fen: don't inherit phantom startpos history#1319

Open
gweber wants to merge 1 commit into
sotetsuk:mainfrom
gweber:chess-from-fen-history
Open

[Chess] from_fen: don't inherit phantom startpos history#1319
gweber wants to merge 1 commit into
sotetsuk:mainfrom
gweber:chess-from-fen-history

Conversation

@gweber

@gweber gweber commented Jun 10, 2026

Copy link
Copy Markdown

Summary

GameState() defaults carry the start position in hash_history[0] and board_history[0]. pgx.experimental.chess.from_fen builds on those defaults and then rolls them via _update_history, so every restored position claims the standard start position as its previous position:

  • hash_history[1] contains the startpos Zobrist hash → a phantom repetition entry. Restoring the start position itself via from_fen immediately reports one repetition; any game that later transposes back to the startpos-hash counts one repetition too many.
  • board_history[1] contains the startpos board → the oldest observation history plane shows a position that was never played.

Fix

Clear both histories before calling _update_history, so the restored position starts with a clean history (matching the semantics of a position restored from FEN, which has no known past).

x = x._replace(hash_history=jnp.zeros_like(x.hash_history), board_history=jnp.zeros_like(x.board_history))

GameState() defaults carry the startpos hash in hash_history[0] and the
startpos board in board_history[0]. from_fen built on those defaults and
then rolled them via _update_history, so every restored position claimed
the startpos as its previous position - a phantom repetition entry and a
wrong oldest observation plane. Clear both histories before updating.

(cherry picked from commit 2d4b5a2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant