Endgame Tablebases


KKFChess can use Nalimov (both compressed and uncompressed) or it's own endgame tables for regular/wild chess but must use the latter for suicide and atomic chess.

KKFChess supports the generation of 2 to 5-man EGTB using the distance to mate method.

For Nalimov tablebases, the configuration item "EGTBBase" controls the search paths while KKFEGTBBase is used for KKFChess EGTBs.  The following directory structure applies for KKFChess' own EGTBs:

Variant Number of pieces Directory
Normal/Wild 3-piece $KKFEGTBBase\normal\3
  4-piece $KKFEGTBBase\normal\4
  5-piece $KKFEGTBBase\normal\5
Suicide 2-piece $KKFEGTBBase\suicide\2
  3-piece $KKFEGTBBase\suicide\3
  4-piece $KKFEGTBBase\suicide\4
  5-piece $KKFEGTBBase\suicide\5
Atomic 3-piece $KKFEGTBBase\atomic\3
  4-piece $KKFEGTBBase\atomic\4
  5-piece $KKFEGTBBase\atomic\5
Losers 4-piece $KKFEGTBBase\losers\4
5-piece $KKFEGTBBase\losers\5

$KKFEGTBBase is the value given to the configuration item "KKFEGTBBase".  There are no EGTBs for crazyhouse.

If both a compressed and an uncompressed EGTB file is present, KKFChess will use the compressed one.

EGTB generation can be interrupt by pressing the space bar.


KKFChess EGTB File Types

KKFChess' EGTB file format includes:

  • Version control

  • Statistical information

  • Table format (8-bit or 16-bit)

  • Checksum

  • Smaller file size (~50% smaller)

  • Optional indexing block

KKFChess generates 8-bit EGTB tables most of the time but will create 16-bit ones for positions with long mating sequences.  The command option "egtbgen ... comp" will automatically compress the EGTB file after its creation.


EGTB File Sizes

Since EGTB files are uncompressed and are not symmetrically optimised, they can be large.  This is especially true for 4 and 5 piece files.  The table below lists the number of pieces against the file sizes:

# of pieces Min. # of files
suicide / atomic /
normal / losers
Uncompressed size per file
8-bits / 16-bits
2 21 / 0 / 0 / 0 ~4KB / ~8KB
3 126 / 5 / 5 / 0 ~256KB / ~512KB
4 567 / 30 / 30 / 15 ~16MB / ~32MB
5 1932 / 110 / 110 / 75 ~1.00GB / ~2.00GB

Compressed files can help reduce the file size but they are slower to access and can reduce the speed of EGTB generations.


KKFChess EGTB Generation

Attempts to generate 2-piece EGTBs other than suicide chess will create no files.  Also loser chess only has 4 and 5-piece EGTBs.  It is highly recommended that you use uncompressed EGTB files when building "higher" EGTBs ones.

Also note the piece dependencies between EGTB files such as 4-piece files requires the present of all 3-piece ones and positions with pawns requires the present of non-pawn tables for promotions.  The full automated EGTB command "egtbgen all" follows this rule and will generate the tables in the correct sequence.

EGTB file generations for 2 to 4-pieces are done in memory (unless force to use temporary file) and with full size 16-bit tables, hence to generate a 4-piece table, you will need an extra 64MB+ of RAM.  You can force the use of a temporary file for EGTB generation by setting the "UseTempFile" configuration item.  The temporary file resides in the target EGTB directory.  The temporary file replaces the in memory work buffer hence it is a full size table - 4.00GB for a 5-piece file.


EGTB Name

EGTB names must have the following rules:

<Piece type sorted white pieces> "_" <Piece type sorted black pieces>

Piece orders are "P", "N", "B", "R", "Q" then "K".  The program automatically reorders the pieces to produce the correct EGTB name.  Below are some examples of EGTB names:

P_NNQ 1 white pawn, 2 black knights and 1 black queen
PQ_QK 1 white pawn, 1 white queen, 1 black queen and 1 black king
KK_PR 2 white kings, 1 black pawn and 1 black rook
KP_KP 1 white pawn, 1 white king, 1 black pawn and 1 black king.  Note that KKFChess converts it to the ordered form of "PK_PK".


