mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 01:03:09 +00:00
Remove duplicated code
Introduce update_stats() and remove correspondng duplicated code. No functional change.
This commit is contained in:
parent
8454d871ec
commit
0118623495
1 changed files with 35 additions and 43 deletions
|
@ -94,6 +94,7 @@ namespace {
|
||||||
void id_loop(Position& pos);
|
void id_loop(Position& pos);
|
||||||
Value value_to_tt(Value v, int ply);
|
Value value_to_tt(Value v, int ply);
|
||||||
Value value_from_tt(Value v, int ply);
|
Value value_from_tt(Value v, int ply);
|
||||||
|
void update_stats(Position& pos, Stack* ss, Move move, Depth depth, Move* quiets, int quietsCnt);
|
||||||
string uci_pv(const Position& pos, int depth, Value alpha, Value beta);
|
string uci_pv(const Position& pos, int depth, Value alpha, Value beta);
|
||||||
|
|
||||||
struct Skill {
|
struct Skill {
|
||||||
|
@ -566,27 +567,10 @@ namespace {
|
||||||
TT.refresh(tte);
|
TT.refresh(tte);
|
||||||
ss->currentMove = ttMove; // Can be MOVE_NONE
|
ss->currentMove = ttMove; // Can be MOVE_NONE
|
||||||
|
|
||||||
// Update killers, history, and counter move on TT hit
|
// If ttMove is quiet, update killers, history, and counter move on TT hit
|
||||||
if ( ttValue >= beta
|
if (ttValue >= beta && ttMove && !pos.capture_or_promotion(ttMove) && !inCheck)
|
||||||
&& ttMove
|
update_stats(pos, ss, ttMove, depth, NULL, 0);
|
||||||
&& !pos.capture_or_promotion(ttMove)
|
|
||||||
&& !inCheck)
|
|
||||||
{
|
|
||||||
if (ss->killers[0] != ttMove)
|
|
||||||
{
|
|
||||||
ss->killers[1] = ss->killers[0];
|
|
||||||
ss->killers[0] = ttMove;
|
|
||||||
}
|
|
||||||
|
|
||||||
Value bonus = Value(int(depth) * int(depth));
|
|
||||||
History.update(pos.moved_piece(ttMove), to_sq(ttMove), bonus);
|
|
||||||
|
|
||||||
if (is_ok((ss-1)->currentMove))
|
|
||||||
{
|
|
||||||
Square prevMoveSq = to_sq((ss-1)->currentMove);
|
|
||||||
Countermoves.update(pos.piece_on(prevMoveSq), prevMoveSq, ttMove);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ttValue;
|
return ttValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1063,29 +1047,8 @@ moves_loop: // When in check and at SpNode search starts from here
|
||||||
depth, bestMove, ss->staticEval);
|
depth, bestMove, ss->staticEval);
|
||||||
|
|
||||||
// Quiet best move: update killers, history and countermoves
|
// Quiet best move: update killers, history and countermoves
|
||||||
if ( bestValue >= beta
|
if (bestValue >= beta && !pos.capture_or_promotion(bestMove) && !inCheck)
|
||||||
&& !pos.capture_or_promotion(bestMove)
|
update_stats(pos, ss, bestMove, depth, quietsSearched, quietCount - 1);
|
||||||
&& !inCheck)
|
|
||||||
{
|
|
||||||
if (ss->killers[0] != bestMove)
|
|
||||||
{
|
|
||||||
ss->killers[1] = ss->killers[0];
|
|
||||||
ss->killers[0] = bestMove;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increase history value of the cut-off move and decrease all the other
|
|
||||||
// played non-capture moves.
|
|
||||||
Value bonus = Value(int(depth) * int(depth));
|
|
||||||
History.update(pos.moved_piece(bestMove), to_sq(bestMove), bonus);
|
|
||||||
for (int i = 0; i < quietCount - 1; ++i)
|
|
||||||
{
|
|
||||||
Move m = quietsSearched[i];
|
|
||||||
History.update(pos.moved_piece(m), to_sq(m), -bonus);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_ok((ss-1)->currentMove))
|
|
||||||
Countermoves.update(pos.piece_on(prevMoveSq), prevMoveSq, bestMove);
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
|
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
|
||||||
|
|
||||||
|
@ -1318,6 +1281,35 @@ moves_loop: // When in check and at SpNode search starts from here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// update_stats() updates killers, history and countermoves stats after a fail-high
|
||||||
|
// of a quiet move.
|
||||||
|
|
||||||
|
void update_stats(Position& pos, Stack* ss, Move move, Depth depth, Move* quiets, int quietsCnt) {
|
||||||
|
|
||||||
|
if (ss->killers[0] != move)
|
||||||
|
{
|
||||||
|
ss->killers[1] = ss->killers[0];
|
||||||
|
ss->killers[0] = move;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increase history value of the cut-off move and decrease all the other
|
||||||
|
// played quiet moves.
|
||||||
|
Value bonus = Value(int(depth) * int(depth));
|
||||||
|
History.update(pos.moved_piece(move), to_sq(move), bonus);
|
||||||
|
for (int i = 0; i < quietsCnt; ++i)
|
||||||
|
{
|
||||||
|
Move m = quiets[i];
|
||||||
|
History.update(pos.moved_piece(m), to_sq(m), -bonus);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_ok((ss-1)->currentMove))
|
||||||
|
{
|
||||||
|
Square prevMoveSq = to_sq((ss-1)->currentMove);
|
||||||
|
Countermoves.update(pos.piece_on(prevMoveSq), prevMoveSq, move);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// When playing with a strength handicap, choose best move among the MultiPV
|
// When playing with a strength handicap, choose best move among the MultiPV
|
||||||
// set using a statistical rule dependent on 'level'. Idea by Heinz van Saanen.
|
// set using a statistical rule dependent on 'level'. Idea by Heinz van Saanen.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue