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 {};
}