X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=204e5fc8b7440cf941c893fe3a4deafc68285d3c;hp=856c003a3654f758f44cc5523264fb84910255d7;hb=e40b06a0503b44bae5508a371d961914828214b6;hpb=eb1a4f11fa18d22543bef9a507d57a5980867965 diff --git a/src/search.cpp b/src/search.cpp index 856c003a..204e5fc8 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -42,6 +42,7 @@ namespace Search { LimitsType Limits; std::vector RootMoves; Position RootPosition; + Color RootColor; Time::point SearchTime; StateStackPtr SetupStates; } @@ -91,7 +92,7 @@ namespace { int BestMoveChanges; int SkillLevel; bool SkillLevelEnabled, Chess960; - Value DrawValue[2]; + Value DrawValue[COLOR_NB]; History H; template @@ -136,7 +137,7 @@ void Search::init() { // Init futility move count array for (d = 0; d < 32; d++) - FutilityMoveCounts[d] = int(3.001 + 0.25 * pow(d, 2.0)); + FutilityMoveCounts[d] = int(3.001 + 0.25 * pow(double(d), 2.0)); } @@ -174,7 +175,7 @@ void Search::think() { Position& pos = RootPosition; Chess960 = pos.is_chess960(); - Eval::RootColor = pos.side_to_move(); + RootColor = pos.side_to_move(); TimeMgr.init(Limits, pos.startpos_ply_counter(), pos.side_to_move()); TT.new_search(); H.clear(); @@ -192,8 +193,8 @@ void Search::think() { { int cf = Options["Contempt Factor"] * PawnValueMg / 100; // In centipawns cf = cf * MaterialTable::game_phase(pos) / PHASE_MIDGAME; // Scale down with phase - DrawValue[ Eval::RootColor] = VALUE_DRAW - Value(cf); - DrawValue[~Eval::RootColor] = VALUE_DRAW + Value(cf); + DrawValue[ RootColor] = VALUE_DRAW - Value(cf); + DrawValue[~RootColor] = VALUE_DRAW + Value(cf); } else DrawValue[WHITE] = DrawValue[BLACK] = VALUE_DRAW; @@ -557,6 +558,8 @@ namespace { : ttValue >= beta ? (tte->type() & BOUND_LOWER) : (tte->type() & BOUND_UPPER))) { + assert(ttValue != VALUE_NONE); // Due to depth > DEPTH_NONE + TT.refresh(tte); ss->currentMove = ttMove; // Can be MOVE_NONE @@ -574,6 +577,7 @@ namespace { // Step 5. Evaluate the position statically and update parent's gain statistics if (inCheck) ss->eval = ss->evalMargin = refinedValue = VALUE_NONE; + else if (tte) { assert(tte->static_value() != VALUE_NONE); @@ -798,7 +802,7 @@ split_point_start: // At split points actual search starts from here && type_of(pos.piece_on(to_sq(move))) != PAWN && type_of(move) == NORMAL && ( pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) - - PieceValue[Mg][pos.piece_on(to_sq(move))] == VALUE_ZERO)); + - PieceValue[MG][pos.piece_on(to_sq(move))] == VALUE_ZERO)); // Step 12. Extend checks and, in PV nodes, also dangerous moves if (PvNode && dangerous) @@ -818,6 +822,8 @@ split_point_start: // At split points actual search starts from here && pos.pl_move_is_legal(move, ci.pinned) && abs(ttValue) < VALUE_KNOWN_WIN) { + assert(ttValue != VALUE_NONE); + Value rBeta = ttValue - int(depth); ss->excludedMove = move; ss->skipNullMove = true; @@ -1018,7 +1024,8 @@ split_point_start: // At split points actual search starts from here // If we are in a singular extension search then return a fail low score. // A split node has at least one move, the one tried before to be splitted. if (!moveCount) - return excludedMove ? alpha : inCheck ? mated_in(ss->ply) : VALUE_DRAW; + return excludedMove ? alpha + : inCheck ? mated_in(ss->ply) : DrawValue[pos.side_to_move()]; // If we have pruned all the moves without searching return a fail-low score if (bestValue == -VALUE_INFINITE) @@ -1111,6 +1118,8 @@ split_point_start: // At split points actual search starts from here : ttValue >= beta ? (tte->type() & BOUND_LOWER) : (tte->type() & BOUND_UPPER))) { + assert(ttValue != VALUE_NONE); // Due to ttDepth > DEPTH_NONE + ss->currentMove = ttMove; // Can be MOVE_NONE return ttValue; } @@ -1175,7 +1184,7 @@ split_point_start: // At split points actual search starts from here && !pos.is_passed_pawn_push(move)) { futilityValue = futilityBase - + PieceValue[Eg][pos.piece_on(to_sq(move))] + + PieceValue[EG][pos.piece_on(to_sq(move))] + (type_of(move) == ENPASSANT ? PawnValueEg : VALUE_ZERO); if (futilityValue < beta) @@ -1306,7 +1315,7 @@ split_point_start: // At split points actual search starts from here while (b) { // Note that here we generate illegal "double move"! - if (futilityBase + PieceValue[Eg][pos.piece_on(pop_lsb(&b))] >= beta) + if (futilityBase + PieceValue[EG][pos.piece_on(pop_lsb(&b))] >= beta) return true; } @@ -1368,13 +1377,10 @@ split_point_start: // At split points actual search starts from here Value value_to_tt(Value v, int ply) { - if (v >= VALUE_MATE_IN_MAX_PLY) - return v + ply; + assert(v != VALUE_NONE); - if (v <= VALUE_MATED_IN_MAX_PLY) - return v - ply; - - return v; + return v >= VALUE_MATE_IN_MAX_PLY ? v + ply + : v <= VALUE_MATED_IN_MAX_PLY ? v - ply : v; } @@ -1384,13 +1390,9 @@ split_point_start: // At split points actual search starts from here Value value_from_tt(Value v, int ply) { - if (v >= VALUE_MATE_IN_MAX_PLY) - return v - ply; - - if (v <= VALUE_MATED_IN_MAX_PLY) - return v + ply; - - return v; + return v == VALUE_NONE ? VALUE_NONE + : v >= VALUE_MATE_IN_MAX_PLY ? v - ply + : v <= VALUE_MATED_IN_MAX_PLY ? v + ply : v; } @@ -1418,7 +1420,7 @@ split_point_start: // At split points actual search starts from here // Case 2: If the threatened piece has value less than or equal to the // value of the threatening piece, don't prune moves which defend it. if ( pos.is_capture(threat) - && ( PieceValue[Mg][pos.piece_on(tfrom)] >= PieceValue[Mg][pos.piece_on(tto)] + && ( PieceValue[MG][pos.piece_on(tfrom)] >= PieceValue[MG][pos.piece_on(tto)] || type_of(pos.piece_on(tfrom)) == KING) && pos.move_attacks_square(m, tto)) return true; @@ -1435,11 +1437,13 @@ split_point_start: // At split points actual search starts from here // refine_eval() returns the transposition table score if possible, otherwise - // falls back on static position evaluation. + // falls back on static position evaluation. Note that we never return VALUE_NONE + // even if v == VALUE_NONE. Value refine_eval(const TTEntry* tte, Value v, Value defaultEval) { assert(tte); + assert(v != VALUE_NONE || !tte->type()); if ( ((tte->type() & BOUND_LOWER) && v >= defaultEval) || ((tte->type() & BOUND_UPPER) && v < defaultEval))