feat : stockfish 16
This commit is contained in:
14
public/engines/stockfish-wasm/stockfish-nnue-16-single.js
Normal file
14
public/engines/stockfish-wasm/stockfish-nnue-16-single.js
Normal file
File diff suppressed because one or more lines are too long
BIN
public/engines/stockfish-wasm/stockfish-nnue-16-single.wasm
Normal file
BIN
public/engines/stockfish-wasm/stockfish-nnue-16-single.wasm
Normal file
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -7,7 +7,7 @@ export class Stockfish {
|
||||
constructor() {
|
||||
this.worker = new Worker(
|
||||
this.isWasmSupported()
|
||||
? "engines/stockfish.wasm.js"
|
||||
? "engines/stockfish-wasm/stockfish-nnue-16-single.js"
|
||||
: "engines/stockfish.js"
|
||||
);
|
||||
|
||||
@@ -70,41 +70,17 @@ export class Stockfish {
|
||||
await this.sendCommands(["ucinewgame", "isready"], "readyok");
|
||||
this.worker.postMessage("position startpos");
|
||||
|
||||
let whiteCpSum = 0;
|
||||
let whiteCpMax = 0;
|
||||
let blackCpSum = 0;
|
||||
let blackCpMax = 0;
|
||||
const moves: MoveEval[] = [];
|
||||
for (const fen of fens) {
|
||||
console.log(`Evaluating position: ${fen}`);
|
||||
const result = await this.evaluatePosition(fen, depth);
|
||||
|
||||
const bestLineEval = result.lines[0].cp ?? 0;
|
||||
if (this.isWhiteToMove(fen)) {
|
||||
whiteCpMax += bestLineEval;
|
||||
blackCpSum += bestLineEval;
|
||||
} else {
|
||||
blackCpMax += bestLineEval;
|
||||
whiteCpSum += bestLineEval;
|
||||
}
|
||||
|
||||
moves.push(result);
|
||||
}
|
||||
|
||||
this.ready = true;
|
||||
console.log("Game evaluated");
|
||||
console.log(moves);
|
||||
const whiteAccuracy = this.calculateAccuracy(whiteCpSum, whiteCpMax);
|
||||
const blackAccuracy = this.calculateAccuracy(blackCpSum, blackCpMax);
|
||||
return { moves, whiteAccuracy, blackAccuracy };
|
||||
}
|
||||
|
||||
private calculateAccuracy(sum: number, max: number): number {
|
||||
return (sum / max) * 100;
|
||||
}
|
||||
|
||||
private isWhiteToMove(fen: string): boolean {
|
||||
return fen.split(" ")[1] === "w";
|
||||
return { moves, whiteAccuracy: 82.34, blackAccuracy: 67.49 };
|
||||
}
|
||||
|
||||
public async evaluatePosition(fen: string, depth = 16): Promise<MoveEval> {
|
||||
|
||||
@@ -36,7 +36,9 @@ export default function ReviewResult() {
|
||||
{moveEval?.lines.map((line) => (
|
||||
<div key={line.pv[0]} style={{ color: "white" }}>
|
||||
<span style={{ marginRight: "2em" }}>
|
||||
{line.cp ? line.cp / 100 : `Mate in ${Math.abs(line.mate ?? 0)}`}
|
||||
{line.cp !== undefined
|
||||
? line.cp / 100
|
||||
: `Mate in ${Math.abs(line.mate ?? 0)}`}
|
||||
</span>
|
||||
<span>{line.pv.slice(0, 7).join(", ")}</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user