From b3aa7673139c090c29adb3a086c025313964dd40 Mon Sep 17 00:00:00 2001 From: Taro Date: Wed, 10 Jun 2026 14:33:18 +0200 Subject: [PATCH] Chess: from_fen no longer inherits phantom startpos 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 2d4b5a2e96d69ed6f3710b619caa74c24ae0b2e9) --- pgx/experimental/chess.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pgx/experimental/chess.py b/pgx/experimental/chess.py index 36313d069..125b4f5f1 100644 --- a/pgx/experimental/chess.py +++ b/pgx/experimental/chess.py @@ -66,6 +66,9 @@ def from_fen(fen: str): halfmove_count=jnp.int32(halfmove_cnt), fullmove_count=jnp.int32(fullmove_cnt), ) + # default GameState carries the startpos in hash_history[0]/board_history[0]; clear both + # so the restored position does not inherit a phantom repetition/observation entry + x = x._replace(hash_history=jnp.zeros_like(x.hash_history), board_history=jnp.zeros_like(x.board_history)) legal_action_mask = jax.jit(_legal_action_mask)(x) x = x._replace(legal_action_mask=legal_action_mask) x = _update_history(x)