syzygy / fathom

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
flok
Posts: 142
Joined: Tue Jul 03, 2018 8:19 am
Full name: Folkert van Heusden
Contact:

syzygy / fathom

Post by flok » Thu Jul 04, 2019 5:35 am

What could be wrong if fathom/syzygy only returns 0-results? e.g. with TB_GET_WDL only returning 0? It has the 6-men table-base.

I tried 4k3/8/8/8/8/8/1B6/1B2K3 w - - 0 1 and also 4k3/8/8/8/8/8/1B6/1B2K3 b - - 0 1

Code: Select all

struct pos
{
        uint64_t white;
        uint64_t black;
        uint64_t kings;
        uint64_t queens;
        uint64_t rooks;
        uint64_t bishops;
        uint64_t knights;
        uint64_t pawns;
        uint8_t castling;
        uint8_t rule50;
        uint8_t ep;
        bool turn;
};

std::optional<libchess::Move> get_first_move(struct pos & pos, unsigned *results, unsigned wdl)
{
        for(unsigned i = 0; results[i] != TB_RESULT_FAILED; i++) {
                printf("hier %u %u=%u\n", i, TB_GET_WDL(results[i]), wdl);
                if (TB_GET_WDL(results[i]) == wdl) {
                        unsigned move     = results[i];

                        unsigned from     = TB_GET_FROM(move);
                        unsigned to       = TB_GET_TO(move);
                        unsigned promotes = TB_GET_PROMOTES(move);

                        char to_type = 0x00;

                        switch (promotes)
                        {
                                case TB_PROMOTES_QUEEN:
                                        to_type = 'q'; break;
                                case TB_PROMOTES_ROOK:
                                        to_type = 'r'; break;
                                case TB_PROMOTES_BISHOP:
                                        to_type = 'b'; break;
                                case TB_PROMOTES_KNIGHT:
                                        to_type = 'n'; break;
                        }

                        std::string move_str = myformat("%c%c%c%c%c", from & 7, from >> 3, to & 7, to >> 3, to_type);

                        printf("found %s\n", move_str.c_str());

                        return libchess::Move::from(move_str);
                }
        }

        return {};
}


std::optional<libchess::Move> probe_fathom(libchess::Position & lpos)
{
        struct pos pos;
        pos.turn == lpos.side_to_move() == libchess::constants::WHITE;
        pos.white = lpos.color_bb(libchess::constants::WHITE);
        pos.black = lpos.color_bb(libchess::constants::BLACK);
        pos.kings = lpos.piece_type_bb(libchess::constants::KING);
        pos.queens = lpos.piece_type_bb(libchess::constants::QUEEN);
        pos.rooks = lpos.piece_type_bb(libchess::constants::ROOK);
        pos.bishops = lpos.piece_type_bb(libchess::constants::BISHOP);
        pos.knights = lpos.piece_type_bb(libchess::constants::KNIGHT);
        pos.pawns = lpos.piece_type_bb(libchess::constants::PAWN);
        //uint8_t castling;
        pos.castling = 0; // FIXME
        pos.rule50 = lpos.fullmoves();
        std::optional<libchess::Square> ep = lpos.enpassant_square();
        pos.ep = ep.has_value() ? ep.value() : 0;

        unsigned results[TB_MAX_MOVES];
        unsigned res = tb_probe_root(pos.white, pos.black, pos.kings, pos.queens, pos.rooks, pos.bishops, pos.knights, pos.pawns, pos.rule50, pos.castling, pos.ep, pos.turn, results);

        if (res == TB_RESULT_FAILED) {
                printf("# TB_RESULT_FAILED\n");
                return {};
        }

        //printf("# %d\n", TB_GET_WDL(res));

        std::optional<libchess::Move> m;

        m = get_first_move(pos, results, TB_WIN);
        if (m.has_value())
                return m;

        m = get_first_move(pos, results, TB_CURSED_WIN);
        if (m.has_value())
                return m;

        m = get_first_move(pos, results, TB_DRAW);
        if (m.has_value())
                return m;

        m = get_first_move(pos, results, TB_BLESSED_LOSS);
        if (m.has_value())
                return m;

        return {};
}
www.vanheusden.com: Micah / Embla / PuppetMaster / DeepBrutePos / Pos / Feeks

