X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=647f2bba69153dc2c71a1762f29506636c2ed239;hp=c09a953b62e3a7612d53f03069266a2a00493d6d;hb=c0bb0415394179e9c771cc96a9da6724fc14c167;hpb=369eff437cc081eb4b8ab5f519cf3f86b79e87d0 diff --git a/src/position.cpp b/src/position.cpp index c09a953b..647f2bba 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -32,6 +32,7 @@ #include "thread.h" #include "tt.h" #include "uci.h" +#include "syzygy/tbprobe.h" using std::string; @@ -85,7 +86,7 @@ PieceType min_attacker(const Bitboard*, Square, Bitboard, Bitboard&, Bitbo /// operator<<(Position) returns an ASCII representation of the position -std::ostream& operator<<(std::ostream& os, const Position& pos) { +std::ostream& operator<<(std::ostream& os, Position& pos) { os << "\n +---+---+---+---+---+---+---+---+\n"; @@ -98,11 +99,22 @@ std::ostream& operator<<(std::ostream& os, const Position& pos) { } os << "\nFen: " << pos.fen() << "\nKey: " << std::hex << std::uppercase - << std::setfill('0') << std::setw(16) << pos.key() << std::dec << "\nCheckers: "; + << std::setfill('0') << std::setw(16) << pos.key() + << std::setfill(' ') << std::dec << "\nCheckers: "; for (Bitboard b = pos.checkers(); b; ) os << UCI::square(pop_lsb(&b)) << " "; + if ( int(Tablebases::MaxCardinality) >= popcount(pos.pieces()) + && !pos.can_castle(ANY_CASTLING)) + { + Tablebases::ProbeState s1, s2; + Tablebases::WDLScore wdl = Tablebases::probe_wdl(pos, &s1); + int dtz = Tablebases::probe_dtz(pos, &s2); + os << "\nTablebases WDL: " << std::setw(4) << wdl << " (" << s1 << ")" + << "\nTablebases DTZ: " << std::setw(4) << dtz << " (" << s2 << ")"; + } + return os; } @@ -357,6 +369,28 @@ void Position::set_state(StateInfo* si) const { } +/// Position::set() is an overload to initialize the position object with +/// the given endgame code string like "KBPKN". It is manily an helper to +/// get the material key out of an endgame code. Position is not playable, +/// indeed is even not guaranteed to be legal. + +Position& Position::set(const string& code, Color c, StateInfo* si) { + + assert(code.length() > 0 && code.length() < 8); + assert(code[0] == 'K'); + + string sides[] = { code.substr(code.find('K', 1)), // Weak + code.substr(0, code.find('K', 1)) }; // Strong + + std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower); + + string fenStr = sides[0] + char(8 - sides[0].length() + '0') + "/8/8/8/8/8/8/" + + sides[1] + char(8 - sides[1].length() + '0') + " w - - 0 10"; + + return set(fenStr, false, si, nullptr); +} + + /// Position::fen() returns a FEN representation of the position. In case of /// Chess960 the Shredder-FEN notation is used. This is mainly a debugging function.