Preferred EGTB Names

EGTB names like "KQ_K" , "QK_K", "K_KQ" and "K_QK" can all be used to represent a king+queen vs pawn position.  This causes problems when generating EGTB files - which name to use?  With piece-sorting, this number is reduced to two - "QK_K" and "K_QK" - one for white holding 2 pieces and one for black holding 2 pieces.

KKFChess only needs one of the files as it can perform "colour swapping" probes.  So "K_QK" actually holds information about "QK_K" also; this helps to save disk space.  For automatic EGTB creation, KKFChess will always create files with white having less or the same number of pieces as black.


Automated EGTB Generation

The "egtbgen" console command is used to automatically create EGTB files.  The partial solutions are kept in memory (or temporary file) and only the final results are useable for probing.  To force the use of temporary files instead of memory, set the configuration item "UseTempFile" to "Yes" or use the command "egtbcache file".  You can also change the amount of file cache memory with either the configuration item "EGTBCacheSize" or the command "egtbcache <size>".

There are additional automated options when generating EGTBs which allows you to create all N-pieces tables or all supported piece tables.  See Console Command Summary for details.

Below are the steps to generate an EGTB file for atomic chess of one white king, one white queens and one black king:

  1. Start the program under a DOS prompt.

  2. Start a new atomic game by typing "atomic".

  3. [Optional]  Enable the verbose mode with "verbose" or "post".

  4. Start the EGTB creation with "egtbgen KQ_K" or "egtbgen K_QK"; the latter name is preferred.

  5. Wait till the process completes (progress is shown on the screen if verbose mode is on).

If the target EGTB file already exists, KKFChess will play it safe and not overwrite it.  Any error during EGTB generation in automatic mode will cause the program to skip to the next file.

The command "egtbgen all" will generate the minimum number of files in the correct order.  The files will be created in the correct EGTB directory path, skipping over files that are already there.


Continuing After an Abnormal Program Termination

KKFChess outputs partial solution files during EGTB generation of 4 or 5-piece EGTBs.  The partial solution file (*.peg or *.tmp, depending if temporary file is used) are updated at fixed iteration intervals and its data will be automatically loaded at the start of the first iteration.  Hence you can terminate the program at iteration 20, say, and continue at a point just less than iteration 20 the next time you generate the same EGTB file.  The use of partial solution file is totally transparent.

As mentioned before, KKFChess will not overwrite any existing EGTB files when generating new ones so it is safe to issue commands like "egtbgen all" to generate the missing files.


Compressing / Decompressing EGTBs

The command "egtbcomp" is used to compress EGTB files.  It's syntax is similar to "egtbgen", some examples are:

egtbcomp N_N Compresses the N_N.fkg file into a N_N.fgz file.
egtbcomp 3 Compresses all the 3-piece files.
egtbcomp all Compresses all the EGTB files.
egtbcomp N_* 3 Compresses all the 3-piece EGTB files that has one white knight and 2 black pieces.  V2.5.13 onwards.  The pattern is the same as the MSDOS' "dir" command.

The files "egtbcomp" operates on are those based on the current chess variant.  Once compressed, the "*.fkg" files can be deleted.

To decompress EGTB file(s), use the command "egtbdecomp".


Speeding up EGTB Generation and Probing

If you have a lot of memory (>=128MB) then you can speed up the EGTB generation or probing by enabling caching of recently accessed EGTB files with the "cacheegtbfile" command BEFORE starting the EGTB generation.  The maximum memory used by caching is 64MB.  Caching works on both compressed and uncompressed EGTB files.


Downloading EGTBs

EGTBs files are no longer available for download since they can be generated fairly quickly.


Limitations of EGTBs

KKFChess's EGTBs do not support positions that contain en passant captures.  In fact KKFChess recognises this and EGTB probing will always fail for such positions.  This is deliberate since no en passant information is stored in the EGTB files.

Also the detection of draws (50 moves, 3-fold repetitions, not enough mating material, positional draws, etc.) are decided in the search routine(s) and not by the EGTBs.


EGTB Statistical Information

The command "egtbinfo" reads in an EGTB file and displays a summary of the statistical information of that file.  Below is a screen shot of the result of the command on a suicide EGTB of K_NBK: