Skip to content

Commit

Permalink
Updated to "Tweak late move reductions at root".
Browse files Browse the repository at this point in the history
official-stockfish/Stockfish@baf184e
This is more or less SF 11, but I skipped one SMP patch.
  • Loading branch information
syzygy1 committed Jun 28, 2020
1 parent 3566be8 commit f461978
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 172 deletions.
32 changes: 16 additions & 16 deletions src/endgame.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ static Value EvaluateKXK(const Pos *pos, unsigned strongSide)
unsigned weakSide = strongSide ^ 1;

assert(verify_material(pos, weakSide, VALUE_ZERO, 0));
assert(!pos_checkers()); // Eval is never called when in check
assert(!checkers()); // Eval is never called when in check

// Stalemate detection with lone king
if (pos_stm() == weakSide) {
if (stm() == weakSide) {
ExtMove list[MAX_MOVES];
if (generate_legal(pos, list) == list)
return VALUE_DRAW;
Expand All @@ -186,7 +186,7 @@ static Value EvaluateKXK(const Pos *pos, unsigned strongSide)
&& (pieces_p(BISHOP) & bb & LightSquares)))
result = min(result + VALUE_KNOWN_WIN, VALUE_MATE_IN_MAX_PLY - 1);

return strongSide == pos_stm() ? result : -result;
return strongSide == stm() ? result : -result;
}


Expand Down Expand Up @@ -215,7 +215,7 @@ static Value EvaluateKBNK(const Pos *pos, unsigned strongSide)
+ PushClose[distance(winnerKSq, loserKSq)]
+ PushToCorners[loserKSq];

return strongSide == pos_stm() ? result : -result;
return strongSide == stm() ? result : -result;
}


Expand All @@ -232,14 +232,14 @@ static Value EvaluateKPK(const Pos *pos, unsigned strongSide)
Square bksq = normalize(pos, strongSide, square_of(weakSide, KING));
Square psq = normalize(pos, strongSide, lsb(pieces_p(PAWN)));

unsigned us = strongSide == pos_stm() ? WHITE : BLACK;
unsigned us = strongSide == stm() ? WHITE : BLACK;

if (!bitbases_probe(wksq, psq, bksq, us))
return VALUE_DRAW;

Value result = VALUE_KNOWN_WIN + PawnValueEg + (Value)(rank_of(psq));

return strongSide == pos_stm() ? result : -result;
return strongSide == stm() ? result : -result;
}


Expand Down Expand Up @@ -268,7 +268,7 @@ static Value EvaluateKRKP(const Pos *pos, unsigned strongSide)

// If the weaker side's king is too far from the pawn and the rook,
// it's a win.
else if ( distance(bksq, psq) >= 3 + (pos_stm() == weakSide)
else if ( distance(bksq, psq) >= 3 + (stm() == weakSide)
&& distance(bksq, rsq) >= 3)
result = RookValueEg - distance(wksq, psq);

Expand All @@ -277,15 +277,15 @@ static Value EvaluateKRKP(const Pos *pos, unsigned strongSide)
else if ( rank_of(bksq) <= RANK_3
&& distance(bksq, psq) == 1
&& rank_of(wksq) >= RANK_4
&& distance(wksq, psq) > 2 + (pos_stm() == strongSide))
&& distance(wksq, psq) > 2 + (stm() == strongSide))
result = (Value)(80) - 8 * distance(wksq, psq);

else
result = (Value)(200) - 8 * ( distance(wksq, psq + SOUTH)
- distance(bksq, psq + SOUTH)
- distance(psq, queeningSq));

return strongSide == pos_stm() ? result : -result;
return strongSide == stm() ? result : -result;
}


Expand All @@ -299,7 +299,7 @@ static Value EvaluateKRKB(const Pos *pos, unsigned strongSide)
assert(verify_material(pos, weakSide, BishopValueMg, 0));

