Roller is a fun little javascript chess program that only knows the rules (except 3-fold repetition). It has no semantic knowledge like piece values etc. It plays by performing thousands of random rollouts from the current root position. No search strategy at all. In effect it’s a “pure” MCTS algorithm. Wins, losses and draws are scored 1, -1, 0 and it simply chooses the root move with the highest net score. Obviously at the start of a game this is mostly just random play but it can avoid mate and give mate when they are clearly in sight. You can play Roller here:-

The UCI commands are then available in data.data in onmessage(). Note that more than one command can be present separated by \n and depending on OS also \r, so assume \n and filter out \r. In my own experience null commands can be present \n\n, so watch out for those too.

stdout

var str = ''
...
nodefs.writeSync(1, str + '\n');

The use of writeSync() is so that that the PV feedback displays in chess UIs like Arena and Winboard in real time. If you write using async functions it appears all at once when the best move is sent back.

It’s useful to call the capture function onmessage() because that what web workers assume, thus it can be used in both web and node.js contexts.

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.

Lozza needs a Javascript engine to live in. Usually this is supplied by a web browser, but other applications also embed Javascript engines, the most common and flexible being an application called node.js, allowing you to execute Javascript outside of your browser. node.js is available for most operating systems, including Windows, Linux and Apple.

Download and install node.js (if you get a choice of engines choose google Chrome V8). node.js adds itself to your path and this is assumed in the example commands below.

If that fails maybe node is not in your path, so either use an absolute directory to address node or tweak your path.

To use in a chess UI like Arena or WInboard, use node.exe (etc) as the chess engine and lozza.js as a command line parameter.

To enter a Javascript engine into HG Muller’s monthly chess tourney. First ask him for a user name and password and install Winboard. Then connect with something like this from the winboard directory itself:-

You must solve 10 mate-in-1 puzzles against the clock. Time penalties are added for illegal and wrong moves. You must drag the piece to the mating square to solve the puzzle. The puzzles are loaded at random from a large collection sourced from here:-

In addition to the standard UCI protocol , the following commands can be used:-

stop

Stop the Lozza engine. Useful to stop a long perft or analysis. What actually happens is that the web worker containing Lozza is killed. You’ll need to restart one.

start

Start Lozza. i.e. create a new web worker containing the Lozza. After a start the following are automatically sent:-

uci
ucinewgame
position startpos
board

A start command is issued when the console UI starts.

clear

Clear the previous output.

board

Display a textual FEN and graphical representation of the current position.

perft depth d [moves m] [inner 1|0]

Perform a perft analysis to a depth of d ply based on the current position. m is the expected number of moves and is optional, defaulting to 0. inner 1 will show inner node counts with the default being inner 0

eval

Show how the static evaluation of the current position is constructed.

id idstring

Attach an identification label to the current position. Only relevant if UCI debugging is on.

ping

Check that the engine is alive.

SHORTCUTS

u == ucinewgame

q == quit

p == position

p s == position startpos

g == go

g d = go depth

b == board

NOTES

An explicit ucinewgame is needed to reset the transposition tables; and is required before the first position. It is optional during a game since it has no effect other than to clear the TT.

Lozza plays it’s best move when a go command completes, changing the current position.

The current position is unchanged after a perft

The start, stop and clear commands are not be available when using Lozza offline; for example with node.js. Similarly only the textual board representation is shown.