Stockfish in Lozza UIs

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

op12no2
Posts: 489
Joined: Tue Feb 04, 2014 12:25 pm
Full name: Colin Jenkins

Stockfish in Lozza UIs

Post 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.
op12no2
Posts: 489
Joined: Tue Feb 04, 2014 12:25 pm
Full name: Colin Jenkins

Re: Stockfish in Lozza UIs

Post 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.
James Constance
Posts: 358
Joined: Wed Mar 08, 2006 8:36 pm
Location: UK

Re: Stockfish in Lozza UIs

Post by James Constance »

Very nice - thanks!
op12no2
Posts: 489
Joined: Tue Feb 04, 2014 12:25 pm
Full name: Colin Jenkins

Re: Stockfish in Lozza UIs

Post 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!
op12no2
Posts: 489
Joined: Tue Feb 04, 2014 12:25 pm
Full name: Colin Jenkins

Re: Stockfish in Lozza UIs

Post 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
gladius
Posts: 568
Joined: Tue Dec 12, 2006 10:10 am
Full name: Gary Linscott

Re: Stockfish in Lozza UIs

Post 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 :).
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Stockfish in Lozza UIs

Post by cdani »

Incredible!! :-)
op12no2
Posts: 489
Joined: Tue Feb 04, 2014 12:25 pm
Full name: Colin Jenkins

Re: Stockfish in Lozza UIs

Post 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!
op12no2
Posts: 489
Joined: Tue Feb 04, 2014 12:25 pm
Full name: Colin Jenkins

Re: Stockfish in Lozza UIs

Post 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.
op12no2
Posts: 489
Joined: Tue Feb 04, 2014 12:25 pm
Full name: Colin Jenkins

Re: Stockfish in Lozza UIs

Post 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!).