Integrating Lozza into your project

You are free to integrate an unmodified Lozza into your own non-commercial projects. In return please link to http://op12no2.me/toys/lozza. If you wish to modify Lozza please email me for a chat first: colin@sailwave.com, thanks.

The Lozza engine itself is self-contained in a single Javascript file (link at bottom of this post) and typically runs in a web worker.  A controlling program  can communicate with Lozza using the string based UCI protocol over the JSON web worker interface.

This is a very simple example:-

http://op12no2.me/toys/lozza/ex.htm

It fires up Lozza in a web worker and asks it to find the best move for a 10 ply search, sending all output to a HTML element called dump using jQuery:-

It looks like this:-

var lozza = new Worker('lozza.js');

lozza.onmessage = function (e) {
  $('#dump').append(e.data);
};

lozza.postMessage('uci');         // get build etc
lozza.postMessage('ucinewgame');  // reset TT
lozza.postMessage('position startpos');
lozza.postMessage('go depth 10'); // 10 ply search

Lozza can auto-detect if it’s running in a node.js context allowing seamless use online in a browser context and offline in node.

This allows Lozza run both online and offline on pretty much any platform, including Windows, Linux and Mac.

For example this image is a dump of the same 10 ply search using node from the Windows command line:-

The “info string debug…” lines show overall time and node count etc and are not strictly part of the UCI protocol.  You can either filter them out or change this.debugging to false in the UCI class.

Lozza can be used outside of a web worker by including lozza.js in your HTML file and then using the loz* classes directly.  This is useful for profiling etc.

The Lozza source itself is here:-

http://op12no2.me/toys/lozza/lozza.js

You are also free to mine any of the example user interfaces, but please do let me know what you use and credit appropriately; thanks.

Leave a Reply