mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
More work in probe_dtz_no_ep()
This commit is contained in:
parent
bea98066a0
commit
47e21c274d
1 changed files with 42 additions and 54 deletions
|
@ -1282,8 +1282,6 @@ int probe_dtz(Position& pos, ProbeState* result);
|
||||||
// This routine treats a position with en passant captures as one without.
|
// This routine treats a position with en passant captures as one without.
|
||||||
int probe_dtz_no_ep(Position& pos, ProbeState* result)
|
int probe_dtz_no_ep(Position& pos, ProbeState* result)
|
||||||
{
|
{
|
||||||
int dtz;
|
|
||||||
|
|
||||||
WDLScore wdl = search<true>(pos, WDLLoss, WDLWin, result);
|
WDLScore wdl = search<true>(pos, WDLLoss, WDLWin, result);
|
||||||
|
|
||||||
if (*result == FAIL)
|
if (*result == FAIL)
|
||||||
|
@ -1296,7 +1294,7 @@ int probe_dtz_no_ep(Position& pos, ProbeState* result)
|
||||||
|| *result == WIN_PAWN_MOVE)
|
|| *result == WIN_PAWN_MOVE)
|
||||||
return wdl == WDLWin ? 1 : 101; // DTZ scores for immediate win or cursed win
|
return wdl == WDLWin ? 1 : 101; // DTZ scores for immediate win or cursed win
|
||||||
|
|
||||||
dtz = 1 + probe_dtz_table(pos, wdl, result); // Probe the table!
|
int dtz = 1 + probe_dtz_table(pos, wdl, result); // Probe the table!
|
||||||
|
|
||||||
if (*result != CHANGE_STM)
|
if (*result != CHANGE_STM)
|
||||||
{
|
{
|
||||||
|
@ -1306,71 +1304,61 @@ int probe_dtz_no_ep(Position& pos, ProbeState* result)
|
||||||
return wdl > WDLDraw ? dtz : -dtz;
|
return wdl > WDLDraw ? dtz : -dtz;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtMove stack[MAX_MOVES];
|
// DTZ stores results for the other STM, so we need to do a 1-ply search.
|
||||||
ExtMove *moves, *end = nullptr;
|
// Because of the structure of the dtz values, it is easier to distinguish
|
||||||
|
// between wdl > 0 and wdl < 0.
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
CheckInfo ci(pos);
|
CheckInfo ci(pos);
|
||||||
|
int minDTZ = 0xFFFF;
|
||||||
|
|
||||||
if (wdl > 0) {
|
if (wdl > 0)
|
||||||
int best = 0xffff;
|
{
|
||||||
|
// Find the winning move that minimizes DTZ. We don't need to probe for
|
||||||
for (moves = stack; moves < end; ++moves) {
|
// captures and pawn moves because we already know are losing.
|
||||||
Move move = moves->move;
|
for (const Move& move : MoveList<LEGAL>(pos))
|
||||||
|
{
|
||||||
if (pos.capture(move) || type_of(pos.moved_piece(move)) == PAWN
|
if (pos.capture(move) || type_of(pos.moved_piece(move)) == PAWN)
|
||||||
|| !pos.legal(move, ci.pinned))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pos.do_move(move, st, pos.gives_check(move, ci));
|
pos.do_move(move, st, pos.gives_check(move, ci));
|
||||||
int v = -probe_dtz(pos, result);
|
dtz = -probe_dtz(pos, result);
|
||||||
pos.undo_move(move);
|
pos.undo_move(move);
|
||||||
|
|
||||||
if (*result == FAIL)
|
if (*result == FAIL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (v > 0 && v + 1 < best)
|
if (dtz > 0 && dtz + 1 < minDTZ)
|
||||||
best = v + 1;
|
minDTZ = dtz + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return best;
|
return minDTZ;
|
||||||
} else {
|
|
||||||
int best = -1;
|
|
||||||
|
|
||||||
if (!pos.checkers())
|
|
||||||
end = generate<NON_EVASIONS>(pos, stack);
|
|
||||||
else
|
|
||||||
end = generate<EVASIONS>(pos, stack);
|
|
||||||
|
|
||||||
for (moves = stack; moves < end; ++moves) {
|
|
||||||
int v;
|
|
||||||
Move move = moves->move;
|
|
||||||
|
|
||||||
if (!pos.legal(move, ci.pinned))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
pos.do_move(move, st, pos.gives_check(move, ci));
|
|
||||||
|
|
||||||
if (st.rule50 == 0) {
|
|
||||||
if (wdl == -2) v = -1;
|
|
||||||
else {
|
|
||||||
v = search(pos, WDLCursedWin, WDLWin, result);
|
|
||||||
v = (v == 2) ? 0 : -101;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
v = -probe_dtz(pos, result) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos.undo_move(move);
|
|
||||||
|
|
||||||
if (*result == FAIL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (v < best)
|
|
||||||
best = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
return best;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the losing move that maximizes DTZ. Of course, all moves will
|
||||||
|
// return a negative dtz value because the position is known to lose.
|
||||||
|
for (const Move& move : MoveList<LEGAL>(pos))
|
||||||
|
{
|
||||||
|
pos.do_move(move, st, pos.gives_check(move, ci));
|
||||||
|
|
||||||
|
if (st.rule50 > 0) // Not a capture or pawn move
|
||||||
|
dtz = -probe_dtz(pos, result) - 1;
|
||||||
|
|
||||||
|
else if (wdl == WDLLoss)
|
||||||
|
dtz = -1;
|
||||||
|
|
||||||
|
else
|
||||||
|
dtz = search(pos, WDLCursedWin, WDLWin, result) == WDLWin ? 0 : -101;
|
||||||
|
|
||||||
|
pos.undo_move(move);
|
||||||
|
|
||||||
|
if (*result == FAIL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (dtz < minDTZ)
|
||||||
|
minDTZ = dtz;
|
||||||
|
}
|
||||||
|
|
||||||
|
return minDTZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Probe the DTZ table for a particular position.
|
// Probe the DTZ table for a particular position.
|
||||||
|
|
Loading…
Add table
Reference in a new issue