nmrugg / stockfish.js

The Stockfish chess engine in Javascript
GNU General Public License v3.0
925 stars 134 forks source link

Readable output from Stockfish 10. #27

Open spinor8 opened 5 years ago

spinor8 commented 5 years ago

I am currently running Stuckfish the following way.

var stockfish = new Worker("stockfish.js");
stockfish.postMessage("position fen " + currfen)
stockfish.postMessage("go depth 21");
stockfish.onmessage = function(event) {
    console.log(event.data ? event.data : event);
}

Of course the output is very messy. Two questions. Is there a way to filter to the best line calculated so far? Also, the lines are usually in long algebraic notation, is there a way to use short algebraic notation? Thanks.

pavel-karpovich commented 5 years ago

About the first question, in my project, I use a simple string matching of the incoming message. Something like this:

stockfish.onmessage = function(e) {
  if (typeof e !== 'string') return;
  if (e.startsWith('bestmove')) {
    const bestMove = e.split(' ')[1];
  }
}