stockfish.js
stockfish.js copied to clipboard
stockfish is not a function
i have done this:
var stockfish = require("stockfish"); chesses[id] = new Chess(); console.log('Chess game: ', message.author.username + ' vs NeuroChess'); thinking[id] = false; stockfishes[id] = STOCKFISH(); stockfishes[id].postMessage('setoption name Contempt value 30'); stockfishes[id].postMessage('setoption name Skill Level value 20'); stockfishes[id].postMessage('ucinewgame'); stockfishes[id].postMessage('isready');
it shows that
ReferenceError: STOCKFISH is not defined
any solution?
Since your named the variable as stockfish
on the first line, then you should call stockfishes[id] = stockfish()
.
same thing,
TypeError: stockfish is not a function
Maybe this will help.
I just did this:
npm i stockfish
And then created this file and it works:
var id = 0;
var stockfish = require("stockfish");
var stockfishes = [];
stockfishes[id] = stockfish();
stockfishes[id].onmessage = function (message) {
console.log("received: " + message);
}
stockfishes[id].postMessage('setoption name Contempt value 30');
stockfishes[id].postMessage('setoption name Skill Level value 20');
stockfishes[id].postMessage('ucinewgame');
stockfishes[id].postMessage('isready');
Also checkout https://github.com/nmrugg/stockfish.js/blob/master/load_engine.js.
I met the same issue when using with Vue:
const stockfish = require("stockfish")
this.engine = stockfish();
I met the same problem as @nganphtgit when using Vue. Despite trying many variation of the import function the file returns an empty object, {}. Any suggestions ?
@honkskillet I used the Worker way, let see my demonstration: https://github.com/nganphtgit/chess-bot
@nganphtgit
Did you just manually copy stockfish.js in the public folder of your project and then run the following?
this.engine = new Worker("stockfish.js");
This didn't work for me.
@honkskillet I coppied 3 files: *.js, *.wasm and *.asm, 3 files will be placed at public folder, the file stockfish.js will be embed in index.html and I used post/get message with Worker to get data.
@nganphtgit I tried this for React. It doesn't seem to work. I also tried adding those files to the folder containing the file instantiating the worker. Is there a work around?