Skip to content

Commit 330e5b3

Browse files
committed
Update Fairy Stockfish (Many variants still unsupported)
1 parent 70324dc commit 330e5b3

11 files changed

Lines changed: 146 additions & 91 deletions

File tree

acas.user.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,6 @@ async function determineBoardPositionValidity(turn) {
22932293
// Do not continue if a piece just disappeared, this is not possible legally!
22942294
// (This happens sometimes because the mutationObserver detects DOM changes so fast)
22952295
if(squareChangeAmount === 1) {
2296-
clearVisuals();
22972296
return;
22982297
}
22992298
}

app/assets/engines/fairy-stockfish-nnue.wasm/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{
22
"name": "fairy-stockfish-nnue.wasm",
3-
"version": "1.1.2",
3+
"version": "1.1.11",
44
"description": "WebAssembly port of Fairy-Stockfish with NNUE support, optimized via WASM SIMD",
55
"author": "Fabian Fichter",
66
"license": "GPL-3.0",
77
"homepage": "https://github.com/ianfab/fairy-stockfish.wasm",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/fairy-stockfish/fairy-stockfish.wasm"
11+
},
812
"files": [
913
"AUTHORS",
1014
"Copying.txt",

app/assets/engines/fairy-stockfish-nnue.wasm/stockfish.js

Lines changed: 57 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
78.4 KB
Binary file not shown.

app/assets/engines/fairy-stockfish-nnue.wasm/stockfish.worker.js

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/assets/engines/fairy-stockfish-nnue.wasm/stockfishWorker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let engine = null;
99
onmessage = e => {
1010
const { method, args } = e.data;
1111

12-
if (!engine) {
12+
if(!engine) {
1313
postMessage(false);
1414
return;
1515
}
@@ -22,7 +22,7 @@ onmessage = e => {
2222
return;
2323
}
2424

25-
if (engine[method] && typeof engine[method] === 'function') {
25+
if(engine[method] && typeof engine[method] === 'function') {
2626
engine[method](...args);
2727
}
2828
};

app/assets/js/AcasInstance.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export default class AcasInstance {
339339
this.pV[profileName].useChess960 = optionValue;
340340
break;
341341
case 'UCI_Variant':
342-
this.pV[profileName].chessVariant = FORMAT_VARIANT(optionValue);
342+
//this.pV[profileName].chessVariant = FORMAT_VARIANT(optionValue);
343343
break;
344344
}
345345

@@ -414,8 +414,6 @@ export default class AcasInstance {
414414
}
415415

416416
setEngineOption(name, value = null, isDynamicOption, profile) {
417-
console.log(name, value, isDynamicOption, profile);
418-
419417
if(Number.isNaN(value) || value === undefined) return;
420418

421419
this.sendMsgToEngine(`setoption name ${name}${value === null ? '' : ' value ' + value}`, profile, isDynamicOption);

app/assets/js/gui/settingChangeObserver.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ export function runSettingChangeObserver(inputElem, delayMs = 0, wasCalledByUpda
8282
lc0WeightDropdown.classList.add('hidden');
8383
}
8484

85-
if(value === 'maia2') {
85+
if(value === 'maia2' || value === 'fairy-stockfish-nnue-wasm') {
8686
disableAdvancedEloCheckbox(false);
8787

8888
normalEloInput.removeAttribute('disabled');
8989
}
9090

91-
if(value !== 'lc0' && value !== 'maia2') {
91+
if(value !== 'lc0' && value !== 'maia2' && value !== 'fairy-stockfish-nnue-wasm') {
9292
advancedEloEnableInput.removeAttribute('disabled');
9393
}
9494

app/assets/js/instance/engineMessageProcessor.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { fillDynamicEngineOptionContainer } from '../gui/dynamicEngineOptions.js
33
import { updatePipData } from '../gui/pip.js';
44
import { setDynamicOptionsReady } from '../gui/dynamicEngineOptions.js';
55

6+
const variantStartposMap = new Map();
7+
68
export default async function engineMessageProcessor(msg, profile) {
79
msg = msg?.trim();
810

@@ -184,26 +186,27 @@ export default async function engineMessageProcessor(msg, profile) {
184186
}
185187
}
186188

187-
if(isMsgOption) {
188-
fillDynamicEngineOptionContainer(msg, profile);
189-
}
189+
if(isMsgOption) fillDynamicEngineOptionContainer(msg, profile);
190+
191+
const variantStartposFen = data['Fen:'];
192+
if(variantStartposFen) variantStartposMap.set(profile, variantStartposFen);
190193

191194
if(msg === 'uciok') {
192195
setDynamicOptionsReady(profile);
193-
}
194196

195-
const variantStartposFen = data['Fen:'];
196-
197-
if(variantStartposFen || msg === 'uciok') {
198-
const dimensions = GET_BOARD_DIMENSIONS_FROM_FEN(variantStartposFen);
199-
const startPos = variantStartposFen || this.defaultStartpos;
197+
setTimeout(() => { // wait a bit for potential variantStartposfen
198+
const startPosFen = variantStartposMap.get(profile);
199+
const dimensions = startPosFen ? GET_BOARD_DIMENSIONS_FROM_FEN(startPosFen) : [8, 8];
200+
const startPos = startPosFen || this.defaultStartpos;
200201

201-
const waitForChessgroundLoad = setInterval(() => {
202-
if(window?.ChessgroundX) {
203-
clearInterval(waitForChessgroundLoad);
202+
const waitForChessgroundLoad = setInterval(() => {
203+
if(window?.ChessgroundX) {
204+
clearInterval(waitForChessgroundLoad);
204205

205-
this.setupEnvironment(startPos, dimensions);
206-
}
207-
}, 5);
206+
this.setupEnvironment(startPos, dimensions);
207+
variantStartposMap.delete(profile);
208+
}
209+
}, 5);
210+
}, 50);
208211
}
209212
}

app/assets/js/instance/loadEngine.js

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,43 @@ export default async function loadEngine(profileName, engineName, attempt = 0) {
7474
};
7575
}
7676

77-
function loadLilaStockfish(workerName) {
77+
function loadFairyStockfish() {
78+
const stockfish = new Worker(`../app/assets/engines/fairy-stockfish-nnue.wasm/stockfishWorker.js`);
79+
let stockfish_loaded = false;
80+
81+
stockfish.onmessage = async e => {
82+
if(e.data === true) {
83+
stockfish_loaded = true;
84+
85+
this.engines.push({
86+
'type': profileChessEngine,
87+
'engine': (method, a) => stockfish.postMessage({ method: method, args: [...a] }),
88+
'sendMsg': msg => stockfish.postMessage({ method: 'postMessage', args: [msg] }),
89+
'worker': stockfish,
90+
profileName
91+
});
92+
93+
startGame.bind(this)(FORMAT_VARIANT(this.pV[profileName].chessVariant));
94+
} else if(e.data) {
95+
processEngineMessage(e.data);
96+
}
97+
};
98+
99+
const waitStockfish = setInterval(() => {
100+
if(stockfish_loaded) {
101+
clearInterval(waitStockfish);
102+
return;
103+
}
104+
105+
stockfish.postMessage({ method: 'acas_check_loaded' });
106+
}, 100);
107+
108+
stockfish.onerror = e => {
109+
restartEngine.bind(this)('fairy-stockfish-nnue-wasm', e);
110+
};
111+
}
112+
113+
function loadLilaStockfish(workerName, engineName) {
78114
const stockfish = new Worker(`../app/assets/engines/lila-stockfish/${workerName}.js`, { type: 'module' });
79115
let stockfish_loaded = false;
80116

@@ -90,10 +126,8 @@ export default async function loadEngine(profileName, engineName, attempt = 0) {
90126
profileName
91127
});
92128

93-
startGame.bind(this)(workerName === 'f14-worker'
94-
? FORMAT_VARIANT(this.pV[profileName].chessVariant)
95-
: 'chess');
96-
} else if (e.data) {
129+
startGame.bind(this)('chess');
130+
} else if(e.data) {
97131
processEngineMessage(e.data);
98132
}
99133
};
@@ -106,6 +140,10 @@ export default async function loadEngine(profileName, engineName, attempt = 0) {
106140

107141
stockfish.postMessage({ method: 'acas_check_loaded' });
108142
}, 100);
143+
144+
stockfish.onerror = e => {
145+
restartEngine.bind(this)(engineName, e);
146+
};
109147
}
110148

111149
function loadLc0() {
@@ -248,7 +286,7 @@ export default async function loadEngine(profileName, engineName, attempt = 0) {
248286
break;
249287

250288
case 'stockfish-16-1-wasm':
251-
loadLilaStockfish.bind(this)('16-0-worker');
289+
loadLilaStockfish.bind(this)('16-0-worker', 'stockfish-16-1-wasm');
252290
break;
253291

254292
case 'stockfish-11':
@@ -259,8 +297,8 @@ export default async function loadEngine(profileName, engineName, attempt = 0) {
259297
loadStockfish.bind(this)('stockfish-8');
260298
break;
261299

262-
case 'fairy-stockfish-nnue-wasm':
263-
loadLilaStockfish.bind(this)('f14-worker');
300+
case 'fairy-stockfish-nnue-wasm':
301+
loadFairyStockfish.bind(this)();
264302
break;
265303

266304
case 'lozza-5':

0 commit comments

Comments
 (0)