naddu

Naddu

Naddu is a Javascript UCI chess engine.

It can be easily included in your web pages.

All you need is naddu.js from the repo root.

The code is written in a straightforward style and deliberately easy to tweak.

Strength is around 2400 Elo.

The hash table defaults to 16 MB and can be set with setoption name Hash value <mb>.

Hello world

const naddu = new Worker('naddu.js');
const ucioutput = document.getElementById('ucioutput');

naddu.onmessage = function(e) {
  ucioutput.textContent += e.data + '\n'; // naddu reponds with text as per UCI 
};

naddu.postMessage('uci');
naddu.postMessage('ucinewgame');
naddu.postMessage('position startpos');
naddu.postMessage('board');
naddu.postMessage('eval');
naddu.postMessage('go depth 8');
naddu.postMessage('go movetime 1000')

Try this example here: https://op12no2.github.io/naddu/examples/hello_world.html

More examples

UCI commands

UCI is richer than this, these are the commands Naddu implements:-

A search runs to completion inside the worker and replies with info lines and then bestmove. Commands sent while it is searching queue up until it finishes. So stop cannot interrupt a search and go infinite runs until the worker is killed. To stop a search, kill the worker and make a new one:-

naddu.terminate();
naddu = new Worker('naddu.js');

UCI options

Reported by uci and set with setoption name <name> value <value>, the name is not case sensitive:-

UCI extensions

Extra commands handy for web pages and testing, with any shortform in parenthsis:-

Some standard UCI commands and sub-commands have shortforms too:-

Allowing useful quick sequences like:-

u
p s
b
g d 10
q

go on its own searches for 100 ms.

Piece square tables

The pst command prints, sets and resets the piece square tables, so a page or a script can restyle the engine without editing it. Pieces are p n b r q k, which means both colours with black mirrored, or wn, bq etc for one colour. Squares are absolute, e4 is e4 for either colour. Values are in centipawns a1 to h8, mg is middlegame and eg endgame. Not case sensitive. Any change clears the hash.

Command line

Naddu can also be started from a command line using Node or Bun:-

node naddu.js

Or give it commands:-

bun naddu.js uci ucinewgame "position startpos" "go depth 8"

Creating binaries

You can create executables using Bun:-

bun build naddu.js --compile --minify --target=bun-windows-x64   --outfile=naddu-win-x64
bun build naddu.js --compile --minify --target=bun-windows-arm64 --outfile=naddu-win-arm64
bun build naddu.js --compile --minify --target=bun-linux-x64     --outfile=naddu-linux-x64
bun build naddu.js --compile --minify --target=bun-linux-arm64   --outfile=naddu-linux-arm64
bun build naddu.js --compile --minify --target=bun-darwin-x64    --outfile=naddu-mac-x64
bun build naddu.js --compile --minify --target=bun-darwin-arm64  --outfile=naddu-mac-arm64

The Linux arm64 binary runs on a Raspberry Pi 3 or later with a 64-bit OS. Add -musl to the Linux targets for Alpine.