Value result = (Value)PushToEdges[square_of(weakSide, KING)];
return strongSide == pos_stm() ? result : -result;
return strongSide == stm() ? result : -result;
}


Expand All @@ -315,7 +315,7 @@ static Value EvaluateKRKN(const Pos *pos, unsigned strongSide)
Square bksq = square_of(weakSide, KING);
Square bnsq = lsb(pieces_p(KNIGHT));
Value result = (Value)PushToEdges[bksq] + PushAway[distance(bksq, bnsq)];
return strongSide == pos_stm() ? result : -result;
return strongSide == stm() ? result : -result;
}


Expand All @@ -341,7 +341,7 @@ static Value EvaluateKQKP(const Pos *pos, unsigned strongSide)
|| !((FileABB | FileCBB | FileFBB | FileHBB) & sq_bb(pawnSq)))
result += QueenValueEg - PawnValueEg;

return strongSide == pos_stm() ? result : -result;
return strongSide == stm() ? result : -result;
}


Expand All @@ -365,7 +365,7 @@ static Value EvaluateKQKR(const Pos *pos, unsigned strongSide)
+ PushToEdges[loserKSq]
+ PushClose[distance(winnerKSq, loserKSq)];

return strongSide == pos_stm() ? result : -result;
return strongSide == stm() ? result : -result;
}


Expand All @@ -381,7 +381,7 @@ static Value EvaluateKNNKP(const Pos *pos, unsigned strongSide)
- PawnValueEg
+ PushToEdges[square_of(weakSide, KING)];

return strongSide == pos_stm() ? result : -result;
return strongSide == stm() ? result : -result;
}


Expand Down Expand Up @@ -512,7 +512,7 @@ static int ScaleKRPKR(const Pos *pos, unsigned strongSide)
File f = file_of(wpsq);
Rank r = rank_of(wpsq);
Square queeningSq = make_square(f, RANK_8);
signed tempo = (pos_stm() == strongSide);
signed tempo = (stm() == strongSide);

// If the pawn is not too far advanced and the defending king defends
// the queening square, use the third-rank defence.
Expand Down Expand Up @@ -878,7 +878,7 @@ static int ScaleKPKP(const Pos *pos, unsigned strongSide)
Square bksq = normalize(pos, strongSide, square_of(weakSide, KING));
Square psq = normalize(pos, strongSide, square_of(strongSide, PAWN));

unsigned us = strongSide == pos_stm() ? WHITE : BLACK;
unsigned us = strongSide == stm() ? WHITE : BLACK;

// If the pawn has advanced to the fifth rank or further, and is not a
// rook pawn, it is too dangerous to assume that it is at least a draw.
Expand Down
34 changes: 17 additions & 17 deletions src/evaluate.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,19 @@ INLINE Score evaluate_piece(const Pos *pos, EvalInfo *ei, Score *mobility,
// squares
if (more_than_one(attacks_bb_bishop(s, pieces_p(PAWN)) & Center))
score += LongDiagonalBishop;
}

// An important Chess960 pattern: A cornered bishop blocked by a friendly
// pawn diagonally in front of it is a very serious problem, especially
// when that pawn is also blocked.
if ( Pt == BISHOP
&& is_chess960()
&& (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1))) {
Square d = pawn_push(Us) + (file_of(s) == FILE_A ? EAST : WEST);
if (piece_on(s + d) == make_piece(Us, PAWN))
score -= piece_on(s + d + pawn_push(Us)) ? CorneredBishop * 4
: piece_on(s + d + d) == make_piece(Us, PAWN) ? CorneredBishop * 2
: CorneredBishop;
// An important Chess960 pattern: a cornered bishop blocked by a
// friendly pawn diagonally in front of it is a very serious problem,
// especially when that pawn is also blocked.
if ( is_chess960()
&& (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1)))
{
Square d = pawn_push(Us) + (file_of(s) == FILE_A ? EAST : WEST);
if (piece_on(s + d) == make_piece(Us, PAWN))
score -= piece_on(s + d + pawn_push(Us)) ? CorneredBishop * 4
: piece_on(s + d + d) == make_piece(Us, PAWN) ? CorneredBishop * 2
: CorneredBishop;
}
}
}

