Published
Edited
Mar 16, 2020
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
async function ask(stockfish, command, params="") {
let
resolve,
idx = ("0000" + trigger).slice(-4),
message = command + " " + params,
promise = new Promise(r => resolve = r),
waitfor = ({
'go': 'bestmove',
'uci': 'uciok',
'isready': 'readyok',
'position': 'NOP',
'ucinewgame': 'NOP',
'd': 'Legal'
})[command]
;
stockfish.onmessage = e => {
console.log( e.data );

if (e.data.includes(waitfor)) {
messages.push(idx + ' <== ' + e.data, '');
mutable trigger += 1;
resolve(e.data);
} else {
messages.push(idx + ' ' + e.data);
}

}
;
if (!waitfor) throw new Error("command not available", command);
console.log( message );
messages.push(idx + ' ==> ' + message);
(waitfor === 'NOP') && messages.push('');
mutable trigger += 1;
stockfish.postMessage( message );
return promise;
}
Insert cell
Insert cell
Insert cell
{ trigger; return html`<pre style="display: block; font-size: 11px; line-height: 13px"; height: 120px !important; overflow-y: scroll>${ messages.slice(-30).map( v => `${v}</br>` ) }</pre>`}
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more