Conversation
- 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
JiwaniZakir
left a comment
There was a problem hiding this comment.
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.
Please note - this commit was AI-generated and I am not a very competent TS dev, please review before accepting. Summary of changes:
src/utils/findPieces.tsx- FixedgetUpdatefunction (line 132)if (square == -1)toif (typeof square !== 'number' || !Number.isInteger(square) || square < 0 || square >= 64)TypeError: can't access property 0, update[square] is undefined- handles undefined/NaN/out-of-bounds square values from tensor operationssrc/utils/findPieces.tsx- Reset state after move detection (lines 223, 240)state = zeros(64, 12);after both move detection pathssrc/utils/math.tsx- Fixed zeros functionArray.from(Array(rows), ...)toArray.from({ length: rows }, ...)src/components/play/playSidebar.tsx- Fixed opponent move handlingboard.move(lastMove)toboard.playUci(lastMove)fromOpponentcheck to prevent sending opponent moves back to Lichesssrc/slices/gameSlice.tsx- Added playUci methodparseUciimport andmakeSanfor converting UCI moves to SAN notationsrc/types.tsx&src/slices/gameSlice.tsx- AddedfromOpponentfieldsrc/utils/lichess.tsx- Removed alert popupalert(err)toconsole.error(err)