Skip to content

Commit

Permalink
Penalty for a quiet ttMove that fails low
Browse files Browse the repository at this point in the history
Also the penalty/bonus function is misleading, we
should simply change it to stat_bonus(depth) for
bonus and -stat_bonus(depth+ ONE_PLY) for extra
penalty.

STC:
LLR: 2.96 (-2.94,2.94) [0.00,5.00]
Total: 11656 W: 2183 L: 2008 D: 7465

LTC:
LLR: 2.95 (-2.94,2.94) [0.00,5.00]
Total: 11152 W: 1531 L: 1377 D: 8244

Bench: 6101931
  • Loading branch information
VoyagerOne authored and mcostalba committed Jan 28, 2017
1 parent 471f7a1 commit 5254a60
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ namespace {
return Reductions[PvNode][i][std::min(d / ONE_PLY, 63)][std::min(mn, 63)] * ONE_PLY;
}

// History and stats update bonus, based on depth
Value stat_bonus(Depth depth) {
int d = depth / ONE_PLY ;
return Value(d * d + 2 * d - 2);
}

// Skill structure is used to implement strength limit
struct Skill {
Skill(int l) : level(l) {}
Expand Down Expand Up @@ -155,9 +161,6 @@ namespace {

const size_t HalfDensitySize = std::extent<decltype(HalfDensity)>::value;

Value bonus(Depth depth) { int d = depth / ONE_PLY ; return Value(d * d + 2 * d - 2); }
Value penalty(Depth depth) { int d = depth / ONE_PLY ; return -Value(d * d + 4 * d + 1); }

EasyMoveManager EasyMove;
Value DrawValue[COLOR_NB];

Expand Down Expand Up @@ -642,14 +645,24 @@ namespace {
: (tte->bound() & BOUND_UPPER)))
{
// If ttMove is quiet, update move sorting heuristics on TT hit
if (ttValue >= beta && ttMove)
if (ttMove)
{
if (!pos.capture_or_promotion(ttMove))
update_stats(pos, ss, ttMove, nullptr, 0, bonus(depth));
if (ttValue >= beta)
{
if (!pos.capture_or_promotion(ttMove))
update_stats(pos, ss, ttMove, nullptr, 0, stat_bonus(depth));

// Extra penalty for a quiet TT move in previous ply when it gets refuted
if ((ss-1)->moveCount == 1 && !pos.captured_piece())
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, penalty(depth));
// Extra penalty for a quiet TT move in previous ply when it gets refuted
if ((ss-1)->moveCount == 1 && !pos.captured_piece())
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, -stat_bonus(depth + ONE_PLY));
}
// Penalty for a quiet ttMove that fails low
else if (ttValue < alpha && !pos.capture_or_promotion(ttMove))
{
Value penalty = -stat_bonus(depth + ONE_PLY);
thisThread->history.update(pos.side_to_move(), ttMove, penalty);
update_cm_stats(ss, pos.moved_piece(ttMove), to_sq(ttMove), penalty);
}
}
return ttValue;
}
Expand Down Expand Up @@ -988,7 +1001,7 @@ namespace {
+ (fmh ? (*fmh )[moved_piece][to_sq(move)] : VALUE_ZERO)
+ (fmh2 ? (*fmh2)[moved_piece][to_sq(move)] : VALUE_ZERO)
+ thisThread->history.get(~pos.side_to_move(), move)
- 8000; // Correction factor
- 4000; // Correction factor

// Decrease/increase reduction by comparing opponent's stat score
if (ss->history > VALUE_ZERO && (ss-1)->history < VALUE_ZERO)
Expand Down Expand Up @@ -1120,17 +1133,17 @@ namespace {

// Quiet best move: update move sorting heuristics
if (!pos.capture_or_promotion(bestMove))
update_stats(pos, ss, bestMove, quietsSearched, quietCount, bonus(depth));
update_stats(pos, ss, bestMove, quietsSearched, quietCount, stat_bonus(depth));

// Extra penalty for a quiet TT move in previous ply when it gets refuted
if ((ss-1)->moveCount == 1 && !pos.captured_piece())
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, penalty(depth));
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, -stat_bonus(depth + ONE_PLY));
}
// Bonus for prior countermove that caused the fail low
else if ( depth >= 3 * ONE_PLY
&& !pos.captured_piece()
&& is_ok((ss-1)->currentMove))
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, bonus(depth));
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, stat_bonus(depth));

tte->save(posKey, value_to_tt(bestValue, ss->ply),
bestValue >= beta ? BOUND_LOWER :
Expand Down

2 comments on commit 5254a60

@Quocvuong82
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Marco Costalba!

I have some questions to ask:

  1. Why prefetch(TT.first_entry(st->key)) when do_null_move only (not prefetch(TT.first_entry(st->key)) when do_move)
  2. when do_null_move, set_check_info need only recompute si->checkSquares only, do not need recompute si->blockersForKing, so:
    struct StateInfo {

// Copied when making a move
Key pawnKey;
Key materialKey;
Value nonPawnMaterial[COLOR_NB];
int castlingRights;
int rule50;
int pliesFromNull;
Score psq;
Square epSquare;

// Not copied when making a move (will be recomputed anyhow)
Key key;
Bitboard checkersBB;
Bitboard blockersForKing[COLOR_NB];
Bitboard pinnersForKing[COLOR_NB];
// Not copied when making a null move (will be recomputed anyhow)
Piece capturedPiece;
StateInfo* previous;
Bitboard checkSquares[PIECE_TYPE_NB];
};
this gain 1% faster

  1. in generate<QUIET_CHECKS>, I think that:
    if (pt == KING)
    b &= ~StepAttacksBB[KING][pos.square(~us)];
    not:
    if (pt == KING)
    b &= ~PseudoAttacks[QUEEN][pos.square(~us)];
    Please fix it.

@anshulongithub
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VoyagerOne @mcostalba Could you guys please confirm if this committed patch is exactly equivalent to @VoyagerOne's original "update search" patch? Thank you.

Please sign in to comment.