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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more