Skip to content

Commit

Permalink
Merge remote-tracking branch 'fairy/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfab committed Aug 20, 2023
2 parents 08d0cd6 + 42b1d85 commit ee109fb
Show file tree
Hide file tree
Showing 39 changed files with 1,376 additions and 337 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:
- name: make largeboards
run: cd src && make clean && make -j build COMP=mingw ARCH=${{ matrix.arch }} EXE=bookgen-largeboards_${{ matrix.arch }}.exe largeboards=yes && strip bookgen-largeboards_${{ matrix.arch }}.exe

- name: make all
if: ${{ matrix.arch == 'x86-64' }}
run: cd src && make clean && make -j build COMP=mingw ARCH=${{ matrix.arch }} EXE=fairy-stockfish-all_${{ matrix.arch }}.exe largeboards=yes all=yes && strip fairy-stockfish-all_${{ matrix.arch }}.exe

- uses: actions/upload-artifact@v3
with:
name: bookgen
Expand All @@ -48,6 +52,10 @@ jobs:
- name: make largeboards
run: cd src && make clean && make -j build COMP=gcc ARCH=${{ matrix.arch }} EXE=bookgen-largeboards_${{ matrix.arch }} largeboards=yes && strip bookgen-largeboards_${{ matrix.arch }}

- name: make all
if: ${{ matrix.arch == 'x86-64' }}
run: cd src && make clean && make -j build COMP=gcc ARCH=${{ matrix.arch }} EXE=fairy-stockfish-all_${{ matrix.arch }} largeboards=yes all=yes && strip fairy-stockfish-all_${{ matrix.arch }}

