Page 1 of 2

Stockfish in Lozza UIs

Posted: Wed Jan 07, 2015 3:08 pm
by op12no2
There is a growing need to 'compile' static languages into Javascript for native use in web browsers etc. Mozilla's approach is to use Clang to convert C/C++ to LLVM then emscripten to convert that in a subset of Javascript that minimises garbage collection (asm.js).

Norbert pointed me at a project where somebody had done that for Stockfish 5. https://github.com/exoticorn/stockfish-js

Given that Lozza is a UCI compliant engine needing no extra commands for web use - it's an edit of one line to replace Lozza with stockfish in my web UIs. I tweaked the play UI to take the engine as a paramater:-

Play Lozza (default): http://op12no2.me/toys/lozzadev/play.htm

Play Stockfish: http://op12no2.me/toys/lozzadev/play.htm?e=stockfish.js

So if you want your engine on the web, feel free to start with my UI code or donate your .js file for inclusion in the Lozza repertoire... Can then extend a bit to run Javascript tournys in client browsers...

Thanks Norbert!

PS: Firefox support asm.js explicitly, Google does not, indeed their whole approach to this is different but Stockfish will run in both Browsers. Dunno about Explorer etc.

Re: Stockfish in Lozza UIs

Posted: Wed Jan 07, 2015 4:17 pm
by op12no2
Lozza UCI console + stockfish.js

http://op12no2.me/toys/lozzadev/console ... ockfish.js

The undefined stuff means I must be making some Lozza specific assumptions which I shall resolve.

Re: Stockfish in Lozza UIs

Posted: Wed Jan 07, 2015 5:25 pm
by James Constance
Very nice - thanks!

Re: Stockfish in Lozza UIs

Posted: Wed Jan 07, 2015 6:56 pm
by op12no2
James Constance wrote:Very nice - thanks!
:) Thanks, done the analysis UI as well now.

http://op12no2.me/toys/lozzadev/fen.htm?e=stockfish.js

I've never looked at the Stockfish code but the NPS reported is slow, so it's either an artifact of my UI or it's pruning like my Grandmother used to prune her roses every year. It gets to crazy depths with a tiny node count!

Re: Stockfish in Lozza UIs

Posted: Wed Jan 07, 2015 7:01 pm
by op12no2
The analysis UI can take a FEN and an action (analyse|evaluate). This is stockfish.js analysing fine #70 - it's insane.

http://op12no2.me/toys/lozzadev/fen.htm ... 0-&act=ana

I give up writing Javascript engines by hand :)

This is Lozza doing the same:-

http://op12no2.me/toys/lozzadev/fen.htm ... 0-&act=ana

Re: Stockfish in Lozza UIs

Posted: Wed Jan 07, 2015 7:34 pm
by gladius
Very very cool :). asm.js/emscripten is great stuff. Your UI is really nice too!

I will get UCI support added to garbochess.js one of these days and we can have a js engine tournament :).

Re: Stockfish in Lozza UIs

Posted: Wed Jan 07, 2015 8:28 pm
by cdani
Incredible!! :-)

Re: Stockfish in Lozza UIs

Posted: Wed Jan 07, 2015 10:33 pm
by op12no2
gladius wrote: I will get UCI support added to garbochess.js one of these days and we can have a js engine tournament :).
Yay!

Re: Stockfish in Lozza UIs

Posted: Thu Jan 08, 2015 10:01 am
by op12no2
cdani wrote:Incredible!! :-)
When you consider that Javascript has no 64bit integer type so all Stockfish 5's bitboard stuff is being done 32 bits at a time - and the javascript is being compiled and optimsied in real time - the performance is amazing.

Re: Stockfish in Lozza UIs

Posted: Thu Jan 08, 2015 10:07 am
by op12no2
The Fine #70 comparison is interesting. Stockfish just keeps on quickly getting through the plys, finding Kb1 from the outset. Lozza takes a while to get to the point were it discovers Kb1 then grinds to a virtual halt... I presume the number of legal moves explodes soon after that point? Or I have a bug (better!).