feat : improve is piece sacrifice calc

This commit is contained in:
GuillaumeSD
2024-03-17 18:16:51 +01:00
parent c77e8897a9
commit f9cb5acc1f
2 changed files with 18 additions and 8 deletions

View File

@@ -24,8 +24,9 @@ const LinearProgressBar = (
alignItems="center" alignItems="center"
justifyContent="center" justifyContent="center"
wrap="nowrap" wrap="nowrap"
columnGap={2}
> >
<Grid item sx={{ width: "100%", mr: 2 }}> <Grid item sx={{ width: "100%" }}>
<LinearProgress <LinearProgress
variant="determinate" variant="determinate"
{...props} {...props}
@@ -45,7 +46,7 @@ const LinearProgressBar = (
})} })}
/> />
</Grid> </Grid>
<Grid item sx={{ minWidth: 35 }}> <Grid item>
<Typography variant="body2" color="text.secondary">{`${Math.round( <Typography variant="body2" color="text.secondary">{`${Math.round(
props.value props.value
)}%`}</Typography> )}%`}</Typography>

View File

@@ -130,10 +130,9 @@ export const getIsPieceSacrifice = (
playedMove: string, playedMove: string,
bestLinePvToPlay: string[] bestLinePvToPlay: string[]
): boolean => { ): boolean => {
const exchangeSquare = playedMove.slice(2, 4);
if ( if (
!bestLinePvToPlay.length || !bestLinePvToPlay.length ||
bestLinePvToPlay[0].slice(2, 4) !== exchangeSquare bestLinePvToPlay[0].slice(2, 4) !== playedMove.slice(2, 4)
) )
return false; return false;
@@ -141,10 +140,20 @@ export const getIsPieceSacrifice = (
const whiteToPlay = game.turn() === "w"; const whiteToPlay = game.turn() === "w";
const startingMaterialDifference = getMaterialDifference(fen); const startingMaterialDifference = getMaterialDifference(fen);
game.move(uciMoveParams(playedMove)); let moves = [playedMove, ...bestLinePvToPlay];
for (const move of bestLinePvToPlay) { if (moves.length % 2 === 1) {
if (move.slice(2, 4) !== exchangeSquare) break; moves = moves.slice(0, -1);
game.move(uciMoveParams(move)); }
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()); const endingMaterialDifference = getMaterialDifference(game.fen());