Expand Down Expand Up @@ -709,7 +709,7 @@ INLINE int evaluate_scale_factor(const Pos *pos, EvalInfo *ei, Value eg)
sf = 22;
else
sf = min(sf, 36 + (opposite_bishops(pos) ? 2 : 7) * piece_count(strongSide, PAWN));
sf = max(0, sf - (pos_rule50_count() - 12) / 4);
sf = max(0, sf - (rule50_count() - 12) / 4);
}

return sf;
Expand All @@ -721,7 +721,7 @@ INLINE int evaluate_scale_factor(const Pos *pos, EvalInfo *ei, Value eg)

Value evaluate(const Pos *pos)
{
assert(!pos_checkers());
assert(!checkers());

Score mobility[2] = { SCORE_ZERO, SCORE_ZERO };
Value v;
Expand All @@ -739,7 +739,7 @@ Value evaluate(const Pos *pos)
// in the position struct (material + piece square tables) and the
// material imbalance. Score is computed internally from the white point
// of view.
Score score = pos_psq_score() + material_imbalance(ei.me) + pos->contempt;
Score score = psq_score() + material_imbalance(ei.me) + pos->contempt;

// Probe the pawn hash table
ei.pe = pawn_probe(pos);
Expand All @@ -748,7 +748,7 @@ Value evaluate(const Pos *pos)
// Early exit if score is high
v = (mg_value(score) + eg_value(score)) / 2;
if (abs(v) > LazyThreshold + non_pawn_material() / 64)
return pos_stm() == WHITE ? v : -v;
return stm() == WHITE ? v : -v;

// Initialize attack and king safety bitboards.
evalinfo_init(pos, &ei, WHITE);
Expand Down Expand Up @@ -789,5 +789,5 @@ Value evaluate(const Pos *pos)

v /= PHASE_MIDGAME;

return (pos_stm() == WHITE ? v : -v) + Tempo; // Side to move point of view
return (stm() == WHITE ? v : -v) + Tempo; // Side to move point of view
}
2 changes: 1 addition & 1 deletion src/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void material_entry_fill(const Pos *pos, MaterialEntry *e, Key key);

