Skip to content

Require legal move validation before showing promotion UI - #9

Open
anas-asghar4831 with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-promotion-picker-for-illegal-drags
Open

anas-asghar4831 with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-promotion-picker-for-illegal-drags

Conversation

Copilot AI commented May 11, 2026 •

Copy link
Copy Markdown

Illegal pawn drags to the back rank were being treated as promotion attempts based only on the destination rank, which caused the promotion picker to appear for moves that chess.js would reject. This change makes promotion detection contingent on actual move legality so illegal drags snap back without opening promotion UI.

  • Promotion gating

    • Tightened isPromotionMove in src/board.tsx to require both:
      • a pawn moving to the promotion rank, and
      • the destination square being present in boardState.getLegalMoves(from)
  • Behavioral impact

    • Preserves existing promotion flows for legal moves (autoPromoteTo, external onPromotion, built-in picker)
    • Prevents illegal back-rank drags from entering any promotion path
  • Implementation

    const isBackRankMove =
      (piece.color === 'w' && toRank === '8') ||
      (piece.color === 'b' && toRank === '1');
    
    if (!isBackRankMove) return false;
    
    return boardState.getLegalMoves(from).some((move) => move.square === to);

Copilot AI linked an issue May 11, 2026 that may be closed by this pull request
@anas-asghar4831
anas-asghar4831 marked this pull request as ready for review May 11, 2026 12:03
Copilot AI changed the title [WIP] Fix promotion picker for illegal pawn drags to back rank Require legal move validation before showing promotion UI May 11, 2026
Copilot AI requested a review from anas-asghar4831 May 11, 2026 12:06
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.

Promotion picker shown for illegal pawn drags to back rank

2 participants