feat : add stockfish 16.1
This commit is contained in:
7
src/lib/engine/shared.ts
Normal file
7
src/lib/engine/shared.ts
Normal 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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
23
src/lib/engine/stockfish16_1.ts
Normal file
23
src/lib/engine/stockfish16_1.ts
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user