Fathom Probing Crashing

Discussion of chess software programming and technical issues.

Moderator: Ras

Joeger-Bahar
Posts: 5
Joined: Thu Sep 18, 2025 3:55 am
Full name: Joshua Bahr

Fathom Probing Crashing

Post by Joeger-Bahar »

My code that returns WDL at a position. tb_probe_root works fine and returns the expected values. However, tb_probe_wdl crashes because b == 0 in a PopLSB intrinsic function. I've tried not flipping the bitboards, flipping them horizontally, only flipping them for the probe_root, and it still crashes.

Code: Select all

bool Tablebase::ProbeLeaf(Engine* engine, Color color, int& scoreOut) const
{
    const BitboardBoard& board = engine->GetBitboardBoard();
    if (!Probeable(board))
        return false;

    // Flip vertically so LSB is a8 (seems to be the expected format)
    uint64_t white = flipVertical(board.allPieces[0]);
    uint64_t black = flipVertical(board.allPieces[1]);
    uint64_t kings = flipVertical(board.pieceBitboards[0][static_cast<int>(Pieces::KING) - 1] | board.pieceBitboards[1][static_cast<int>(Pieces::KING) - 1]);
    uint64_t queens = flipVertical(board.pieceBitboards[0][static_cast<int>(Pieces::QUEEN) - 1] | board.pieceBitboards[1][static_cast<int>(Pieces::QUEEN) - 1]);
    uint64_t rooks = flipVertical(board.pieceBitboards[0][static_cast<int>(Pieces::ROOK) - 1] | board.pieceBitboards[1][static_cast<int>(Pieces::ROOK) - 1]);
    uint64_t bishops = flipVertical(board.pieceBitboards[0][static_cast<int>(Pieces::BISHOP) - 1] | board.pieceBitboards[1][static_cast<int>(Pieces::BISHOP) - 1]);
    uint64_t knights = flipVertical(board.pieceBitboards[0][static_cast<int>(Pieces::KNIGHT) - 1] | board.pieceBitboards[1][static_cast<int>(Pieces::KNIGHT) - 1]);
    uint64_t pawns = flipVertical(board.pieceBitboards[0][static_cast<int>(Pieces::PAWN) - 1] | board.pieceBitboards[1][static_cast<int>(Pieces::PAWN) - 1]);

    unsigned rule50 = GameState::halfmoves;
    unsigned castling = 0;
    unsigned ep = (GameState::enPassantTarget == -1) ? 0 : GameState::enPassantTarget;
    bool turn = (color == Color::WHITE);

    unsigned wdl = tb_probe_wdl(
        white, black, kings, queens, rooks, bishops,
        knights, pawns, 0, castling, ep, turn);

    if (wdl == TB_RESULT_FAILED)
    {
        std::cout << "Failed\n";
        return false;
    }

    int dtz = 0;
    unsigned result = tb_probe_root(
        white, black, kings, queens, rooks, bishops,
        knights, pawns, rule50, castling, ep, turn, nullptr);
    if (result != TB_RESULT_FAILED)
        dtz = TB_GET_DTZ(result);

    switch (wdl)
    {
    case TB_WIN:
    case TB_CURSED_WIN:
        scoreOut = MATE_VAL - dtz;
        return true;
    case TB_DRAW:
        scoreOut = 0;
        return true;
    case TB_LOSS:
    case TB_BLESSED_LOSS:
        scoreOut = -(MATE_VAL - dtz);
        return true;
    default:
        return false;
    }
}
jdart
Posts: 4413
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Fathom Probing Crashing

Post by jdart »

I will take a look. Can you supply a debug stack trace from the crash?
jdart
Posts: 4413
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Fathom Probing Crashing

Post by jdart »

I am not sure why Fathom would be crashing.

However, it should not be necessary to modify the board representation when passing it to Fathom, unless you have some unusual layout. Almost all engines have a board layout with square A1 being 0, and square H8 being 63. If this is the case, you should be able to pass your bitboards directly to Fathom. See for example method probe_wdl in this file: https://github.com/jdart1/arasan-chess/ ... syzygy.cpp.