UCI and XBoard Protocols for Android

Chess for Android is a chess application for the Android platform
that supports the Universal Chess Interface (UCI) and Chess Engine Communication Protocol
(often simply called the XBoard or WinBoard protocol). This feature allows replacing the
built-in Java chess engine with more powerful third party engines. Users can either play
an imported engine directly, use infinite analysis to study games, or even run tournaments between engines
(see e.g. Android chess engines tournaments).
This page gives some background on the feature. Detailed instructions can be found in the
Chess for Android Manual.

UCI and XBoard

The
Universal Chess Interface (UCI)
was designed by Stefan Meyer-Kahlen and Rudolf Huber
as an open interface between a chess engine and a chess
GUI. The interface allows chess programmers to focus on
writing the chess engine, leaving details such as board
setup and play, clock and notation display, and possibly
opening book and root-level endgame tablebases play to
the GUI. Examples of programs on Windows, Linux, and
Mac OS with UCI engine support are
Arena,
ChessBase Fritz,
Lucas Chess, and
Sigma Chess.
In August 2010, Chess for Android
was the first program that introduced UCI
support on the Android platform.

The
Chess Engine Communication Protocol (often simply called the
XBoard or WinBoard protocol), designed by Tim Mann and H.G.Muller,
provides an alternative protocol between chess engines and a chess GUI.
In October 2011, Chess for Android
was also the first program that introduced
XBoard protocol on the Android platform.

Android Development

Applications for the Android platform (mainly ARM-based devices,
although x86-based devices are emerging as well) can be developed in
several ways.

(1) Most development for Android is done using the
Android SDK
and the Java programming language. An application is compiled
into bytecode that used to run on the Dalvik Virtual Machine or, from Android 5.0 (Lollipop)
forward, on ART (Android RunTime), making this approach
the most portable (it runs on ARM and x86, as well as on possible future architectures).
Because bytecode interpretation has lower performance than native code, Android 2.2 (Froyo)
introduced the Dalvik JIT compiler, which translates bytecode into native code right before
execution for a speed boost. Since then ART has replaced this with an optimizing AOT/JIT
compiler. The Chess for Android GUI and its built-in engine are implemented
using this first approach, and ship as a single package.

(2) Alternatively, developers that want higher performance can use the
Android NDK
to write performance-critical portions in C/C++, which is compiled
into native code (ARM and/or x86). Those native components are then
embedded through JNI in a regular Android application that is developed
with the SDK. In this second approach, the bytecode and native components
still ship as a single package.

(3) Finally, developers can do all development in C/C++ and generate
stand-alone native code using the appropriate compiler toolchain (e.g.
CodeSourcery for ARM
or the toolchain that ships with the NDK).
This third approach is used by Chess for Android to
import engines that do not ship with the application.
Users can first get Chess for Android from the Google Play,
and later install third party engines from any other (possibly private) source.

UCI and XBoard Engines for Android

Although Chess for Android runs on any Android device,
it is important that the engine has been compiled into proper
native code for that device. Currently, the Android platform
distinguishes between x86-based devices and ARM-based devices.
Any engine binary that has been compiled for 32-bit x86 Linux will work
for x86 Android as well. This format is widely available for many chess engines.
Engine binaries compiled for ARM are not as widespread yet, although the list is growing.
Some examples are given below.

Importing UCI and XBoard Engines in Chess for Android

Before UCI and XBoard engines can be imported in Chess for Android,
they first must be installed in internal memory as follows
(Android Chessbase compatible engines, such as in the
Android Chess Engines Package,
do not need this step; such engines are directly available for import):

Get one or more engines in the proper native format
(ARM for most mobile devices, x86 for a few others).
You can either compile your own engine or obtain binaries elsewhere.

Copy the engines anywhere on the SD card of the Android
device. To do this from a desktop, connect the device through
the USB cable and select the USB storage option. This
usually pops up a navigation window to which engines
can be dragged-and-dropped. Alternatively, one can
download engines directly to the device over the
internet (this typically saves in /sdcard/download).

Open Chess for Android on the device, long press the
notation window, enter the UCI and XBoard submenu,
and select Install Engine from SD, which
opens a file navigation window. Select the appropriate
engine and wait until a message pops up that the
engine has been installed on internal memory.
Repeat this install for every new engine.

Optionally, if useful for any of the installed engines,
copy the Nalimov, Gaviota, Scorpio, and/or Robbobases endgame
tablebases to SD card in the recommended default folders
/sdcard/tb, /sdcard/gtb,
/sdcard/egbb, and/or /sdcard/robbo,
respectively (complete 3- and 4-piece Nalimov takes 29.6MB,
complete 3-, 4- and 5-piece Nalimov takes 7.05GB).
This only has to be done once per Android device.
Engine authors probably need to change
probing heuristics when reading from SD card.

To actually import an engine in Chess for Android for game play, go
to the UCI and XBoard submenu again, but now pick Import Engine
and select the appropriate engine from the list of installed engines.
If the import is successful, a window pops up with the engine name and
author to indicate that the built-in Java chess engine now has been
replaced by the imported engine (exiting the application
unloads the engine). Some screenshots are shown below. Also see the
Chess for Android Manual.