mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Small cleanup in search Step.5
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
5aef9186ac
commit
977f6349a9
1 changed files with 28 additions and 30 deletions
|
@ -1043,28 +1043,27 @@ namespace {
|
||||||
return value_from_tt(tte->value(), ply);
|
return value_from_tt(tte->value(), ply);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 5. Evaluate the position statically
|
// Step 5. Evaluate the position statically and
|
||||||
// At PV nodes we do this only to update gain statistics
|
// update gain statistics of parent move.
|
||||||
isCheck = pos.is_check();
|
isCheck = pos.is_check();
|
||||||
if (!isCheck)
|
if (isCheck)
|
||||||
|
ss->eval = VALUE_NONE;
|
||||||
|
else if (tte)
|
||||||
{
|
{
|
||||||
if (tte)
|
assert(tte->static_value() != VALUE_NONE);
|
||||||
{
|
|
||||||
assert(tte->static_value() != VALUE_NONE);
|
|
||||||
|
|
||||||
ss->eval = tte->static_value();
|
ss->eval = tte->static_value();
|
||||||
ei.kingDanger[pos.side_to_move()] = tte->king_danger();
|
ei.kingDanger[pos.side_to_move()] = tte->king_danger();
|
||||||
}
|
refinedValue = refine_eval(tte, ss->eval, ply);
|
||||||
else
|
|
||||||
{
|
|
||||||
ss->eval = evaluate(pos, ei);
|
|
||||||
TT.store(posKey, VALUE_NONE, VALUE_TYPE_NONE, DEPTH_NONE, MOVE_NONE, ss->eval, ei.kingDanger[pos.side_to_move()]);
|
|
||||||
}
|
|
||||||
refinedValue = refine_eval(tte, ss->eval, ply); // Enhance accuracy with TT value if possible
|
|
||||||
update_gains(pos, (ss-1)->currentMove, (ss-1)->eval, ss->eval);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ss->eval = VALUE_NONE;
|
{
|
||||||
|
refinedValue = ss->eval = evaluate(pos, ei);
|
||||||
|
TT.store(posKey, VALUE_NONE, VALUE_TYPE_NONE, DEPTH_NONE, MOVE_NONE, ss->eval, ei.kingDanger[pos.side_to_move()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save gain for the parent non-capture move
|
||||||
|
update_gains(pos, (ss-1)->currentMove, (ss-1)->eval, ss->eval);
|
||||||
|
|
||||||
// Step 6. Razoring (is omitted in PV nodes)
|
// Step 6. Razoring (is omitted in PV nodes)
|
||||||
if ( !PvNode
|
if ( !PvNode
|
||||||
|
@ -1090,8 +1089,8 @@ namespace {
|
||||||
if ( !PvNode
|
if ( !PvNode
|
||||||
&& !ss->skipNullMove
|
&& !ss->skipNullMove
|
||||||
&& depth < RazorDepth
|
&& depth < RazorDepth
|
||||||
&& refinedValue >= beta + futility_margin(depth, 0)
|
|
||||||
&& !isCheck
|
&& !isCheck
|
||||||
|
&& refinedValue >= beta + futility_margin(depth, 0)
|
||||||
&& !value_is_mate(beta)
|
&& !value_is_mate(beta)
|
||||||
&& pos.non_pawn_material(pos.side_to_move()))
|
&& pos.non_pawn_material(pos.side_to_move()))
|
||||||
return refinedValue - futility_margin(depth, 0);
|
return refinedValue - futility_margin(depth, 0);
|
||||||
|
@ -1103,8 +1102,8 @@ namespace {
|
||||||
if ( !PvNode
|
if ( !PvNode
|
||||||
&& !ss->skipNullMove
|
&& !ss->skipNullMove
|
||||||
&& depth > OnePly
|
&& depth > OnePly
|
||||||
&& refinedValue >= beta - (depth >= 4 * OnePly ? NullMoveMargin : 0)
|
|
||||||
&& !isCheck
|
&& !isCheck
|
||||||
|
&& refinedValue >= beta - (depth >= 4 * OnePly ? NullMoveMargin : 0)
|
||||||
&& !value_is_mate(beta)
|
&& !value_is_mate(beta)
|
||||||
&& pos.non_pawn_material(pos.side_to_move()))
|
&& pos.non_pawn_material(pos.side_to_move()))
|
||||||
{
|
{
|
||||||
|
@ -1222,7 +1221,7 @@ namespace {
|
||||||
// singular extension search result is still valid.
|
// singular extension search result is still valid.
|
||||||
if ( !PvNode
|
if ( !PvNode
|
||||||
&& depth < SingularExtensionDepth[PvNode] + 5 * OnePly
|
&& depth < SingularExtensionDepth[PvNode] + 5 * OnePly
|
||||||
&& ((ttx = TT.retrieve(pos.get_exclusion_key())) != NULL))
|
&& (ttx = TT.retrieve(pos.get_exclusion_key())) != NULL)
|
||||||
{
|
{
|
||||||
if (is_upper_bound(ttx->type()))
|
if (is_upper_bound(ttx->type()))
|
||||||
ext = OnePly;
|
ext = OnePly;
|
||||||
|
@ -1350,7 +1349,7 @@ namespace {
|
||||||
bestValue = value;
|
bestValue = value;
|
||||||
if (value > alpha)
|
if (value > alpha)
|
||||||
{
|
{
|
||||||
if (PvNode && value < beta) // This guarantees that always: alpha < beta
|
if (PvNode && value < beta) // We want always alpha < beta
|
||||||
alpha = value;
|
alpha = value;
|
||||||
|
|
||||||
if (value == value_mate_in(ply + 1))
|
if (value == value_mate_in(ply + 1))
|
||||||
|
@ -1377,7 +1376,7 @@ namespace {
|
||||||
// no legal moves, it must be mate or stalemate.
|
// no legal moves, it must be mate or stalemate.
|
||||||
// If one move was excluded return fail low score.
|
// If one move was excluded return fail low score.
|
||||||
if (!moveCount)
|
if (!moveCount)
|
||||||
return excludedMove ? oldAlpha : (isCheck ? value_mated_in(ply) : VALUE_DRAW);
|
return excludedMove ? oldAlpha : isCheck ? value_mated_in(ply) : VALUE_DRAW;
|
||||||
|
|
||||||
// Step 20. Update tables
|
// Step 20. Update tables
|
||||||
// If the search is not aborted, update the transposition table,
|
// If the search is not aborted, update the transposition table,
|
||||||
|
@ -1385,9 +1384,9 @@ namespace {
|
||||||
if (AbortSearch || TM.thread_should_stop(threadID))
|
if (AbortSearch || TM.thread_should_stop(threadID))
|
||||||
return bestValue;
|
return bestValue;
|
||||||
|
|
||||||
ValueType f = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT);
|
ValueType vt = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT);
|
||||||
move = (bestValue <= oldAlpha ? MOVE_NONE : ss->bestMove);
|
move = (bestValue <= oldAlpha ? MOVE_NONE : ss->bestMove);
|
||||||
TT.store(posKey, value_to_tt(bestValue, ply), f, depth, move, ss->eval, ei.kingDanger[pos.side_to_move()]);
|
TT.store(posKey, value_to_tt(bestValue, ply), vt, depth, move, ss->eval, ei.kingDanger[pos.side_to_move()]);
|
||||||
|
|
||||||
// Update killers and history only for non capture moves that fails high
|
// Update killers and history only for non capture moves that fails high
|
||||||
if (bestValue >= beta)
|
if (bestValue >= beta)
|
||||||
|
@ -1460,6 +1459,7 @@ namespace {
|
||||||
if (tte)
|
if (tte)
|
||||||
{
|
{
|
||||||
assert(tte->static_value() != VALUE_NONE);
|
assert(tte->static_value() != VALUE_NONE);
|
||||||
|
|
||||||
ei.kingDanger[pos.side_to_move()] = tte->king_danger();
|
ei.kingDanger[pos.side_to_move()] = tte->king_danger();
|
||||||
bestValue = tte->static_value();
|
bestValue = tte->static_value();
|
||||||
}
|
}
|
||||||
|
@ -1569,8 +1569,8 @@ namespace {
|
||||||
|
|
||||||
// Update transposition table
|
// Update transposition table
|
||||||
Depth d = (depth == Depth(0) ? Depth(0) : Depth(-1));
|
Depth d = (depth == Depth(0) ? Depth(0) : Depth(-1));
|
||||||
ValueType f = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT);
|
ValueType vt = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT);
|
||||||
TT.store(pos.get_key(), value_to_tt(bestValue, ply), f, d, ss->bestMove, ss->eval, ei.kingDanger[pos.side_to_move()]);
|
TT.store(pos.get_key(), value_to_tt(bestValue, ply), vt, d, ss->bestMove, ss->eval, ei.kingDanger[pos.side_to_move()]);
|
||||||
|
|
||||||
// Update killers only for checking moves that fails high
|
// Update killers only for checking moves that fails high
|
||||||
if ( bestValue >= beta
|
if ( bestValue >= beta
|
||||||
|
@ -1989,8 +1989,7 @@ namespace {
|
||||||
|
|
||||||
Value refine_eval(const TTEntry* tte, Value defaultEval, int ply) {
|
Value refine_eval(const TTEntry* tte, Value defaultEval, int ply) {
|
||||||
|
|
||||||
if (!tte)
|
assert(tte);
|
||||||
return defaultEval;
|
|
||||||
|
|
||||||
Value v = value_from_tt(tte->value(), ply);
|
Value v = value_from_tt(tte->value(), ply);
|
||||||
|
|
||||||
|
@ -2046,8 +2045,7 @@ namespace {
|
||||||
&& before != VALUE_NONE
|
&& before != VALUE_NONE
|
||||||
&& after != VALUE_NONE
|
&& after != VALUE_NONE
|
||||||
&& pos.captured_piece() == NO_PIECE_TYPE
|
&& pos.captured_piece() == NO_PIECE_TYPE
|
||||||
&& !move_is_castle(m)
|
&& !move_is_special(m))
|
||||||
&& !move_is_promotion(m))
|
|
||||||
H.set_gain(pos.piece_on(move_to(m)), move_to(m), -(before + after));
|
H.set_gain(pos.piece_on(move_to(m)), move_to(m), -(before + after));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue