README of GNU Chess

  Copyright (C) 2001-2011 Free Software Foundation, Inc.

  Copying and distribution of this file, with or without modification,
  are permitted in any medium without royalty provided the copyright
  notice and this notice are preserved.

Table of Contents

  Introduction
  Who We Are
  Auxillary File Formats (PGN, EPD)
  Compilers
  Internet
  Xboard/Winboard
  Config file
  Environment variables
  Command List
  Book
  Background of v6
  Guidelines followed to develop GNU Chess v6
  Chess protocol adapter
  Design approach
  GNU Chess commands
  Organization of the source code
  C/C++ coexistence

Introduction
------------

Welcome to the GNU Chess 6 README. GNU Chess 6 is the new version of GNU Chess.

Who we are
----------

We are the GNU Chess developers and you may reach us at 

	bug-gnu-chess@gnu.org

We are indebted to our sponsor, the Free Software Foundation
whose web page is:

	http://www.gnu.org

and which also serves as our software depository for new versions of
GNU and GNU Chess.

We also have a Usenet bulletin board, gnu.chess. Feel free to post and
support. Please become a developer and contribute your time and coding skill
to GNU Chess. Make a donation of your time and money.

But, as developers we like to develop our own ideas. Thus, if you have
an idea check to see that no one else is working on it (posting on the
above bulletin board or sending an email should be sufficient to find
if someone is working on the idea and if you can collaborate with
them.)

We don't like messages asking us to implement features. Everybody
has a list a mile long. Instead, contribute by writing code or pointing
out very clearly a bug. To report a bug, tell us the version number
of the program ("./gnuchess --version").

The code is provided for the purpose of encouraging you to do the
programming.  If you lack the programming skills to do so, try
dabbling in it. You might surprise yourself.

Auxiliary file formats
----------------------

.bin - binary book format
.pgn - game listing like 1. e4 e5 2. Nf3 etc.
.epd - epd-style format using FEN notation. See tests subdirectory for example.
log.nnn - record of an entire game from computer's viewpoint (thinking, etc.)
game.nnn - record of an entire game, similar to .pgn but auto-generated

The .bin file format is a simple binary format for the compiled book
which is read by the program when it is using book. See the book section
for more detail.

EPD and PGN require little introduction. These are the uniformly accepted
standards for position recording and game recording.

Note that log.nnn and game.nnn files are written at the end of a game
when you use the "name" command to give the computer your name. It is
highly recommended to do this since the resulting two files that match
in a monotonically-increasing extension numbered suffix may be used for
reporting bugs and keeping track of your games.

Compilers
---------

  We like GNU C in all its various forms. For Mac OS X, Unix and GNU/Linux, 
  use GNU C.

  For Microsoft Windows platforms we compile and test using Cygwin,
  which is a port of many GNU packages, including GCC.

  Cygwin may require specific run time DLL's to provide the interface, 
  these should be provided with any executable you receive.

  Whilst GCC is the supported compiler, a key goal is portability. If
  you experience problems compiling GNU Chess with a modern C compiler
  please let the developers know.

  Note: the current version does not support Microsoft Windows yet.

Internet
--------

  GNU Chess 6 has been tested on the Free Internet Chess Server (freechess.org)
  with Xboard (See Zippy documentation in the Xboard/Winboard distribution 
  http://www.tim-mann.org/).

XBoard/WinBoard
---------------

  Running the program with the "--xboard" command line parameter sets it
  to produce output acceptable to and accept input suitable for xboard
  and winboard, the graphical display front-ends with mouse interface.

  For historical reasons the option "xboard" does not need to be 
  preceeded by "--", however we would encourage the new syntax.

  How to run xboard with GNU Chess as chess backend:

    xboard -fd . -fcp 'gnuchess --xboard'

Config file
-----------

  A file called 'gnuchess.ini' is used to define configuration options.
  The file is looked in three places according to the following precedence:
    1) The directory where the program was started
    2) $GNUCHESS_PKGDATADIR
    3) The the package data directory stated at configure time

  See doc/README_adapter for details. 

Environment variables
---------------------

  If GNUCHESS_PKGDATADIR is defined, it will be taken as the path for
  the config file and for the book, in case the files are not found in the
  current directory. If it is not defined, they will be taken from the 
  package data directory, in case the files are not found in the current
  directory.

