Skip to content

Various Bugfixes#144

Open
squidKid-deluxe wants to merge 1 commit intoPbatch:mainfrom
squidKid-deluxe:main
Open

Various Bugfixes#144
squidKid-deluxe wants to merge 1 commit intoPbatch:mainfrom
squidKid-deluxe:main

Conversation

@squidKid-deluxe
Copy link
Copy Markdown

Please note - this commit was AI-generated and I am not a very competent TS dev, please review before accepting. Summary of changes:

  1. src/utils/findPieces.tsx - Fixed getUpdate function (line 132)
  • Changed if (square == -1) to if (typeof square !== 'number' || !Number.isInteger(square) || square < 0 || square >= 64)
  • Fixes: TypeError: can't access property 0, update[square] is undefined - handles undefined/NaN/out-of-bounds square values from tensor operations
  1. src/utils/findPieces.tsx - Reset state after move detection (lines 223, 240)
  • Added state = zeros(64, 12); after both move detection paths
  • Fixes: Second move being ignored - state now resets after each detected move
  1. src/utils/math.tsx - Fixed zeros function
  • Changed Array.from(Array(rows), ...) to Array.from({ length: rows }, ...)
  • Fixes: Sparse array issues that could cause undefined rows
  1. src/components/play/playSidebar.tsx - Fixed opponent move handling
  • Changed board.move(lastMove) to board.playUci(lastMove)
  • Added fromOpponent check to prevent sending opponent moves back to Lichess
  • Fixes: TypeError: board.move is not a function and duplicate move submissions
  1. src/slices/gameSlice.tsx - Added playUci method
  • Added parseUci import and makeSan for converting UCI moves to SAN notation
  • Fixes: Opponent moves from Lichess stream not being properly added to game state
  1. src/types.tsx & src/slices/gameSlice.tsx - Added fromOpponent field
  • Tracks whether a move came from the opponent (via stream) vs detected by camera
  • Fixes: System sending opponent's moves back to Lichess
  1. src/utils/lichess.tsx - Removed alert popup
  • Changed alert(err) to console.error(err)
  • Fixes: Intrusive error alerts during Lichess API failures

- findPieces.tsx - Fixed getUpdate to handle invalid square values (undefined/NaN/out-of-bounds)
- findPieces.tsx - Reset state after detecting a move so subsequent moves can be detected
- math.tsx - Fixed zeros to use Array.from({ length: rows }, ...) instead of sparse array
- gameSlice.tsx - Added playUci method with makeSan for opponent moves
- types.tsx - Added fromOpponent field to prevent sending opponent moves back to Lichess
- lichess.tsx - Changed alert() to console.error() for error handling
Copy link
Copy Markdown

@JiwaniZakir JiwaniZakir left a comment

Choose a reason for hiding this comment

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

The lichess.tsx change from alert(err) to console.error(err) silently swallows HTTP errors from the user's perspective — while removing intrusive alerts is reasonable, there's no fallback UI notification, so failed Lichess API calls will now fail invisibly for end users. Consider dispatching an error to the Redux store or using a toast notification instead.

The state = zeros(64, 12) reset added in findPieces.tsx after both greedy and non-greedy moves looks like a meaningful bug fix — without it, accumulated piece-score state from the previous board position would bleed into detection for the next position, which could cause incorrect move detection. Worth calling out explicitly in the PR description.

In gameSlice.tsx, board.playUci uses (move as any).san = san to attach SAN notation to the move object before pushing to history. The as any cast is a workaround that bypasses type safety — it would be cleaner to either extend the move type or store SAN separately in the history array as a tuple [move, san], consistent with how playSan likely handles it.

The fromOpponent flag never explicitly resets to false after processing — it relies on the next makeUpdatePayload call (which defaults fromOpponent to false) to overwrite it. This is fragile; if fromOpponent is true and the local player attempts a move before state is updated, the early-return guard in the playSidebar useEffect could incorrectly skip processing that move.

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