feat : add arrow opt out options

This commit is contained in:
GuillaumeSD
2024-02-24 18:20:48 +01:00
parent 035591208f
commit 7b328d3159
16 changed files with 228 additions and 89 deletions

View File

@@ -2,14 +2,14 @@ import { EngineName } from "@/types/enums";
import { UciEngine } from "./uciEngine";
export class Stockfish16 extends UciEngine {
constructor() {
constructor(multiPv: number) {
const isWasmSupported = Stockfish16.isWasmSupported();
const enginePath = isWasmSupported
? "engines/stockfish-wasm/stockfish-nnue-16-single.js"
: "engines/stockfish.js";
super(EngineName.Stockfish16, enginePath);
super(EngineName.Stockfish16, enginePath, multiPv);
}
public static isWasmSupported() {

View File

@@ -5,10 +5,11 @@ export abstract class UciEngine {
private worker: Worker;
private ready = false;
private engineName: EngineName;
private multiPv = 3;
private multiPv: number;
constructor(engineName: EngineName, enginePath: string) {
constructor(engineName: EngineName, enginePath: string, multiPv: number) {
this.engineName = engineName;
this.multiPv = multiPv;
this.worker = new Worker(enginePath);
@@ -17,7 +18,7 @@ export abstract class UciEngine {
public async init(): Promise<void> {
await this.sendCommands(["uci"], "uciok");
await this.setMultiPv(3, false);
await this.setMultiPv(this.multiPv, false);
this.ready = true;
console.log(`${this.engineName} initialized`);
}
@@ -81,24 +82,21 @@ export abstract class UciEngine {
public async evaluateGame(
fens: string[],
depth = 16,
multiPv = 3
multiPv = this.multiPv
): Promise<GameEval> {
this.throwErrorIfNotReady();
this.ready = false;
await this.setMultiPv(multiPv, false);
await this.sendCommands(["ucinewgame", "isready"], "readyok");
this.worker.postMessage("position startpos");
const moves: MoveEval[] = [];
for (const fen of fens) {
console.log(`Evaluating position: ${fen}`);
const result = await this.evaluatePosition(fen, depth, false);
const result = await this.evaluatePosition(fen, depth, multiPv, false);
moves.push(result);
}
this.ready = true;
console.log(moves);
return {
moves,
accuracy: { white: 82.34, black: 67.49 }, // TODO: Calculate accuracy
@@ -114,12 +112,16 @@ export abstract class UciEngine {
public async evaluatePosition(
fen: string,
depth = 16,
multiPv = this.multiPv,
checkIsReady = true
): Promise<MoveEval> {
if (checkIsReady) {
this.throwErrorIfNotReady();
}
await this.setMultiPv(multiPv, checkIsReady);
console.log(`Evaluating position: ${fen}`);
const results = await this.sendCommands(
[`position fen ${fen}`, `go depth ${depth}`],
"bestmove"