Skip to content

Fix off-by-one errors in board and promotion click mapping#7

Merged
Qelxiros merged 1 commit into
mainfrom
fix-square-click-offbyone
Jun 24, 2026
Merged

Fix off-by-one errors in board and promotion click mapping#7
Qelxiros merged 1 commit into
mainfrom
fix-square-click-offbyone

Conversation

@Qelxiros

Copy link
Copy Markdown
Collaborator

Summary

Fixes two vertical off-by-one bugs in mouse click handling where the click-to-coordinate math didn't match the actual rendered layout.

Square clicking

squareFromMouse assumed the board's top cell sat at terminal row 0. That holds for the live game screen, but the puzzle and replay screens render a title + blank line first, placing the board at row 2. The missing offset meant clicks below the top row of each square spilled into the square below it.

Fix: add SetBoardOriginY so each screen declares the board's vertical origin (set to 2 in puzzle/replay; the live game keeps the 0 default), and translate the mouse y by it.

Promotion popup

handlePromoClick hit-tested the promotion piece cells at promoPopupY + 2, but the cells render at promoPopupY + 1 — the row right after the "Promote pawn:" label. This rejected clicks on the top piece row (the queen) and wrongly accepted the key-label row below the pieces. Fixed to +1.

Testing

  • go test ./... — all green
  • Added regression tests that fail under the old math:
    • TestLocalMoveInput_HandleMsg_BoardOriginY_OffsetsClick
    • TestLocalMoveInput_HandlePromoClick_TopPieceRowSelectsQueen
    • TestLocalMoveInput_HandlePromoClick_LabelRowIsNotAPiece

🤖 Generated with Claude Code

squareFromMouse assumed the board's top cell was at terminal row 0, but
puzzle and replay screens render a title + blank line first, placing the
board at row 2. Clicks below the top row of each square spilled into the
square below. Add SetBoardOriginY so screens declare the board's vertical
origin, and translate the mouse y by it.

handlePromoClick had the same class of bug: it hit-tested the promotion
piece cells at promoPopupY+2, but the cells render at promoPopupY+1 (the
row right after the "Promote pawn:" label). This rejected the top piece
row and accepted the key-label row below the pieces. Fix to +1.

Add regression tests for both.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@ikopke23 ikopke23 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prob good

@Qelxiros Qelxiros merged commit e5aa80d into main Jun 24, 2026
3 of 4 checks passed
@Qelxiros Qelxiros deleted the fix-square-click-offbyone branch June 24, 2026 18:21
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.

2 participants