feat : great & brilliant v1
This commit is contained in:
@@ -130,19 +130,25 @@ export const getIsPieceSacrifice = (
|
||||
playedMove: string,
|
||||
bestLinePvToPlay: string[]
|
||||
): boolean => {
|
||||
if (playedMove.slice(2, 4) !== bestLinePvToPlay[0].slice(2, 4)) return false;
|
||||
const exchangeSquare = playedMove.slice(2, 4);
|
||||
if (bestLinePvToPlay[0].slice(2, 4) !== exchangeSquare) return false;
|
||||
|
||||
const game = new Chess(fen);
|
||||
const whiteToPlay = game.turn() === "w";
|
||||
const startingMaterialDifference = getMaterialDifference(fen);
|
||||
|
||||
game.move(uciMoveParams(playedMove));
|
||||
game.move(uciMoveParams(bestLinePvToPlay[0]));
|
||||
for (const move of bestLinePvToPlay) {
|
||||
if (move.slice(2, 4) !== exchangeSquare) break;
|
||||
game.move(uciMoveParams(move));
|
||||
}
|
||||
|
||||
const endingMaterialDifference = getMaterialDifference(game.fen());
|
||||
|
||||
const materialDiff = endingMaterialDifference - startingMaterialDifference;
|
||||
const materialDiffPlayerRelative = whiteToPlay ? materialDiff : -materialDiff;
|
||||
|
||||
return materialDiffPlayerRelative < 0;
|
||||
return materialDiffPlayerRelative < -1;
|
||||
};
|
||||
|
||||
export const getMaterialDifference = (fen: string): number => {
|
||||
|
||||
@@ -47,11 +47,13 @@ export const getMovesClassification = (
|
||||
|
||||
if (
|
||||
isBrilliantMove(
|
||||
lastPositionWinPercentage,
|
||||
positionWinPercentage,
|
||||
isWhiteMove,
|
||||
playedMove,
|
||||
bestLinePvToPlay,
|
||||
fens[index - 1]
|
||||
fens[index - 1],
|
||||
lastPositionAlternativeLineWinPercentage
|
||||
)
|
||||
) {
|
||||
return {
|
||||
@@ -117,26 +119,34 @@ const getMoveBasicClassification = (
|
||||
};
|
||||
|
||||
const isBrilliantMove = (
|
||||
lastPositionWinPercentage: number,
|
||||
positionWinPercentage: number,
|
||||
isWhiteMove: boolean,
|
||||
playedMove: string,
|
||||
bestLinePvToPlay: string[],
|
||||
fen: string
|
||||
fen: string,
|
||||
lastPositionAlternativeLineWinPercentage: number | undefined
|
||||
): boolean => {
|
||||
if (!lastPositionAlternativeLineWinPercentage) return false;
|
||||
|
||||
const winPercentageDiff =
|
||||
(positionWinPercentage - lastPositionWinPercentage) *
|
||||
(isWhiteMove ? 1 : -1);
|
||||
if (winPercentageDiff < -2) return false;
|
||||
|
||||
const isPieceSacrifice = getIsPieceSacrifice(
|
||||
fen,
|
||||
playedMove,
|
||||
bestLinePvToPlay
|
||||
);
|
||||
|
||||
if (!isPieceSacrifice) return false;
|
||||
|
||||
const isNotLosing = isWhiteMove
|
||||
? positionWinPercentage > 50
|
||||
: positionWinPercentage < 50;
|
||||
? positionWinPercentage >= 50
|
||||
: positionWinPercentage <= 50;
|
||||
const isAlternateCompletelyWinning = isWhiteMove
|
||||
? positionWinPercentage > 70
|
||||
: positionWinPercentage < 30;
|
||||
? lastPositionAlternativeLineWinPercentage > 70
|
||||
: lastPositionAlternativeLineWinPercentage < 30;
|
||||
|
||||
return isNotLosing && !isAlternateCompletelyWinning;
|
||||
};
|
||||
@@ -152,7 +162,6 @@ const isGreatMove = (
|
||||
const winPercentageDiff =
|
||||
(positionWinPercentage - lastPositionWinPercentage) *
|
||||
(isWhiteMove ? 1 : -1);
|
||||
|
||||
if (winPercentageDiff < -2) return false;
|
||||
|
||||
const hasChangedGameOutcome = getHasChangedGameOutcome(
|
||||
@@ -167,7 +176,7 @@ const isGreatMove = (
|
||||
isWhiteMove
|
||||
);
|
||||
|
||||
return hasChangedGameOutcome && isTheOnlyGoodMove;
|
||||
return hasChangedGameOutcome || isTheOnlyGoodMove;
|
||||
};
|
||||
|
||||
const getHasChangedGameOutcome = (
|
||||
|
||||
@@ -36,23 +36,12 @@ export const getLichessEval = async (
|
||||
}));
|
||||
|
||||
lines.sort(sortLines);
|
||||
const isWhiteToPlay = fen.split(" ")[1] === "w";
|
||||
if (!isWhiteToPlay) lines.reverse();
|
||||
|
||||
const bestMove = lines[0].pv[0];
|
||||
const linesToKeep = lines.slice(0, multiPv);
|
||||
|
||||
const isWhiteToPlay = fen.split(" ")[1] === "w";
|
||||
|
||||
if (!isWhiteToPlay) {
|
||||
return {
|
||||
bestMove,
|
||||
lines: linesToKeep.map((line) => ({
|
||||
...line,
|
||||
cp: line.cp ? -line.cp : line.cp,
|
||||
mate: line.mate ? -line.mate : line.mate,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
bestMove,
|
||||
lines: linesToKeep,
|
||||
|
||||
@@ -60,7 +60,7 @@ export default SquareRenderer;
|
||||
export const moveClassificationColors: Record<MoveClassification, string> = {
|
||||
[MoveClassification.Book]: "#d5a47d",
|
||||
[MoveClassification.Brilliant]: "#26c2a3",
|
||||
[MoveClassification.Great]: "#749bbf",
|
||||
[MoveClassification.Great]: "#4099ed",
|
||||
[MoveClassification.Best]: "#3aab18",
|
||||
[MoveClassification.Excellent]: "#3aab18",
|
||||
[MoveClassification.Good]: "#81b64c",
|
||||
|
||||
Reference in New Issue
Block a user