diff --git a/src/lib/chess.ts b/src/lib/chess.ts index c7a5673..1fa9d1a 100644 --- a/src/lib/chess.ts +++ b/src/lib/chess.ts @@ -131,7 +131,11 @@ export const getIsPieceSacrifice = ( bestLinePvToPlay: string[] ): boolean => { const exchangeSquare = playedMove.slice(2, 4); - if (bestLinePvToPlay[0].slice(2, 4) !== exchangeSquare) return false; + if ( + !bestLinePvToPlay.length || + bestLinePvToPlay[0].slice(2, 4) !== exchangeSquare + ) + return false; const game = new Chess(fen); const whiteToPlay = game.turn() === "w";