Drop the en-passant TODO and lock in current behavior with a regression test - #5
Merged
Merged
Conversation
Replace the `# TODO: Append annotation for En passant take.` marker with a comment explaining what the engine already does. On investigation the work was effectively already done: the regular pawn-capture branch fires for en passant too because Move.perform() sets ``taken_piece`` from ``taken_cell`` (the captured pawn's actual square, not the empty destination), so the elog records 'exd6' which is the standard PGN notation for an en-passant capture. JSON save/load and PGN save/load both round-trip the move correctly. Adds a regression test exercising the full path: - elog token is 'exd6' - d5 is cleared, d6 holds the (white) pawn - JSON save/load preserves elog and board state - PGN save/load via PGNFile preserves elog and board state That replaces the implicit "it works if you don't touch it" with an explicit fence so future refactors of the move/capture branches don't silently regress en-passant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Smaller than I pitched. When I dug into the
# TODO: Append annotation for En passant take.marker atgame/game.py:438, the work was already effectively done — I'd misread the code. The engine's regular pawn-capture branch fires for en passant becauseMove.perform()setstaken_piecefromtaken_cell(the captured pawn's actual square, not the empty destination), so the elog already recordsexd6— the standard PGN notation for an en passant capture, noe.p.suffix needed. JSON and PGN save/load both round-trip the move correctly.So instead of changing behavior, this PR:
PGNFile. That fence prevents future refactors of the move/capture branches from silently breaking en passant.Why the previous test sweep didn't catch this implicitly
The Carlsen/Nakamura PGN tests pass moves through
PGNFile.game()which usesparse_pgn_move()and thengame.move()— the en passant detection inBoard.move_piecedoes the right thing for any pawn diagonal-into-empty move, so the existing tests would have flagged a regression in that path. But the fast-suite tests didn't directly exercise en passant against the engine's own move-side flow, so a refactor that broke the elog token (without breaking parse) could have slipped through. The new test plugs that gap.What I considered and didn't do
e.p.suffix to the elog — would diverge fromCarlsen.pgn/Nakamura.pgnconventions and break the equality assertion intest_load_pgn_file. Standard PGN doesn't require it.(d5, "ep")) for cli display — would break the JSONGame.loadpath, which expects ilog event strings to be piece-promotion letters inPIECE_NAME_TYPE_MAP. Could be done with aload()change but the value/risk ratio is poor.Test plan
make test— fast suite (208 passed, 2 deselected) in ~1.4 s.coverage reportaftermake testshows TOTAL 100%.1.e4 a6 2.e5 d5, capture en passant withe5 → d6. Save as PGN. Confirm movetext ends...exd6. Reload — board state matches.https://claude.ai/code/session_01RnQvxtXfn9JFTN8jpNyriL
Generated by Claude Code