- // Probe each move
- for (size_t i = 0; i < rootMoves.size(); ++i) {
- Move move = rootMoves[i].pv[0];
- pos.do_move(move, st);
- int v = 0;
-
- if (pos.checkers() && dtz > 0) {
- ExtMove s[MAX_MOVES];
-
- if (generate<LEGAL>(pos, s) == s)
- v = 1;
- }
-
- if (!v) {
- if (st.rule50 != 0) {
- v = -probe_dtz(pos, &result);
-
- if (v > 0)
- ++v;
- else if (v < 0)
- --v;
- } else {
- v = -probe_wdl(pos, &result);
- v = dtz_before_zeroing(WDLScore(v));
- }
- }
-
- pos.undo_move(move);
-
- if (result == FAIL)
- return false;
-
- rootMoves[i].score = (Value)v;
- }
-
- // Obtain 50-move counter for the root position.
- // In Stockfish there seems to be no clean way, so we do it like this:
- int cnt50 = st.previous ? st.previous->rule50 : 0;
-
- // Use 50-move counter to determine whether the root position is
- // won, lost or drawn.
- WDLScore wdl = WDLDraw;
-
- if (dtz > 0)
- wdl = (dtz + cnt50 <= 100) ? WDLWin : WDLCursedWin;
- else if (dtz < 0)
- wdl = (-dtz + cnt50 <= 100) ? WDLLoss : WDLBlessedLoss;