flok
Posts: 142
Joined: Tue Jul 03, 2018 8:19 am
Full name: Folkert van Heusden
Contact:

Re: syzygy / fathom

Post by flok » Thu Jul 04, 2019 7:03 am

Please ignore this bug, I fixed that already :-)
flok wrote:
Thu Jul 04, 2019 5:35 am

Code: Select all

        pos.turn == lpos.side_to_move() == libchess::constants::WHITE;
The only wdl==0 problem disappeared, now every query returns TB_RESULT_FAILED
www.vanheusden.com: Micah / Embla / PuppetMaster / DeepBrutePos / Pos / Feeks

flok
Posts: 142
Joined: Tue Jul 03, 2018 8:19 am
Full name: Folkert van Heusden
Contact:

Re: syzygy / fathom

Post by flok » Thu Jul 04, 2019 12:40 pm

flok wrote:
Thu Jul 04, 2019 7:03 am
Ok I verified that at least the white and the bishop bitboard are the same (when comparing the fathom commandline tool and what micah produces).
So I'm still puzzled why it doesn't work!
www.vanheusden.com: Micah / Embla / PuppetMaster / DeepBrutePos / Pos / Feeks

flok
Posts: 142
Joined: Tue Jul 03, 2018 8:19 am
Full name: Folkert van Heusden
Contact:

Re: syzygy / fathom

Post by flok » Thu Jul 04, 2019 3:30 pm

flok wrote:
Thu Jul 04, 2019 12:40 pm
flok wrote:
Thu Jul 04, 2019 7:03 am
Ok I verified that at least the white and the bishop bitboard are the same (when comparing the fathom commandline tool and what micah produces).
So I'm still puzzled why it doesn't work!
In fact: all bitboards and other values (ep, castling, etc) are the same. So that's not the problem.
www.vanheusden.com: Micah / Embla / PuppetMaster / DeepBrutePos / Pos / Feeks

flok
Posts: 142
Joined: Tue Jul 03, 2018 8:19 am
Full name: Folkert van Heusden
Contact:

Re: syzygy / fathom

Post by flok » Thu Jul 04, 2019 4:37 pm

flok wrote:
Thu Jul 04, 2019 5:35 am

Code: Select all

                        char to_type = 0x00;
...
                        std::string move_str = myformat("%c%c%c%c%c", from & 7, from >> 3, to & 7, to >> 3, to_type);
This is a problem.
www.vanheusden.com: Micah / Embla / PuppetMaster / DeepBrutePos / Pos / Feeks

jdart
Posts: 3750
Joined: Fri Mar 10, 2006 4:23 am
Location: http://www.arasanchess.org

Re: syzygy / fathom

Post by jdart » Fri Jul 05, 2019 12:16 am

Which Fathom are you using? Is it https://github.com/jdart1/Fathom?

If the command-line tool works on your position, then you have to be passing something different into the API for it to not work for you. You do have to call tb_init first.

Btw. the newer and now preferred root level probing API call is tb_probe_root_dtz, or as a fallback, tb_probe_root_wdl.

--Jon

flok
Posts: 142
Joined: Tue Jul 03, 2018 8:19 am
Full name: Folkert van Heusden
Contact:

Re: syzygy / fathom

Post by flok » Fri Jul 05, 2019 6:51 pm

jdart wrote:
Fri Jul 05, 2019 12:16 am
Which Fathom are you using? Is it https://github.com/jdart1/Fathom?

If the command-line tool works on your position, then you have to be passing something different into the API for it to not work for you. You do have to call tb_init first.

Btw. the newer and now preferred root level probing API call is tb_probe_root_dtz, or as a fallback, tb_probe_root_wdl.

--Jon
Got it to work! :D

Thanks

Next step: not only at the root but in tree check as well.
www.vanheusden.com: Micah / Embla / PuppetMaster / DeepBrutePos / Pos / Feeks

Post Reply