+ // Step 4a. Tablebase probe
+ if (!RootNode && TB::Cardinality)
+ {
+ int piecesCnt = pos.count<ALL_PIECES>(WHITE) + pos.count<ALL_PIECES>(BLACK);
+
+ if ( piecesCnt <= TB::Cardinality
+ && (piecesCnt < TB::Cardinality || depth >= TB::ProbeDepth)
+ && pos.rule50_count() == 0)
+ {
+ int found, v = Tablebases::probe_wdl(pos, &found);
+
+ if (found)
+ {
+ TB::Hits++;
+
+ int drawScore = TB::UseRule50 ? 1 : 0;
+
+ value = v < -drawScore ? -VALUE_MATE + MAX_PLY + ss->ply
+ : v > drawScore ? VALUE_MATE - MAX_PLY - ss->ply
+ : VALUE_DRAW + 2 * v * drawScore;
+
+ tte->save(posKey, value_to_tt(value, ss->ply), BOUND_EXACT,
+ std::min(DEPTH_MAX - ONE_PLY, depth + 6 * ONE_PLY),
+ MOVE_NONE, VALUE_NONE, TT.generation());
+
+ return value;
+ }
+ }
+ }
+