Skip to content

Commit c491dc7

Browse files
authored
3.2.1: update fathom library to support Syzygy 7-man (#268)
BENCH: 3925018
1 parent bf9cda6 commit c491dc7

File tree

13 files changed

+4199
-1987
lines changed

13 files changed

+4199
-1987
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
99
FILE(GLOB SRCFILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
1010
FILE(GLOB HDRFILES ${PROJECT_SOURCE_DIR}/src/*.h)
1111

12-
FILE(GLOB FATHOM_SRCFILES ${PROJECT_SOURCE_DIR}/src/fathom/*.c)
12+
FILE(GLOB FATHOM_SRCFILES ${PROJECT_SOURCE_DIR}/src/fathom/*.cpp)
1313
FILE(GLOB FATHOM_HDRFILES ${PROJECT_SOURCE_DIR}/src/fathom/*.h)
1414

1515
IF (DEFINED EVAL_NNUE)

appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 1.0.{build}
22
clone_depth: 5
33

4-
os: Visual Studio 2017
4+
os: Visual Studio 2022
55

66
platform:
77
- x64
@@ -26,8 +26,8 @@ before_build:
2626
- git submodule update --init --recursive
2727

2828
build_script:
29-
- cmake -D_BTYPE=1 -G "Visual Studio 15 2017 Win64" .
29+
- cmake -D_BTYPE=1 -G "Visual Studio 17 2022" .
3030
- cmake --build . --target ALL_BUILD --config %CONFIGURATION%
31-
- cmake -D_MAKE_UNIT_TEST=UNIT_TEST -D_BTYPE=1 -G "Visual Studio 15 2017 Win64" .
31+
- cmake -D_MAKE_UNIT_TEST=UNIT_TEST -D_BTYPE=1 -G "Visual Studio 17 2022" .
3232
- cmake --build . --target ALL_BUILD --config %CONFIGURATION%
3333
- .\%CONFIGURATION%\unit.exe

src/fathom/LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
The MIT License (MIT)
22

3+
Copyright (c) 2013-2018 Ronald de Man
34
Copyright (c) 2015 basil00
4-
Modifications Copyright (c) 2016-2018 by Jon Dart
5+
Copyright (c) 2016-2020 by Jon Dart
56

67
Permission is hereby granted, free of charge, to any person obtaining a copy
78
of this software and associated documentation files (the "Software"), to deal

src/fathom/README.md

Lines changed: 95 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ are:
99
* To make it easy to create stand-alone applications that use the Syzygy
1010
tablebases;
1111

12+
Fathom is compilable under either C99 or C++ and supports a variety of
13+
platforms, including at least Windows, Linux, and MacOS.
14+
1215
Tool
1316
----
1417

@@ -26,64 +29,117 @@ The tool will print out a PGN representation of the probe result, including:
2629
* WinningMoves: The list of all winning moves
2730
* DrawingMoves: The list of all drawing moves
2831
* LosingMoves: The list of all losing moves
29-
* A pseudo "principle variation" of Syzygy vs. Syzygy for the input position.
32+
* A pseudo "principal variation" of Syzygy vs. Syzygy for the input position.
3033

3134
For more information, run the following command:
3235

3336
fathom --help
3437

35-
Pre-compiled versions of `fathom` (for all platforms) are available from here:
36-
37-
* https://github.com/basil00/Fathom/releases
38-
3938
Programming API
4039
---------------
4140

42-
Fathom provides a simple API. There are three main function calls:
41+
Fathom provides a simple API. Following are the main function calls:
4342

44-
* `tb_init` initializes the tablebase
45-
* `tb_probe_wdl` probes the Win-Draw-Loss (WDL) table for a given position
43+
* `tb_init` initializes the tablebases.
44+
* `tb_free` releases any resources allocated by Fathom.
45+
* `tb_probe_wdl` probes the Win-Draw-Loss (WDL) table for a given position.
4646
* `tb_probe_root` probes the Distance-To-Zero (DTZ) table for the given
47-
position.
48-
49-
All of the API functions use basic integer types, i.e. there is no need to
50-
create and initialize data-structures. Fathom does not require the callee
51-
to provide any additional functionality (e.g. move generation) unlike the
52-
traditional `tbprobe` code. However, chess engines can opt to replace some
53-
of the functionality of Fathom for better performance (see below).
54-
55-
Chess Engines
47+
position. It returns a recommended move, and also a list of unsigned
48+
integers, each one encoding a possible move and its DTZ and WDL values.
49+
* `tb_probe_root_dtz` probes the Distance-To-Zero (DTZ) at the root position.
50+
It returns a score and a rank for each possible move.
51+
* `tb_probe_root_wdl` probes the Win-Draw-Loss (WDL) at the root position.
52+
it returns a score and a rank for each possible move.
53+
54+
Fathom does not require the callee to provide any additional functionality
55+
(e.g. move generation). A simple set of chess-related functions including move
56+
generation is provided in file `tbchess.c`. However, chess engines can opt to
57+
replace some of this functionality for better performance (see below).
58+
59+
Chess engines
5660
-------------
5761

58-
Chess engines can be `tb_probe_wdl` to get the WDL value during search. The
59-
`tb_probe_root` functional can be used to help pick the best move at the root.
60-
Note that `tb_probe_root` is slower and therefore should only be used at the
61-
root.
62-
63-
Chess engines can opt for a tighter integration of Fathom by configuring
64-
`tbconfig.h`. Specifically, the chess engines can define `TB_*_ATTACKS`
65-
macros that replace the default definitions with the engine's own definitions,
66-
avoiding duplication of functionality.
67-
68-
Credits
69-
-------
70-
71-
The Syzygy tablebases were created by Ronald de Man. Much of the probing code
72-
`tbprobe.c` is a modified version of Ronald's `tbprobe.cpp` for Stockfish (all
73-
Stockfish-specific code has been removed). The `tbcore.c` file is virtually
74-
unchanged from Ronald's original version.
62+
Chess engines can use `tb_probe_wdl` to get the WDL value during
63+
search. This function is thread safe (unless TB_NO_THREADS is
64+
set). The various "probe_root" functions are intended for probing only
65+
at the root node and are not thread-safe.
66+
67+
Chess engines and other clients can modify some features of Fathom and
68+
override some of its internal functions by configuring
69+
`tbconfig.h`. `tbconfig.h` is included in Fathom's code with angle
70+
brackets. This allows a client of Fathom to override tbconfig.h by
71+
placing its own modified copy in its include path before the Fathom
72+
source directory.
73+
74+
One option provided by `tbconfig.h` is to define macros that replace
75+
some aspects of Fathom's functionality, such as calculating piece
76+
attacks, avoiding duplication of functionality. If doing this,
77+
however, be careful with including typedefs or defines from your own
78+
code into `tbconfig.h`, since these may clash with internal definitions
79+
used by Fathom. I recommend instead interfacing to external
80+
functions via a small module, with an interface something like this:
81+
82+
```
83+
#ifndef _TB_ATTACK_INTERFACE
84+
#define _TB_ATTACK_INTERFACE
85+
86+
#ifdef __cplusplus
87+
#include <cstdint>
88+
#else
89+
#include <stdint.h>
90+
#endif
91+
92+
extern tb_knight_attacks(unsigned square);
93+
extern tb_king_attacks(unsigned square);
94+
extern tb_root_attacks(unsigned square, uint64_t occ);
95+
extern tb_bishop_attacks(unsigned square, uint64_t occ);
96+
extern tb_queen_attacks(unsigned square, uint64_t occ);
97+
extern tb_pawn_attacks(unsigned square, uint64_t occ);
98+
99+
#endif
100+
```
101+
102+
You can add if wanted other function definitions such as a popcnt
103+
function based on the chess engine's native popcnt support.
104+
105+
`tbconfig.h` can then reference these functions safety because the
106+
interface depends only on types defined in standard headers. The
107+
implementation, however, can use any types from the chess engine or
108+
other client that are necessary. (A good optimizer with link-time
109+
optimization will inline the implementation code even though it is not
110+
visible in the interface).
111+
112+
History and Credits
113+
-------------------
114+
115+
The Syzygy tablebases were created by Ronald de Man. The original version of Fathom
116+
(https://github.com/basil00/Fathom) combined probing code from Ronald de Man, originally written for
117+
Stockfish, with chess-related functions and other support code from Basil Falcinelli.
118+
That codebase is no longer being maintained. This repository was originaly a fork of
119+
that codebase, with additional modifications by Jon Dart.
120+
121+
However, the current Fathom code in this repository is no longer
122+
derived directly from the probing code written for Stockfish, but
123+
instead derives from tbprobe.c, which is a component of the Cfish
124+
chess engine (https://github.com/syzygy1/Cfish), a Stockfish
125+
derivative. tbprobe.c includes 7-man tablebase support. It was written
126+
by Ronald de Man and released for unrestricted distribution and use.
127+
128+
This fork of Fathom replaces the Cfish board representation and move
129+
generation code used in tbprobe.c with simpler, MIT-licensed code from the original
130+
Fathom source by Basil. The code has been reorganized so that
131+
`tbchess.c` contains all move generation and most chess-related typedefs
132+
and functions, while `tbprobe.c` contains all the tablebase probing
133+
code. The code replacement and reorganization was done by Jon Dart.
75134

76135
License
77136
-------
78137

79138
(C) 2013-2015 Ronald de Man (original code)
80139
(C) 2015 basil (new modifications)
81-
(C) 2016-2018 Jon Dart (additional modifications)
82-
83-
Ronald de Man's original code can be "redistributed and/or modified without
84-
restrictions".
140+
(C) 2016-2020 Jon Dart (additional modifications)
85141

86-
The new modifications are released under the permissive MIT License:
142+
This version of Fathom is released under the MIT License:
87143

88144
Permission is hereby granted, free of charge, to any person obtaining a copy of
89145
this software and associated documentation files (the "Software"), to deal in

0 commit comments

Comments
 (0)