Fix battlekings promotion move encoding#70
Conversation
…o codex/fix-illegal-move-in-battlekings-engine-304qlc
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/position.cpp
Outdated
| PieceType Position::gating_piece_type(Move m, Color c) const { | ||
|
|
||
| if (!gating() || !is_gating(m)) | ||
| return NO_PIECE_TYPE; | ||
|
|
||
| if (type_of(m) == PROMOTION && !gating_from_hand()) | ||
| { | ||
| Piece moving = moved_piece(m); | ||
| if (moving != NO_PIECE) | ||
| { | ||
| PieceType forced = forced_gating_type(c, type_of(moving)); |
There was a problem hiding this comment.
Determine forced gate before source square is cleared
The new gating_piece_type() tries to infer forced gates by calling moved_piece(m) and using forced_gating_type(...). However Position::do_move() invokes this helper after it has already moved the piece off from (see lines 2025‑2031), so moved_piece(m) returns NO_PIECE and the function falls back to gating_type(m)—which now encodes the chosen promotion piece. As a result forced Battlekings promotions place the gating piece equal to the promotion choice rather than the mandated gate type whenever they differ. The gating piece should be computed using the original moving piece (captured before the board update) or the function must be called before the piece is removed.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Summary
- Added a three-argument
gating_piece_typeoverload and wrappers so callers can provide the original moving piece when computing forced gate types. src/position.hL195-L197 src/position.hL885-L891 - Updated
Position::do_moveto pass the pre-move piece into the gating helper, ensuring Battlekings promotions still use the mandated gate piece after the source square is cleared. src/position.cppL223-L240 src/position.cppL2025-L2059
Testing
⚠️ python -m unittest test.TestPyffish.test_battlekings_commoner_capture_ends_game_even_if_gate_attacked test.TestPyffish.test_battlekings_pawn_promotion_lists_all_choices(fails: ModuleNotFoundError: No module named 'pyffish')
7af2b20
into
codex/implement-battle-of-the-kings-variant-7bhqbn
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68f68af740c48322a6acc4499aeaa3d0