1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 09:13:08 +00:00

Fix issue and rewrite search() flags

This commit is contained in:
Marco Costalba 2016-05-21 21:09:37 +02:00
parent 3731213994
commit db8112ec9e
2 changed files with 21 additions and 23 deletions

View file

@ -1210,20 +1210,23 @@ int probe_dtz_table(const Position& pos, WDLScore wdl, ProbeState* result)
// All of this means that during probing, the engine must look at captures and probe // All of this means that during probing, the engine must look at captures and probe
// their results and must probe the position itself. The "best" result of these // their results and must probe the position itself. The "best" result of these
// probes is the correct result for the position. // probes is the correct result for the position.
template<bool CheckPawnMoves = false> // DTZ table don't store values when a following move is a zeroing winning move
// (winning capture or winning pawn move). Also DTZ store wrong values for positions
// where the best move is an ep-move (even if losing). So in all these cases set
// the state to ZEROING_MOVE.
template<bool CheckZeroingMoves = false>
WDLScore search(Position& pos, WDLScore alpha, WDLScore beta, ProbeState* result) WDLScore search(Position& pos, WDLScore alpha, WDLScore beta, ProbeState* result)
{ {
WDLScore value, epValue = WDLScoreNone; WDLScore value, epValue = WDLScoreNone;
StateInfo st; StateInfo st;
CheckInfo ci(pos); CheckInfo ci(pos);
Move bestMove = MOVE_NONE;
auto moveList = MoveList<LEGAL>(pos); auto moveList = MoveList<LEGAL>(pos);
size_t moveCount = moveList.size(); size_t moveCount = moveList.size();
for (const Move& move : moveList) for (const Move& move : moveList)
{ {
if ( !pos.capture(move) if ( !pos.capture(move)
&& (!CheckPawnMoves || type_of(pos.moved_piece(move)) != PAWN)) && (!CheckZeroingMoves || type_of(pos.moved_piece(move)) != PAWN))
continue; continue;
pos.do_move(move, st, pos.gives_check(move, ci)); pos.do_move(move, st, pos.gives_check(move, ci));
@ -1242,15 +1245,12 @@ WDLScore search(Position& pos, WDLScore alpha, WDLScore beta, ProbeState* result
if (value >= beta) if (value >= beta)
{ {
*result = (!CheckPawnMoves || pos.capture(move)) ? WIN_CAPTURE : WIN_PAWN_MOVE; *result = ZEROING_MOVE; // Winning DTZ-zeroing move
return value; return value;
} }
if (value > alpha) if (value > alpha)
{
alpha = value; alpha = value;
bestMove = move;
}
} }
value = probe_wdl_table(pos, result); value = probe_wdl_table(pos, result);
@ -1267,13 +1267,9 @@ WDLScore search(Position& pos, WDLScore alpha, WDLScore beta, ProbeState* result
// Here alpha stores the best value out of the previous search // Here alpha stores the best value out of the previous search
if (value > alpha) if (value > alpha)
return *result = (value == epValue && value > WDLDraw ? WIN_CAPTURE : OK), value; return *result = (value == epValue ? ZEROING_MOVE : OK), value;
if (bestMove && alpha > WDLDraw)
*result = (!CheckPawnMoves || pos.capture(bestMove)) ? WIN_CAPTURE : WIN_PAWN_MOVE;
else
*result = OK;
*result = alpha > WDLDraw ? ZEROING_MOVE : OK;
return alpha; return alpha;
} }
@ -1461,9 +1457,13 @@ int Tablebases::probe_dtz(Position& pos, ProbeState* result)
if (wdl == WDLDraw) // DTZ tables don't store draws if (wdl == WDLDraw) // DTZ tables don't store draws
return 0; return 0;
if ( *result == WIN_CAPTURE // DTZ tables store a 'don't care' value in this case // DTZ table stores a 'don't care' value in this case, or even a plain wrong
|| *result == WIN_PAWN_MOVE) // one as in case the best move is a losing ep, so it cannot be probed.
return wdl == WDLWin ? 1 : 101; // DTZ scores for immediate win or cursed win if (*result == ZEROING_MOVE)
return wdl == WDLWin ? 1 :
wdl == WDLCursedWin ? 101 :
wdl == WDLCursedLoss ? -101 :
wdl == WDLLoss ? -1 : 0;
int dtz = probe_dtz_table(pos, wdl, result); // Probe the table! int dtz = probe_dtz_table(pos, wdl, result); // Probe the table!

View file

@ -38,11 +38,10 @@ enum WDLScore {
// Possible states after a probing operation // Possible states after a probing operation
enum ProbeState { enum ProbeState {
FAIL = 0, // Probe failed (missing file table) FAIL = 0, // Probe failed (missing file table)
OK = 1, // Probe succesful OK = 1, // Probe succesful
CHANGE_STM = -1, // WDL probe succesful but DTZ should check the other side CHANGE_STM = -1, // DTZ should check the other side
WIN_CAPTURE = 2, // WDL probe succesful but position's DTZ value is invalid ZEROING_MOVE = 2 // Best move zeroes DTZ (capture or pawn move)
WIN_PAWN_MOVE = 3 // WDL probe succesful but position's DTZ value is invalid
}; };
extern size_t MaxCardinality; extern size_t MaxCardinality;
@ -69,8 +68,7 @@ inline std::ostream& operator<<(std::ostream& os, const ProbeState v) {
os << (v == FAIL ? "Failed" : os << (v == FAIL ? "Failed" :
v == OK ? "Success" : v == OK ? "Success" :
v == CHANGE_STM ? "Probed opponent side" : v == CHANGE_STM ? "Probed opponent side" :
v == WIN_CAPTURE ? "Found a winning capture" : v == ZEROING_MOVE ? "Missing DTZ value" : "None");
v == WIN_PAWN_MOVE ? "Found a winning pawn move" : "None");
return os; return os;
} }