feat : improve is piece sacrifice calc
This commit is contained in:
@@ -24,8 +24,9 @@ const LinearProgressBar = (
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
wrap="nowrap"
|
||||
columnGap={2}
|
||||
>
|
||||
<Grid item sx={{ width: "100%", mr: 2 }}>
|
||||
<Grid item sx={{ width: "100%" }}>
|
||||
<LinearProgress
|
||||
variant="determinate"
|
||||
{...props}
|
||||
@@ -45,7 +46,7 @@ const LinearProgressBar = (
|
||||
})}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item sx={{ minWidth: 35 }}>
|
||||
<Grid item>
|
||||
<Typography variant="body2" color="text.secondary">{`${Math.round(
|
||||
props.value
|
||||
)}%`}</Typography>
|
||||
|
||||
@@ -130,10 +130,9 @@ export const getIsPieceSacrifice = (
|
||||
playedMove: string,
|
||||
bestLinePvToPlay: string[]
|
||||
): boolean => {
|
||||
const exchangeSquare = playedMove.slice(2, 4);
|
||||
if (
|
||||
!bestLinePvToPlay.length ||
|
||||
bestLinePvToPlay[0].slice(2, 4) !== exchangeSquare
|
||||
bestLinePvToPlay[0].slice(2, 4) !== playedMove.slice(2, 4)
|
||||
)
|
||||
return false;
|
||||
|
||||
@@ -141,10 +140,20 @@ export const getIsPieceSacrifice = (
|
||||
const whiteToPlay = game.turn() === "w";
|
||||
const startingMaterialDifference = getMaterialDifference(fen);
|
||||
|
||||
game.move(uciMoveParams(playedMove));
|
||||
for (const move of bestLinePvToPlay) {
|
||||
if (move.slice(2, 4) !== exchangeSquare) break;
|
||||
game.move(uciMoveParams(move));
|
||||
let moves = [playedMove, ...bestLinePvToPlay];
|
||||
if (moves.length % 2 === 1) {
|
||||
moves = moves.slice(0, -1);
|
||||
}
|
||||
let nonCapturingMovesTemp = 1;
|
||||
|
||||
for (const move of moves) {
|
||||
const fullMove = game.move(uciMoveParams(move));
|
||||
if (fullMove.captured) {
|
||||
nonCapturingMovesTemp = 1;
|
||||
} else {
|
||||
nonCapturingMovesTemp--;
|
||||
if (nonCapturingMovesTemp < 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
const endingMaterialDifference = getMaterialDifference(game.fen());
|
||||
|
||||
Reference in New Issue
Block a user