- uses: actions/upload-artifact@v3
with:
name: bookgen
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/stockfish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
matrix:
config:
- {
name: "Ubuntu 20.04 GCC",
os: ubuntu-20.04,
name: "Ubuntu 22.04 GCC",
os: ubuntu-22.04,
compiler: g++,
comp: gcc,
run_expensive_tests: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macos-10.15]
os: [ubuntu-20.04, windows-2019, macos-11]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ cloudfish
CouchTomato87
Fulmene
gbtami
gnunicode
johndoknjas
kz04px
majormink
mtaktikos
QueensGambit
RainRat
rkb97
romstad
Snowmoondaphne
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# bookgen
EPD opening book generator based on [Fairy-Stockfish](https://github.com/ianfab/Fairy-Stockfish).
EPD opening book generator based on [Fairy-Stockfish](https://github.com/fairy-stockfish/Fairy-Stockfish).

Bookgen extends Fairy-Stockfish by the possibility of automatically generating opening books for all supported chess variants, including Chess, Xiangqi, Shogi, Crazyhouse, Antichess, Atomic, etc.

Several methods for generation and filtering of positions in FEN format are supported to adapt the book to specific requirements. The generation can be based on perft and multipv searches. The filtering supports a variety of options to define the criteria for evaluation of positions to be included. The output format is EPD. See the [Wiki](https://github.com/ianfab/bookgen/wiki) for documentation and usage examples.
Several methods for generation and filtering of positions in FEN format are supported to adapt the book to specific requirements. The generation can be based on perft and multipv searches. The filtering supports a variety of options to define the criteria for evaluation of positions to be included. The output format is EPD. See the [Wiki](https://github.com/fairy-stockfish/bookgen/wiki) for documentation and usage examples.

Built binaries for Windows and Linux can be downloaded from the [releases](https://github.com/ianfab/bookgen/releases). Development versions can be downloaded from the [release workflow](https://github.com/ianfab/bookgen/actions/workflows/release.yml) (requires logging in to github).
Built binaries for Windows and Linux can be downloaded from the [releases](https://github.com/fairy-stockfish/bookgen/releases). Development versions can be downloaded from the [release workflow](https://github.com/fairy-stockfish/bookgen/actions/workflows/release.yml) (requires logging in to github).

Instead of downloading it, you can also use the [online book generator](https://bookgen-wasm.vercel.app) ([code](https://github.com/ianfab/bookgen-wasm)), which uses the [WebAssembly port](https://github.com/ianfab/fairy-stockfish.wasm/tree/bookgen).
Instead of downloading it, you can also use the [online book generator](https://bookgen-wasm.vercel.app) ([code](https://github.com/ianfab/bookgen-wasm)), which uses the [WebAssembly port](https://github.com/fairy-stockfish/fairy-stockfish.wasm/tree/bookgen).

There are separate (older) versions based on specialized variant forks, such as [official Stockfish](https://github.com/ianfab/bookgen/tree/official-stockfish), [multi-variant Stockfish](https://github.com/ianfab/bookgen/tree/multivariant), [Seirawan-Stockfish](https://github.com/ianfab/bookgen/tree/seirawan), [Shatranj-Stockfish](https://github.com/ianfab/bookgen/tree/shatranj), and [Makruk-Stockfish](https://github.com/ianfab/bookgen/tree/makruk) that can be found on the respective branches, but the Fairy-Stockfish based version supports all of these variants as well.
There are separate (older) versions based on specialized variant forks, such as [official Stockfish](https://github.com/fairy-stockfish/bookgen/tree/official-stockfish), [multi-variant Stockfish](https://github.com/fairy-stockfish/bookgen/tree/multivariant), [Seirawan-Stockfish](https://github.com/fairy-stockfish/bookgen/tree/seirawan), [Shatranj-Stockfish](https://github.com/fairy-stockfish/bookgen/tree/shatranj), and [Makruk-Stockfish](https://github.com/fairy-stockfish/bookgen/tree/makruk) that can be found on the respective branches, but the Fairy-Stockfish based version supports all of these variants as well.

Also see the [Fairy-Stockfish](https://github.com/ianfab/Fairy-Stockfish) repository for more info.
Also see the [Fairy-Stockfish](https://github.com/fairy-stockfish/Fairy-Stockfish) repository for more info.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ before_build:
'add_compile_definitions(NNUE_EMBEDDING_OFF)',
'add_executable(stockfish ${source_files})'
# Write CMakeLists.txt withouth BOM
# Write CMakeLists.txt without BOM
$MyPath = (Get-Item -Path "." -Verbose).FullName + '\CMakeLists.txt'
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines($MyPath, $t, $Utf8NoBomEncoding)
Expand Down
52 changes: 0 additions & 52 deletions appveyor_python.yml

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
sources=sources,
extra_compile_args=args)

setup(name="pyffish", version="0.0.77",
setup(name="pyffish", version="0.0.78",
description="Fairy-Stockfish Python wrapper",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile_js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ help:
@echo ""

objclean:
@rm -f $(EXE) *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o
@rm -f $(EXE)

clean: objclean

Expand Down
13 changes: 9 additions & 4 deletions src/apiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ inline bool has_insufficient_material(Color c, const Position& pos) {
if ( pos.captures_to_hand()
|| pos.count_in_hand(c, ALL_PIECES)
|| (pos.extinction_value() != VALUE_NONE && !pos.extinction_pseudo_royal())
|| (pos.capture_the_flag_piece() && pos.count(c, pos.capture_the_flag_piece())))
|| (pos.flag_region(c) && pos.count(c, pos.flag_piece(c))))
return false;

// Restricted pieces
Expand Down Expand Up @@ -404,12 +404,17 @@ inline bool has_insufficient_material(Color c, const Position& pos) {
if ((pos.pieces(c) & unbound) && (popcount(pos.pieces() ^ restricted) >= 2 || pos.stalemate_value() != VALUE_DRAW || pos.check_counting() || pos.makpong()))
return false;

// Non-draw stalemate with lone custom king
if ( pos.stalemate_value() != VALUE_DRAW && pos.king_type() != KING
&& pos.pieces(c, KING) && (pos.board_bb(c, KING) & pos.board_bb(~c, KING)))
return false;

return true;
}

inline bool is_check(const Position& pos) {
return pos.checkers()
|| (pos.extinction_pseudo_royal() && pos.attackers_to_pseudo_royals(~pos.side_to_move()));
inline Bitboard checked(const Position& pos) {
return (pos.checkers() ? square_bb(pos.square<KING>(pos.side_to_move())) : Bitboard(0))
| (pos.extinction_pseudo_royal() ? pos.checked_pseudo_royals(pos.side_to_move()) : Bitboard(0));
}

namespace FEN {
Expand Down
54 changes: 45 additions & 9 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,21 @@ namespace {
score += bonus - PassedFile * edge_distance(file_of(s), pos.max_file());
}

// Passed custom pawns
for (PieceSet ps = pos.variant()->promotionPawnTypes[Us] & ~piece_set(PAWN); ps;)
{
PieceType pt = pop_lsb(ps);
Bitboard b2 = pos.pieces(Us, pt);
while (b2)
{
Square s = pop_lsb(b2);
if (pos.promotion_square(Us, s) == SQ_NONE || (pos.pieces(Them, pt) & forward_file_bb(Us, s)))
continue;
int r = std::max(RANK_8 - std::max(relative_rank(Us, pos.promotion_square(Us, s), pos.max_rank()) - relative_rank(Us, s, pos.max_rank()), 0), 0);
score += PassedRank[r];
}
}

// Scale by maximum promotion piece value
Value maxMg = VALUE_ZERO, maxEg = VALUE_ZERO;
for (PieceSet ps = pos.promotion_piece_types(Us); ps;)
Expand Down Expand Up @@ -1148,8 +1163,8 @@ namespace {
int weight = pos.count<ALL_PIECES>(Us) - 3 + std::min(pe->blocked_count(), 9);
Score score = make_score(bonus * weight * weight / 16, 0);

if (pos.capture_the_flag(Us))
score += make_score(200, 200) * popcount(behind & safe & pos.capture_the_flag(Us));
if (pos.flag_region(Us))
score += make_score(200, 200) * popcount(behind & safe & pos.flag_region(Us));

if constexpr (T)
Trace::add(SPACE, Us, score);
Expand All @@ -1169,11 +1184,10 @@ namespace {
Score score = SCORE_ZERO;

// Capture the flag
if (pos.capture_the_flag(Us))
if (pos.flag_region(Us))
{
PieceType ptCtf = pos.capture_the_flag_piece();
Bitboard ctfPieces = pos.pieces(Us, ptCtf);
Bitboard ctfTargets = pos.capture_the_flag(Us) & pos.board_bb();
Bitboard ctfPieces = pos.pieces(Us, pos.flag_piece(Us));
Bitboard ctfTargets = pos.flag_region(Us) & pos.board_bb();
Bitboard onHold = 0;
Bitboard onHold2 = 0;
Bitboard processed = 0;
Expand All @@ -1186,6 +1200,8 @@ namespace {
// Traverse all paths of the CTF pieces to the CTF targets.
// Put squares that are attacked or occupied on hold for one iteration.
// This reflects that likely a move will be needed to block or capture the attack.
// If all piece types are eligible, use the king path as a proxy for distance.
PieceType ptCtf = pos.flag_piece(Us) == ALL_PIECES ? KING : pos.flag_piece(Us);
for (int dist = 0; (ctfPieces || onHold || onHold2) && (ctfTargets & ~processed); dist++)
{
int wins = popcount(ctfTargets & ctfPieces);
Expand Down Expand Up @@ -1264,7 +1280,22 @@ namespace {
// Connect-n
if (pos.connect_n() > 0)
{
for (Direction d : {NORTH, NORTH_EAST, EAST, SOUTH_EAST})
std::vector<Direction> connect_directions;

if (pos.connect_horizontal())
{
connect_directions.push_back(EAST);
}
if (pos.connect_vertical())
{
connect_directions.push_back(NORTH);
}
if (pos.connect_diagonal())
{
connect_directions.push_back(NORTH_EAST);
connect_directions.push_back(SOUTH_EAST);
}
for (Direction d : connect_directions)
{
// Find sufficiently large gaps
Bitboard b = pos.board_bb() & ~pos.pieces(Them);
Expand Down Expand Up @@ -1333,10 +1364,15 @@ namespace {
template<Tracing T>
Value Evaluation<T>::winnable(Score score) const {

// No initiative bonus for extinction variants
// No initiative bonus for variants that do not require sufficient mating material, e.g., extinction variants.
// This protects them from misidentification as drawish.
int complexity = 0;
bool pawnsOnBothFlanks = true;
if (pos.extinction_value() == VALUE_NONE && !pos.captures_to_hand() && !pos.connect_n() && !pos.material_counting())
if ( pos.extinction_value() == VALUE_NONE
&& !pos.captures_to_hand()
&& !pos.connect_n()
&& !pos.material_counting()
&& !(pos.flag_region(WHITE) || pos.flag_region(BLACK)))
{
int outflanking = !pos.count<KING>(WHITE) || !pos.count<KING>(BLACK) ? 0
: distance<File>(pos.square<KING>(WHITE), pos.square<KING>(BLACK))
Expand Down
15 changes: 14 additions & 1 deletion src/ffishjs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,20 @@ class Board {
return "0-1";
}

std::string checked_pieces() const {
Bitboard checked = Stockfish::checked(pos);
std::string squares;
while (checked) {
Square sr = pop_lsb(checked);
squares += UCI::square(pos, sr);
squares += DELIM;
}
save_pop_back(squares);
return squares;
}

bool is_check() const {
return Stockfish::is_check(pos);
return Stockfish::checked(pos);
}

bool is_bikjang() const {
Expand Down Expand Up @@ -706,6 +718,7 @@ EMSCRIPTEN_BINDINGS(ffish_js) {
.function("isGameOver", select_overload<bool(bool) const>(&Board::is_game_over))
.function("result", select_overload<std::string() const>(&Board::result))
.function("result", select_overload<std::string(bool) const>(&Board::result))
.function("checkedPieces", &Board::checked_pieces)
.function("isCheck", &Board::is_check)
.function("isBikjang", &Board::is_bikjang)
.function("isCapture", &Board::is_capture)
Expand Down
5 changes: 3 additions & 2 deletions src/movegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ namespace {

Bitboard b = pawns & pawn_attacks_bb(Them, epSquare);

assert(b);
// En passant square is already disabled for non-fairy variants if there is no attacker
assert(b || !pos.variant()->fastAttacks);

while (b)
moveList = make_move_and_gating<EN_PASSANT>(pos, moveList, Us, pop_lsb(b), epSquare);
Expand Down Expand Up @@ -387,7 +388,7 @@ namespace {
target = pos.checkers();
}

// Remove inaccesible squares (outside board + wall squares)
// Remove inaccessible squares (outside board + wall squares)
target &= pos.board_bb();

moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
Expand Down
2 changes: 1 addition & 1 deletion src/nnue/features/half_ka_v2_variants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Stockfish::Eval::NNUE::Features {
// Orient a square according to perspective (rotates by 180 for black)
// Missing kings map to index 0 (SQ_A1)
inline Square HalfKAv2Variants::orient(Color perspective, Square s, const Position& pos) {
return s != SQ_NONE ? to_variant_square( perspective == WHITE || (pos.capture_the_flag(BLACK) & Rank8BB) ? s
return s != SQ_NONE ? to_variant_square( perspective == WHITE || (pos.flag_region(BLACK) & Rank8BB) ? s
: flip_rank(s, pos.max_rank()), pos) : SQ_A1;
}

Expand Down
6 changes: 3 additions & 3 deletions src/nnue/nnue_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace Stockfish::Eval::NNUE {

// write_little_endian() is our utility to write an integer (signed or unsigned, any size)
// to a stream in little-endian order. We swap the byte order before the write if
// necessary to always write in little endian order, independantly of the byte
// necessary to always write in little endian order, independently of the byte
// ordering of the compiling machine.
template <typename IntType>
inline void write_little_endian(std::ostream& stream, IntType value) {
Expand Down Expand Up @@ -137,7 +137,7 @@ namespace Stockfish::Eval::NNUE {
}
}

// read_little_endian(s, out, N) : read integers in bulk from a little indian stream.
// read_little_endian(s, out, N) : read integers in bulk from a little endian stream.
// This reads N integers from stream s and put them in array out.
template <typename IntType>
inline void read_little_endian(std::istream& stream, IntType* out, std::size_t count) {
Expand All @@ -148,7 +148,7 @@ namespace Stockfish::Eval::NNUE {
out[i] = read_little_endian<IntType>(stream);
}

// write_little_endian(s, values, N) : write integers in bulk to a little indian stream.
// write_little_endian(s, values, N) : write integers in bulk to a little endian stream.
// This takes N integers from array values and writes them on stream s.
template <typename IntType>
inline void write_little_endian(std::ostream& stream, const IntType* values, std::size_t count) {
Expand Down
Loading

0 comments on commit ee109fb

Please sign in to comment.