diff --git a/src/lib/chess.ts b/src/lib/chess.ts index efceff9..ee27eb6 100644 --- a/src/lib/chess.ts +++ b/src/lib/chess.ts @@ -197,9 +197,14 @@ export const getIsPieceSacrifice = ( } let nonCapturingMovesTemp = 1; + const capturedPieces: { w: PieceSymbol[]; b: PieceSymbol[] } = { + w: [], + b: [], + }; for (const move of moves) { const fullMove = game.move(uciMoveParams(move)); if (fullMove.captured) { + capturedPieces[fullMove.color].push(fullMove.captured); nonCapturingMovesTemp = 1; } else { nonCapturingMovesTemp--; @@ -207,6 +212,19 @@ export const getIsPieceSacrifice = ( } } + for (const p of capturedPieces["w"].slice(0)) { + if (capturedPieces["b"].includes(p)) { + capturedPieces["b"].splice(capturedPieces["b"].indexOf(p), 1); + capturedPieces["w"].splice(capturedPieces["w"].indexOf(p), 1); + } + } + + if ( + Math.abs(capturedPieces["w"].length - capturedPieces["b"].length) <= 1 && + capturedPieces["w"].concat(capturedPieces["b"]).every((p) => p === "p") + return false; + } + const endingMaterialDifference = getMaterialDifference(game.fen()); const materialDiff = endingMaterialDifference - startingMaterialDifference; diff --git a/src/lib/engine/helpers/moveClassification.ts b/src/lib/engine/helpers/moveClassification.ts index 67720ad..2f0b300 100644 --- a/src/lib/engine/helpers/moveClassification.ts +++ b/src/lib/engine/helpers/moveClassification.ts @@ -153,8 +153,9 @@ const isBrilliantMove = ( lastPositionAlternativeLineWinPercentage, isWhiteMove ) - ) + ) { return false; + } return true; }; @@ -165,8 +166,8 @@ const isLosingOrAlternateCompletelyWinning = ( isWhiteMove: boolean ): boolean => { const isLosing = isWhiteMove - ? positionWinPercentage < 45 - : positionWinPercentage > 55; + ? positionWinPercentage < 50 + : positionWinPercentage > 50; const isAlternateCompletelyWinning = isWhiteMove ? lastPositionAlternativeLineWinPercentage > 97 : lastPositionAlternativeLineWinPercentage < 3; @@ -202,8 +203,9 @@ const isGreatMove = ( lastPositionAlternativeLineWinPercentage, isWhiteMove ) - ) + ) { return false; + } const hasChangedGameOutcome = getHasChangedGameOutcome( lastPositionWinPercentage,