Quirkafleeg 48K 2.7 - UCI edition
=================================

What this is
------------
The ZX Spectrum 48K chess engine Quirkafleeg 2.7 as a UCI engine for PC chess GUIs
(Arena, Cute Chess, Banksia, Fritz/ChessBase, ...).

It is NOT a stronger PC version. It is the C reference model of the Z80 engine,
running with a virtual Spectrum clock:

  * The search is identical to the Z80 code: same evaluation (the v2.2 weights), same pruning,
    same move ordering, same 512-entry hash table, same 347-move opening book.
    At a fixed depth the C model and the Z80 code search the same tree, node for node
    (checked on 40 positions at depth 5, 25 at depth 6 and 25 at depth 7).
  * Time is counted in Z80 T-states (3.5469 MHz), from a cost model fitted to the real
    Z80 code. When the GUI says "you have 60 seconds", the engine thinks exactly as deep
    as a real 48K Spectrum would in 60 seconds - but it gets there in a fraction of a
    second on a PC.

So the time control you set in the GUI is Spectrum time. The engine plays at real 48K
strength and normally answers almost instantly.

Options
-------
  Ponder     (default true)  Think on the opponent's time, as the Spectrum version does.
                             Pondering runs at real Spectrum speed: in N seconds of the
                             opponent's thinking it gets N seconds of Spectrum work, never more.
  OwnBook    (default true)  Use the 48K opening book (347 positions).
  RealSpeed  (default false) Run every search at real Spectrum speed. Moves then take as long
                             as on a real 48K. Note: at fast GUI time controls the engine may
                             lose on time with this switched on (the clock is checked every
                             256 nodes, about 2 seconds of Spectrum time).

Standard UCI commands are supported: position, go (wtime/btime/winc/binc/movetime/depth/nodes/
infinite/ponder), stop, ponderhit, isready, ucinewgame, quit. movestogo is accepted but not used:
the time manager always budgets about 1/30 of the remaining time plus 3/4 of the increment.
"go infinite" (analysis) is NOT throttled unless RealSpeed is on - analysis therefore runs
at PC speed and goes much deeper than a Spectrum could.

Changes since 2.2
-----------------
  2.3  Endgame: the king-chase (mop-up) bonus is now damped like the rest of the score in
       drawish endings (KB or KN vs K no longer looks like a win), and K+N+N vs a bare king
       is scored as the draw it is. Real wins are scored exactly as before.
  2.4  Opening book: the book key is 16 bits, so an unrelated middlegame or endgame position
       could match a book entry and get a "book" move played without thinking (about 1 game
       in 200). The book is now only used until the first position that is not in it; after
       that the engine always searches. Book lines themselves are unchanged.
  2.5  Endgame knowledge. King, bishop and knight vs a bare king: the bare king is driven to a
       corner of the bishop's colour, so the engine now finds the mate (against Stockfish, 48
       positions at a long time control: 25 mated, before 4). King, bishop and rook pawn(s) vs
       a bare king with the "wrong" bishop (it does not cover the queening square) and the king
       in the corner is scored as a draw (draws held 56 of 60, before 18; wins 59 of 60, before
       56). Middlegames are searched exactly as before, node for node.
  2.6  Pondering. The move to ponder on (the opponent's expected reply) was taken from the hash
       table, whose entry is usually overwritten by the end of a long search, so the engine had
       a move to ponder on in only about a fifth of its moves at long time controls (57 % at 30 s
       per move, 21 % at 120 s). It now takes the reply its own search found: a ponder move
       almost every time (40 of 40 test positions), so it uses the opponent's thinking time far
       more often. The search itself is unchanged, node for node.
  2.7  Speed. The Z80 code was reworked for speed (faster attack tests, move generation, copying
       and evaluation): it now needs 9.3 % fewer T-states per node, and so searches a little
       deeper in the same Spectrum time. The search itself is unchanged, node for node. Measured
       against Stockfish (UCI_Elo 2000, 25,000 nodes per move, 4,000 games per version, paired):
       +1.85 percentage points (95 %: +0.12..+3.58), about +13 Elo.
  The strength figures below were measured with 2.2; the middlegame search and evaluation are the same.

Strength
--------
Measured with the identical C model (1,000 games vs Stockfish limited to UCI_Elo 2100 and a
very short think, about 25,000 nodes per move; from the start position, no pondering): 50.6 %, i.e. about 2,100 on Stockfish's
UCI_Elo scale. That scale is not CCRL or FIDE.

The real Z80 code (v2.2) beat Colossus 4 by 124.0/200 (62 %), both programs pondering,
~10 s per move, both running their original Z80 code at Spectrum speed in an emulator.

Files
-----
  q48.exe   Windows 64-bit engine (single file, no DLLs or data files needed)
  q48       Linux x86-64 engine

Environment variables of the reference model (PARAMS, BOOKFILE, VCOSTFILE, EGK, EGK2, OPKW, ...)
still override the built-in settings; normal users do not need them.

Author: Anders Strange.
