Published
Edited
Mar 8, 2020
2 forks
5 stars
Insert cell
Insert cell
stockfish = {
const workerScript = await require.resolve("stockfish@10/src/stockfish.asm.js")
.then(fetch)
.then(response => response.blob())
.then(blob => URL.createObjectURL(blob, {type: "text/javascript"}));
return new Worker(workerScript);
}
Insert cell
async function bestmove(stockfish, message) {
let resolve;
const promise = new Promise(r => resolve = r);
const messages = [];
const messaged = e => {
messages.push(e.data);
if (/^bestmove /.test(e.data)) {
stockfish.onmessage = null;
resolve(messages);
}
};
if (stockfish.onmessage) throw new Error("already listening");
stockfish.onmessage = messaged;
stockfish.postMessage(message);
return promise;
}
Insert cell
bestmove(stockfish, "go depth 15")
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