From c77e8897a96e5f8547c1a9edf2a8a1afaa2b3d39 Mon Sep 17 00:00:00 2001 From: GuillaumeSD Date: Sun, 10 Mar 2024 21:06:52 +0100 Subject: [PATCH] fix : handle bestLinePvToPlay empty array case --- src/lib/chess.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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";