Command list
------------

  Moves are accepted either in standard algebraic notation (SAN) or
  in coordinate algebraic notation. Examples:
        Nf3
        g1f3
        O-O
        e1g1

  ^C
	Quit the program.

  quit
	Quit the program.
  exit
	In analysis mode this stops analysis, otherwise it quits the program.

  help
	Produces a help blurb corresponding to this list of commands.

  usage
	Produce blurb on command line options.
	(Same as "gnuchess --help")

  book
	add - compiles book.dat from book.pgn
	on - enables use of book
	off - disables use of book
	best - play best move from book
	worst - play worst move from book
	random - play any move from book
	
	prefer (default) - choose a good move from book
	(Method subject to variation)

        Note: only 'book add' is supported at the moment. In order to enable
              and disable the book, see the book section.

  version
	prints out the version of this program
	(Same as "gnuchess --version")

  pgnsave FILENAME
	saves the game so far to the file from memory

  pgnload FILENAME
	loads the game in the file into memory

  force
  manual
	Makes the program stop moving. You may now enter moves
	to reach some position in the future.
	(Same as "gnuchess --manual")
   
  white
	Program plays black, set white to move.

        Note: not implemented in this version.

  black
	Program plays white, set black to move.

	(White and black commands are mainly for icsDrone
	 and will cause the current en-passant capture
	 square to be forgotten).

        Note: not implemented in this version.

  go
	Computer takes whichever side is on move and begins its
	thinking immediately

  easy 
	Disables thinking on opponent's time
	(Same as "gnuchess --easy").

  hard
	Enables thinking on opponent's time

  post
	Arranges for verbose thinking output showing variation, score,
	time, depth, etc.

	If pondering (see hard) is on, the program will output
	it's thinking whilst the opponent is thinking.

	(Also "gnuchess --post")

  nopost
	Turns off verbose thinking output

  name NAME
	Lets you input your name. Also writes the log.nnn and a
	corresponding game.nnn file. For details please see
	auxillary file format sections.

  result
	Mostly used by Internet Chess server.

  activate

	This command reactivates a game that has been terminated automatically
	due to checkmate or no more time on the clock. However, it does not
	alter those conditions. You would have to undo a move or two or
	add time to the clock with level or time in that case.

        Note: not implemented in this version.

  rating COMPUTERRATING OPPONENTRATING
	Inputs the estimated rating for computer and for its opponent

  new
	Sets up new game (i.e. positions in original positions)

  time
	Inputs time left in game for computer in hundredths of a second.
	Mostly used by Internet Chess server.

  otim
	Mostly used by Internet Chess server.

  random
	Randomizes play by perturbing the evaluation score slightly.
	The degree of perturbation is adjustable.

        Note: not implemented in this version.

  hash
	on - enables using the memory hash table to speed search
	off - disables the memory hash table

        Note: not implemented in this version.

  hashsize N
	Sets the hash table to permit storage of N positions
	N is rounded down to nearest power of 2.
	(Also "gnuchess --hashsize=N")

        Note: not implemented in this version.

  null
	on - enables using the null move heuristic to speed search
	off - disables using the null move heuristic

        Note: not implemented in this version.

  xboard
	on - enables use of xboard/winboard
	off - disables use of xboard/winboard
	(Also "gnuchess --xboard")

  depth N
	Sets the program to look N ply (half-moves) deep for every
	search it performs. If there is a checkmate or other condition
	that does not allow that depth, then it will not be 

  level MOVES MINUTES INCREMENT
	Sets time control to be MOVES in MINUTES with each move giving
	an INCREMENT (in seconds, i.e. Fischer-style clock).

  load
  epdload
	Loads a position in EPD format from disk into memory.

  save
  epdsave
	Saves game position into EPD format from memory to disk.

  switch
	Switches side to move
 
        Note: not implemented in this version.

  solve FILENAME
  solveepd FILENAME
	Solves the positions in FILENAME

  remove
	Backs up two moves in game history

  undo
	Backs up one move in game history

  show
	board - displays the current board
	time - displays the time settings
	moves - shows all moves using one call to routine
	escape - shows moves that escape from check using one call to routine
	noncapture - shows non-capture moves
	capture - shows capture moves
	eval [or score] - shows the evaluation per piece and overall
	game - shows moves in game history
	pin - shows pinned pieces

        Note: 'show eval' and 'show pin' not implemented in this version.

  test
	movelist - reads in an epd file and shows legal moves for its entries
	capture - reads in an epd file and shows legal captures for its entries
	movegenspeed - tests speed of move generator
	capturespeed - tests speed of capture move generator
	eval - reads in an epd file and shows evaluation for its entries
	evalspeed tests speed of the evaluator

        Note: not implemented in this version.

  analyze
	Switches program into analysis mode, this is primarily intended for
	communicating analysis to an external interface using the Xboard 
	chess engine protocol. It enables "force", "post", and
	"hard", at the same time, whilst altering the
	output format of post to conform with the engine protocol.	

Book
----

Using a book can save time at the beginning of a game. Either the adapter or
the engine can handle a book. See doc/README_adapter.

The book format is binary. It can be generated from a PGN file. The standard
distribution includes a small book, which is placed at the package data 
directory. A larger source book can be found at:
http://ftp.gnu.org/pub/gnu/chess/book_1.02.pgn.gz

