lichess-org / stockfish.js Goto Github PK
View Code? Open in Web Editor NEWThe strong open source chess engine Stockfish compiled to JavaScript and WebAssembly using Emscripten
License: GNU General Public License v3.0
The strong open source chess engine Stockfish compiled to JavaScript and WebAssembly using Emscripten
License: GNU General Public License v3.0
Hello,
Is it possible to get a compiled version with a npm package ?
Thank you.
cannot run with docker. Getting this permission error inside docker container.
vjuneja$ docker run --volume $PWD:/home/builder/stockfish.js --user $(id -u) niklasf/emscripten-for-stockfish
Makefile:613: recipe for target '.depend' failed
make: [.depend] Error 127 (ignored)
Config:
debug: 'no'
sanitize: 'no'
optimize: 'yes'
arch: 'any'
bits: '32'
kernel: 'Linux'
os: 'GNU/Linux'
prefetch: 'no'
popcnt: 'no'
sse: 'no'
pext: 'no'
Flags:
CXX: em++
CXXFLAGS: -Wall -Wcast-qual -std=c++11 -DANTI -DATOMIC -DCRAZYHOUSE -DHORDE -DKOTH -DRACE -DTHREECHECK -DUSELONGESTPV -DNDEBUG -O3 -DNO_PREFETCH
LDFLAGS: -s TOTAL_MEMORY=33554432 --memory-init-file 0 -s NO_EXIT_RUNTIME=1 -s EXPORTED_FUNCTIONS=[_main, _uci_command] --pre-js pre.js --post-js post.js -O3
Testing config sanity. If this fails, try 'make help' ...
make ARCH=js COMP=emscripten all
make[1]: Entering directory '/home/builder/stockfish.js/src'
Makefile:613: recipe for target '.depend' failed
make[1]: [.depend] Error 127 (ignored)
em++ -Wall -Wcast-qual -std=c++11 -DANTI -DATOMIC -DCRAZYHOUSE -DHORDE -DKOTH -DRACE -DTHREECHECK -DUSELONGESTPV -DNDEBUG -O3 -DNO_PREFETCH -c -o bitbase.o bitbase.cpp
make[1]: execvp: em++: Permission denied
<builtin>: recipe for target 'bitbase.o' failed
make[1]: *** [bitbase.o] Error 127
make[1]: Leaving directory '/home/builder/stockfish.js/src'
Makefile:491: recipe for target 'build' failed
make: *** [build] Error 2
vjuneja$
Tried running assudo as well.
When I try to use the web assembly version I get an error in the browser
This is how I serve the wasm
files with NestJs
@Get('webworker-wasm.js')
private getWebworkerWasmSfjs(req: Request, res: Response) {
Logger.Info('Serving file ../../node_modules/stockfish.js/stockfish.wasm.js');
fs.readFile('../../node_modules/stockfish.js/stockfish.wasm.js', 'utf8', (err: any, data: string) => {
// Buffer.concat(data)
if (err) {
console.log(err);
}
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Request-Method', '*');
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
res.setHeader('Access-Control-Allow-Headers', '*');
// res.setHeader('Content-Type', 'application/wasm');
res.setHeader('Content-Type', 'application/javascript');
// res.writeHead(200, {'Content-Type': 'application/wasm'});
res.status(200).end(data);
});
}
@Get('stockfish.wasm')
private getWebworkerWasmSf(req: Request, res: Response) {
Logger.Info('Serving file ../../node_modules/stockfish.js/stockfish.wasm');
fs.readFile('../../node_modules/stockfish.js/stockfish.wasm', 'binary', (err: any, data: Buffer) => {
// Buffer.concat(data)
if (err) {
console.log(err);
}
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Request-Method', '*');
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
res.setHeader('Access-Control-Allow-Headers', '*');
res.setHeader('Content-Type', 'application/wasm');
// res.writeHead(200, {'Content-Type': 'application/wasm'});
res.status(200).end(data);
});
}
In my browser I execute it as follows
engine = new Worker(`http://localhost:${this.port}/files/webworker-wasm.js`);
engine.postMessage('uci');
engine.postMessage('setoption name Move Overhead value 200');
engine.postMessage('position fen rnbqkbnr/pppppppp/8/8/8/P7/1PPPPPPP/RNBQKBNR b KQkq - 0 1');
engine.postMessage('go wtime 59000 btime 60000');
Maybe I'm serving the files wrong or am I using wrong options. Any suggestions?
Here, there's only 3 possibles moves: https://fr.lichess.org/analysis/standard/3k4/p2n4/Pp2Q3/4P3/5qPb/1N6/1P5K/6B1_w_-_-_5_44
the local engine doesn't start with 4 best lineshttps://fr.lichess.org/IQbOWke5#88
with 1 best line, it's OK
with 2 or 3 best lines, the engine doesn't start
optimize=no | optimize=yes | |
---|---|---|
Chrome 57 | ✔ | ✔ |
Firefox 49 | ✔ | ✔ |
Safari 9.1.3 | :-( | ✔ |
The js error:
TypeError: Module['___cxa_is_pointer_type'] is not a function.
(In 'Module['___cxa_is_pointer_type'](throwntype)', 'Module['___cxa_is_pointer_type']' is undefined)
Built with OS X 10.11.6, LLVM 8.0.0, emscripten 1.37.1. I was trying to debug the wonky elapsed clock in safari, but it's difficult to trace through without optimize=no.
Following instructions from the readme and emscripten, I get this error
stockfish.js git/ddugovic
❯ ./build.sh
Config:
debug: 'no'
sanitize: 'no'
optimize: 'yes'
arch: 'any'
bits: '32'
kernel: 'Darwin'
os: ''
prefetch: 'no'
popcnt: 'no'
sse: 'no'
pext: 'no'
Flags:
CXX: em++
CXXFLAGS: -Wall -Wcast-qual -std=c++11 -DANTI -DATOMIC -DCRAZYHOUSE -DHORDE -DKOTH -DRACE -DTHREECHECK -DNDEBUG -O3 -mdynamic-no-pic -DNO_PREFETCH -flto
LDFLAGS: -s TOTAL_MEMORY=33554432 --memory-init-file 0 -s NO_EXIT_RUNTIME=1 -s EXPORTED_FUNCTIONS=[_main, _uci_command] -s EXTRA_EXPORTED_RUNTIME_METHODS=[ccall] --pre-js pre.js -s WASM=0 -s LEGACY_VM_SUPPORT=1 -O3 -Wall -Wcast-qual -std=c++11 -DANTI -DATOMIC -DCRAZYHOUSE -DHORDE -DKOTH -DRACE -DTHREECHECK -DNDEBUG -O3 -mdynamic-no-pic -DNO_PREFETCH -flto
Testing config sanity. If this fails, try 'make help' ...
/Library/Developer/CommandLineTools/usr/bin/make ARCH=js COMP=emscripten all
em++ -Wall -Wcast-qual -std=c++11 -DANTI -DATOMIC -DCRAZYHOUSE -DHORDE -DKOTH -DRACE -DTHREECHECK -DNDEBUG -O3 -mdynamic-no-pic -DNO_PREFETCH -flto -c -o bitbase.o bitbase.cpp
em++ -Wall -Wcast-qual -std=c++11 -DANTI -DATOMIC -DCRAZYHOUSE -DHORDE -DKOTH -DRACE -DTHREECHECK -DNDEBUG -O3 -mdynamic-no-pic -DNO_PREFETCH -flto -c -o bitboard.o bitboard.cpp
clang-13: error: unsupported option '-mdynamic-no-pic' for target 'wasm32-unknown-emscripten'
clang-13: error: unsupported option '-mdynamic-no-pic' for target 'wasm32-unknown-emscripten'
em++: error: '/Users/robertwebb/emsdk/upstream/bin/clang++ -DEMSCRIPTEN -fignore-exceptions -flto=full -Xclang -iwithsysroot/include/SDL -target wasm32-unknown-emscripten -D__EMSCRIPTEN_major__=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=14 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -flegacy-pass-manager -Werror=implicit-function-declaration --sysroot=/Users/robertwebb/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -Wall -Wcast-qual -std=c++11 -DANTI -DATOMIC -DCRAZYHOUSE -DHORDE -DKOTH -DRACE -DTHREECHECK -DNDEBUG -O3 -mdynamic-no-pic -DNO_PREFETCH -flto -c bitboard.cpp -o bitboard.o' failed (1)
make[1]: *** [bitboard.o] Error 1
make[1]: *** Waiting for unfinished jobs....
clang-13: error: unsupported option '-mdynamic-no-pic' for target 'wasm32-unknown-emscripten'
clang-13: error: unsupported option '-mdynamic-no-pic' for target 'wasm32-unknown-emscripten'
em++: error: '/Users/robertwebb/emsdk/upstream/bin/clang++ -DEMSCRIPTEN -fignore-exceptions -flto=full -Xclang -iwithsysroot/include/SDL -target wasm32-unknown-emscripten -D__EMSCRIPTEN_major__=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=14 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -flegacy-pass-manager -Werror=implicit-function-declaration --sysroot=/Users/robertwebb/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -Wall -Wcast-qual -std=c++11 -DANTI -DATOMIC -DCRAZYHOUSE -DHORDE -DKOTH -DRACE -DTHREECHECK -DNDEBUG -O3 -mdynamic-no-pic -DNO_PREFETCH -flto -c bitbase.cpp -o bitbase.o' failed (1)
make[1]: *** [bitbase.o] Error 1
make: *** [build] Error 2
This is probably due to latest emscripten being incompatible with this build, going to try to find either a different stockfish js or the correct version of emscripten to use.
The engine doesn't seem to be responding to eval UCI command, is there a specific UCI sequence needed for debug output?
So i'm having an issue in my code where the stockfish.wasm.js file can't find the stockfish.wasm file.
myFunctions.loadChessEngine = function() {
if(!lozzaObjectURL) {
lozzaObjectURL = URL.createObjectURL(new Blob([GM_getResourceText('stockFish.js')], {type: 'application/javascript'}));
}
if(!wasmObjectURL) {
wasmObjectURL = URL.createObjectURL(new Blob([GM_getResourceText('stockFish.wasm.js')], {type: 'application/javascript'}));
}
if(!wasmFile) {
wasmFile = URL.createObjectURL(new Blob([GM_getResourceText('stockFish.wasm')], {type: 'application/wasm'}));
}
console.log(lozzaObjectURL);
console.log(wasmObjectURL);
var wasmSupported = typeof WebAssembly === 'object' && WebAssembly.validate(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
console.log('Webassembly supported: '+wasmSupported);
if(lozzaObjectURL && wasmObjectURL) {
engine.engine = new Worker(wasmSupported ? wasmObjectURL : lozzaObjectURL);
//engine.engine = new Worker(lozzaObjectURL);
engine.engine.onmessage = e => {
parser(e);
};
engine.engine.onerror = e => {
console.log("Worker Error: "+e);
};
engine.engine.postMessage('ucinewgame');
}
console.log('loaded chess engine');
}
(The code tag wasn't working on GitHub for me. :( )
I'm currently trying to load the files through blob and stockfish.wasm.js can't find the stockfist.wasm file.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.