feat : add stockfish 16.1

This commit is contained in:
GuillaumeSD
2024-09-30 02:01:07 +02:00
parent 2baf9b76ad
commit 94b7c9d9f7
25 changed files with 110 additions and 47 deletions

7
src/lib/engine/shared.ts Normal file
View File

@@ -0,0 +1,7 @@
export const isWasmSupported = () =>
typeof WebAssembly === "object" &&
WebAssembly.validate(
Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)
);
export const isMultiThreadSupported = () => SharedArrayBuffer !== undefined;

View File

@@ -1,18 +1,19 @@
import { EngineName } from "@/types/enums";
import { UciEngine } from "./uciEngine";
import { isMultiThreadSupported, isWasmSupported } from "./shared";
export class Stockfish16 extends UciEngine {
constructor(nnue?: boolean) {
if (!Stockfish16.isSupported()) {
if (!isWasmSupported()) {
throw new Error("Stockfish 16 is not supported");
}
const isMultiThreadSupported = Stockfish16.isMultiThreadSupported();
if (!isMultiThreadSupported) console.log("Single thread mode");
const multiThreadIsSupported = isMultiThreadSupported();
if (!multiThreadIsSupported) console.log("Single thread mode");
const enginePath = isMultiThreadSupported
? "engines/stockfish-16-wasm/stockfish-nnue-16.js"
: "engines/stockfish-16-wasm/stockfish-nnue-16-single.js";
const enginePath = multiThreadIsSupported
? "engines/stockfish-16/stockfish-nnue-16.js"
: "engines/stockfish-16/stockfish-nnue-16-single.js";
const customEngineInit = async () => {
await this.sendCommands(
@@ -23,17 +24,4 @@ export class Stockfish16 extends UciEngine {
super(EngineName.Stockfish16, enginePath, customEngineInit);
}
public static isSupported() {
return (
typeof WebAssembly === "object" &&
WebAssembly.validate(
Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)
)
);
}
public static isMultiThreadSupported() {
return SharedArrayBuffer !== undefined;
}
}

View File

@@ -0,0 +1,23 @@
import { EngineName } from "@/types/enums";
import { UciEngine } from "./uciEngine";
import { isMultiThreadSupported, isWasmSupported } from "./shared";
export class Stockfish16_1 extends UciEngine {
constructor(lite?: boolean) {
if (!isWasmSupported()) {
throw new Error("Stockfish 16.1 is not supported");
}
const multiThreadIsSupported = isMultiThreadSupported();
if (!multiThreadIsSupported) console.log("Single thread mode");
const enginePath = `engines/stockfish-16.1/stockfish-16.1${
lite ? "-lite" : ""
}${multiThreadIsSupported ? "" : "-single"}.js`;
super(
lite ? EngineName.Stockfish16_1Lite : EngineName.Stockfish16_1,
enginePath
);
}
}