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