How to compile the book:
1. Unzip and copy the book pgn file (book_1.02.gpn) to the directory where you 
run GNU Chess.
2. Start GNU Chess.
3. Execute the following command: 'book add book_1.02.pgn'.
'book.bin' is created.

The book will be handled by the adapter if the following values are set in the 
[Polyglot] section of the configuration file gnuchess.ini:

Book = true
BookFile = book.bin

The book will be handled by the engine if the following values are set in the 
[Engine] section of the configuration file gnuchess.ini:

OwnBook = true
BookFile = book.bin

Background of v6
----------------

Since version 5.07 of GNU Chess was released in 2003, GNU Chess has basically
remained unchanged. Then Fabien Letouzey developped the famous Fruit, which 
proved to be a stronger chess engine. At some point in time, he kindly granted 
FSF permission to make Fruit 2.1 (the latest free version) the base for a 
future release of GNU Chess. 

Therefore, it can be fairly said that Fabien Letouzey is remarkably the main 
contributor to GNU Chess v6.

Guidelines followed to develop GNU Chess v6
-------------------------------------------

The idea is to use Fruit 2.1 as the base for GNU Chess v6, keeping external
interfaces backwards compatible. This is particularly important since
GNU Chess has been  world-wide used for long.

GNU Chess can be used in two modes: interactively using the command-line 
interface on a text console, and used as backend engine from a graphical 
frontend. Both cases rely on almost identical grammar. The former is described
in GNU Chess help. 

When GNU Chess is used as a pure chess engine, for instance, as backend for
Xboard, it uses the Chess Engine Communication Protocol, which is described
here:
http://home.hccnet.nl/h.g.muller/engine-intf.html

Since Fruit uses the Universal Chess Interface (UCI), keeping the former
interface is the main challenge of GNU Chess v6. UCI is described here:
http://wbec-ridderkerk.nl/html/UCIProtocol.html

GNU Chess can also run as a UCI chess engine, if the -u/--uci command-line
option is specified.

Chess protocol adapter
----------------------

UCI is very different from the Chess Engine Communication Protocol. Fortunately
Fabien coped with this and developed Polyglot, a chess protocol adapter that
can be used in front of UCI engines such as Fruit, thus exposing an interface
like that of GNU Chess 5.

Polyglot can be used, along with Fruit, as chess engine for chess frontends,
suchs as Xboard. In this case, Polyglot and Fruit run as two independent
single-threaded processes. Polyglot starts first, and it forks Fruit. Both
processes get communicated by by means of pipes: Polyglot captures Fruit's
standrad input and output.

Polyglot 1.4 has been incorporated to GNU Chess v6.

Design approach
---------------

We want to keep three loosely-coupled modules in GNU Chess v6:
- frontend
- adapter
- engine

The main program contains the frontend and starts two threads, one for the
adapter, one for the engine. The three components comprise a chain, thus
there are two links:
- frontend <--> adapter
- adapter  <--> engine

The links are based on pipes. There is no need for additional synchronization
mechanisms such as mutex. The changes in Polyglot and Fruit are minimal, since
they were already using the same mechanism to communicate with each other.

Another technical problem was the fact that GNU Chess 5 was written in C,
whereas Polyglot and Fruit are written in C++. In GNU Chess v6 the main 
program, the adapter and the engine are in C++, but the frontend remains in C.

GNU Chess commands
------------------

Some of the commands are passed on to the adapter/engine, other are locally
implemented by the frontend.

Organization of the source code
-------------------------------

Source code was placed under a single 'src' in GNU Chess 5, as usual.
For the time being, three additional directories have been created  for
GNU Chess v6, so the code is organized in four directories:

src
src\frontend
src\adapter
src\engine

The sources in each src subdirectory are compiled as a static library. When
link with the sources in top src, they result into the binary 'gnuchess'.
The module libraries are named after their respective directory name:
libfrontend.a
libadapter.a
libengine.a

* src

Contains the 'main' and a file used to create the pipes that communicate the
three modules: frontend, adapter and engine.

* src/frontend

Contains the frontend. The code here is inherited from GNU Chess 5, with some
modifications mainly in cmd.c and a new file engine.c which addresses the
message passing through modules.

* src/adapter

Contains the chess protocol adapter, based on Polyglot 1.4. Minor changes, wrt
the baseline.

* src/engine

Contains the chess engine, based on Fruit 2.1. Minor changes wrt the baseline.

C/C++ coexistence
-----------------

There is no problem in having both C and C++ in the same program. However, 
there is no technical reason for this heterogeneity. The only reason is the
different origins of the code. It is desirable to get a more homogeneous
program.

Polyglot and Fruit have a common origin, which means that there is a lot of
shared code. The point is that the shared code is very similar but not
identical, which would make hard an eventual unification. In order to avoid
massive name clash, all the code has been wrapped in namespaces, one for the
adapter, one for the engine. The frontend remains compiled as C code.