INLINE MaterialEntry *material_probe(const Pos *pos)
{
Key key = pos_material_key();
Key key = material_key();
MaterialEntry *e = &pos->materialTable[key >> (64-13)];

if (unlikely(e->key != key))
Expand Down
22 changes: 11 additions & 11 deletions src/movegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ INLINE ExtMove *generate_all(const Pos *pos, ExtMove *list, Bitboard target,
INLINE ExtMove *generate(const Pos *pos, ExtMove *list, const int Type)
{
assert(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS);
assert(!pos_checkers());
assert(!checkers());

Color us = pos_stm();
Color us = stm();

Bitboard target = Type == CAPTURES ? pieces_c(us ^ 1)
: Type == QUIETS ? ~pieces()
Expand Down Expand Up @@ -280,9 +280,9 @@ ExtMove *generate_non_evasions(const Pos *pos, ExtMove *list)
// knight underpromotions that give check.
ExtMove *generate_quiet_checks(const Pos *pos, ExtMove *list)
{
assert(!pos_checkers());
assert(!checkers());

Color us = pos_stm();
Color us = stm();
Bitboard dc = blockers_for_king(pos, us ^ 1) & pieces_c(us);

while (dc) {
Expand Down Expand Up @@ -310,12 +310,12 @@ ExtMove *generate_quiet_checks(const Pos *pos, ExtMove *list)
// side to move is in check.
ExtMove *generate_evasions(const Pos *pos, ExtMove *list)
{
assert(pos_checkers());
assert(checkers());

Color us = pos_stm();
Color us = stm();
Square ksq = square_of(us, KING);
Bitboard sliderAttacks = 0;
Bitboard sliders = pos_checkers() & ~pieces_pp(KNIGHT, PAWN);
Bitboard sliders = checkers() & ~pieces_pp(KNIGHT, PAWN);

// Find all the squares attacked by slider checkers. We will remove them
// from the king evasions in order to skip known illegal moves, which
Expand All @@ -330,11 +330,11 @@ ExtMove *generate_evasions(const Pos *pos, ExtMove *list)
while (b)
(list++)->move = make_move(ksq, pop_lsb(&b));

if (more_than_one(pos_checkers()))
if (more_than_one(checkers()))
return list; // Double check, only a king move can save the day

// Generate blocking evasions or captures of the checking piece
Square checksq = lsb(pos_checkers());
Square checksq = lsb(checkers());
Bitboard target = between_bb(ksq, checksq) | sq_bb(checksq);

return us == WHITE ? generate_all(pos, list, target, WHITE, EVASIONS)
Expand All @@ -346,12 +346,12 @@ ExtMove *generate_evasions(const Pos *pos, ExtMove *list)
SMALL
ExtMove *generate_legal(const Pos *pos, ExtMove *list)
{
Color us = pos_stm();
Color us = stm();
Bitboard pinned = blockers_for_king(pos, us) & pieces_c(us);
Square ksq = square_of(us, KING);
ExtMove *cur = list;

list = pos_checkers() ? generate_evasions(pos, list)
list = checkers() ? generate_evasions(pos, list)
: generate_non_evasions(pos, list);
while (cur != list)
if ( (pinned || from_sq(cur->move) == ksq
Expand Down
4 changes: 2 additions & 2 deletions src/movepick.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void score_quiets(const Pos *pos)
PieceToHistory *fmh2 = (st-4)->history;
PieceToHistory *fmh3 = (st-6)->history;

Color c = pos_stm();
Color c = stm();

for (ExtMove *m = st->cur; m < st->endMoves; m++) {
uint32_t move = m->move & 4095;
Expand All @@ -107,7 +107,7 @@ static void score_evasions(const Pos *pos)

ButterflyHistory *history = pos->history;
PieceToHistory *cmh = (st-1)->history;
Color c = pos_stm();
Color c = stm();

for (ExtMove *m = st->cur; m < st->endMoves; m++)
if (is_capture(pos, m->move))
Expand Down
6 changes: 3 additions & 3 deletions src/movepick.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ INLINE void mp_init(const Pos *pos, Move ttm, Depth d)
st->mpKillers[0] = st->killers[0];
st->mpKillers[1] = st->killers[1];

st->stage = pos_checkers() ? ST_EVASION : ST_MAIN_SEARCH;
st->stage = checkers() ? ST_EVASION : ST_MAIN_SEARCH;
st->ttMove = ttm;
if (!ttm || !is_pseudo_legal(pos, ttm)) {
st->stage++;
Expand All @@ -91,7 +91,7 @@ INLINE void mp_init_q(const Pos *pos, Move ttm, Depth d, Square s)

Stack *st = pos->st;

st->stage = pos_checkers() ? ST_EVASION : ST_QSEARCH;
st->stage = checkers() ? ST_EVASION : ST_QSEARCH;
st->ttMove = ttm
&& is_pseudo_legal(pos, ttm)
&& (d > DEPTH_QS_RECAPTURES || to_sq(ttm) == s) ? ttm : 0;
Expand All @@ -103,7 +103,7 @@ INLINE void mp_init_q(const Pos *pos, Move ttm, Depth d, Square s)

INLINE void mp_init_pc(const Pos *pos, Move ttm, Value th)
{
assert(!pos_checkers());
assert(!checkers());

Stack *st = pos->st;

Expand Down
Loading

1 comment on commit f461978

@mausalimi
Copy link

Choose a reason for hiding this comment

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

This is more or less SF 11, but I skipped one SMP patch.

^ great, thanks for the effort. :)

Please sign in to comment.