feat : add stockfish 17

This commit is contained in:
GuillaumeSD
2025-01-07 00:43:58 +01:00
parent 151277524b
commit 49bbc87fa5
18 changed files with 121 additions and 22 deletions

View File

@@ -1,3 +1,9 @@
import { EngineName } from "@/types/enums";
import { Stockfish11 } from "./stockfish11";
import { Stockfish16 } from "./stockfish16";
import { Stockfish16_1 } from "./stockfish16_1";
import { Stockfish17 } from "./stockfish17";
export const isWasmSupported = () =>
typeof WebAssembly === "object" &&
WebAssembly.validate(
@@ -5,3 +11,19 @@ export const isWasmSupported = () =>
);
export const isMultiThreadSupported = () => SharedArrayBuffer !== undefined;
export const isEngineSupported = (name: EngineName): boolean => {
switch (name) {
case EngineName.Stockfish17:
case EngineName.Stockfish17Lite:
return Stockfish17.isSupported();
case EngineName.Stockfish16_1:
case EngineName.Stockfish16_1Lite:
return Stockfish16_1.isSupported();
case EngineName.Stockfish16:
case EngineName.Stockfish16NNUE:
return Stockfish16.isSupported();
case EngineName.Stockfish11:
return Stockfish11.isSupported();
}
};

View File

@@ -8,4 +8,8 @@ export class Stockfish11 {
return UciEngine.create(EngineName.Stockfish11, worker);
}
public static isSupported() {
return true;
}
}

View File

@@ -5,7 +5,7 @@ import { getEngineWorker } from "./worker";
export class Stockfish16 {
public static async create(nnue?: boolean): Promise<UciEngine> {
if (!isWasmSupported()) {
if (!Stockfish16.isSupported()) {
throw new Error("Stockfish 16 is not supported");
}
@@ -29,4 +29,8 @@ export class Stockfish16 {
return UciEngine.create(EngineName.Stockfish16, worker, customEngineInit);
}
public static isSupported() {
return isWasmSupported();
}
}

View File

@@ -5,7 +5,7 @@ import { getEngineWorker } from "./worker";
export class Stockfish16_1 {
public static async create(lite?: boolean): Promise<UciEngine> {
if (!isWasmSupported()) {
if (!Stockfish16_1.isSupported()) {
throw new Error("Stockfish 16.1 is not supported");
}
@@ -23,4 +23,8 @@ export class Stockfish16_1 {
return UciEngine.create(engineName, worker);
}
public static isSupported() {
return isWasmSupported();
}
}

View File

@@ -0,0 +1,27 @@
import { EngineName } from "@/types/enums";
import { UciEngine } from "./uciEngine";
import { isMultiThreadSupported, isWasmSupported } from "./shared";
import { getEngineWorker } from "./worker";
export class Stockfish17 {
public static async create(lite?: boolean): Promise<UciEngine> {
if (!Stockfish17.isSupported()) {
throw new Error("Stockfish 17 is not supported");
}
const enginePath = lite
? "engines/stockfish-17/stockfish-17-lite-02843c1.js"
: "engines/stockfish-17/stockfish-17-aaa11cd.js";
const engineName = lite
? EngineName.Stockfish17Lite
: EngineName.Stockfish17;
const worker = getEngineWorker(enginePath);
return UciEngine.create(engineName, worker);
}
public static isSupported() {
return isWasmSupported() && isMultiThreadSupported();
}
}