mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 17:19:36 +00:00
Simplify stats update
Simplify code by moving countermove and follow-up move history update into procedure. No functional change.
This commit is contained in:
parent
3e739f883f
commit
9bd856e28e
1 changed files with 20 additions and 38 deletions
|
@ -168,8 +168,8 @@ namespace {
|
||||||
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_pv(Move* pv, Move move, Move* childPv);
|
void update_pv(Move* pv, Move move, Move* childPv);
|
||||||
|
void update_cm_stats(Stack* ss, Piece pc, Square s, Value bonus);
|
||||||
void update_stats(const Position& pos, Stack* ss, Move move, Move* quiets, int quietsCnt, Value bonus);
|
void update_stats(const Position& pos, Stack* ss, Move move, Move* quiets, int quietsCnt, Value bonus);
|
||||||
void update_opponent_stats(const Position& pos, Stack* ss, Value bonus);
|
|
||||||
void check_time();
|
void check_time();
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -651,7 +651,8 @@ namespace {
|
||||||
if ((ss-1)->moveCount == 1 && !pos.captured_piece_type())
|
if ((ss-1)->moveCount == 1 && !pos.captured_piece_type())
|
||||||
{
|
{
|
||||||
Value penalty = Value(d * d + 4 * d + 1);
|
Value penalty = Value(d * d + 4 * d + 1);
|
||||||
update_opponent_stats(pos, ss, -penalty);
|
Square prevSq = to_sq((ss-1)->currentMove);
|
||||||
|
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, -penalty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ttValue;
|
return ttValue;
|
||||||
|
@ -1141,7 +1142,8 @@ moves_loop: // When in check search starts from here
|
||||||
if ((ss-1)->moveCount == 1 && !pos.captured_piece_type())
|
if ((ss-1)->moveCount == 1 && !pos.captured_piece_type())
|
||||||
{
|
{
|
||||||
Value penalty = Value(d * d + 4 * d + 1);
|
Value penalty = Value(d * d + 4 * d + 1);
|
||||||
update_opponent_stats(pos, ss, -penalty);
|
Square prevSq = to_sq((ss-1)->currentMove);
|
||||||
|
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, -penalty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Bonus for prior countermove that caused the fail low
|
// Bonus for prior countermove that caused the fail low
|
||||||
|
@ -1151,7 +1153,8 @@ moves_loop: // When in check search starts from here
|
||||||
{
|
{
|
||||||
int d = depth / ONE_PLY;
|
int d = depth / ONE_PLY;
|
||||||
Value bonus = Value(d * d + 2 * d - 2);
|
Value bonus = Value(d * d + 2 * d - 2);
|
||||||
update_opponent_stats(pos, ss, bonus);
|
Square prevSq = to_sq((ss-1)->currentMove);
|
||||||
|
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, bonus);
|
||||||
}
|
}
|
||||||
|
|
||||||
tte->save(posKey, value_to_tt(bestValue, ss->ply),
|
tte->save(posKey, value_to_tt(bestValue, ss->ply),
|
||||||
|
@ -1411,25 +1414,22 @@ moves_loop: // When in check search starts from here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// update_opponent_stats() updates countermoves for prior opponent move, i.e.
|
// update_cm_stats() updates countermove and follow-up move history
|
||||||
// (ss-1)->currentMove. Called for both capture and non-capture moves.
|
|
||||||
|
|
||||||
void update_opponent_stats(const Position& pos, Stack* ss, Value bonus) {
|
void update_cm_stats(Stack* ss, Piece pc, Square s, Value bonus) {
|
||||||
|
|
||||||
Square prevSq = to_sq((ss-1)->currentMove);
|
CounterMoveStats* cmh = (ss-1)->counterMoves;
|
||||||
|
CounterMoveStats* fmh1 = (ss-2)->counterMoves;
|
||||||
CounterMoveStats* cmh = (ss-2)->counterMoves;
|
CounterMoveStats* fmh2 = (ss-4)->counterMoves;
|
||||||
CounterMoveStats* fmh1 = (ss-3)->counterMoves;
|
|
||||||
CounterMoveStats* fmh2 = (ss-5)->counterMoves;
|
|
||||||
|
|
||||||
if (cmh)
|
if (cmh)
|
||||||
cmh->update(pos.piece_on(prevSq), prevSq, bonus);
|
cmh->update(pc, s, bonus);
|
||||||
|
|
||||||
if (fmh1)
|
if (fmh1)
|
||||||
fmh1->update(pos.piece_on(prevSq), prevSq, bonus);
|
fmh1->update(pc, s, bonus);
|
||||||
|
|
||||||
if (fmh2)
|
if (fmh2)
|
||||||
fmh2->update(pos.piece_on(prevSq), prevSq, bonus);
|
fmh2->update(pc, s, bonus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1445,42 +1445,24 @@ moves_loop: // When in check search starts from here
|
||||||
ss->killers[0] = move;
|
ss->killers[0] = move;
|
||||||
}
|
}
|
||||||
|
|
||||||
CounterMoveStats* cmh = (ss-1)->counterMoves;
|
|
||||||
CounterMoveStats* fmh1 = (ss-2)->counterMoves;
|
|
||||||
CounterMoveStats* fmh2 = (ss-4)->counterMoves;
|
|
||||||
|
|
||||||
Color c = pos.side_to_move();
|
Color c = pos.side_to_move();
|
||||||
Thread* thisThread = pos.this_thread();
|
Thread* thisThread = pos.this_thread();
|
||||||
thisThread->history.update(pos.moved_piece(move), to_sq(move), bonus);
|
|
||||||
thisThread->fromTo.update(c, move, bonus);
|
thisThread->fromTo.update(c, move, bonus);
|
||||||
|
thisThread->history.update(pos.moved_piece(move), to_sq(move), bonus);
|
||||||
|
update_cm_stats(ss, pos.moved_piece(move), to_sq(move), bonus);
|
||||||
|
|
||||||
if (cmh)
|
if ((ss-1)->counterMoves)
|
||||||
{
|
{
|
||||||
Square prevSq = to_sq((ss-1)->currentMove);
|
Square prevSq = to_sq((ss-1)->currentMove);
|
||||||
thisThread->counterMoves.update(pos.piece_on(prevSq), prevSq, move);
|
thisThread->counterMoves.update(pos.piece_on(prevSq), prevSq, move);
|
||||||
cmh->update(pos.moved_piece(move), to_sq(move), bonus);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fmh1)
|
|
||||||
fmh1->update(pos.moved_piece(move), to_sq(move), bonus);
|
|
||||||
|
|
||||||
if (fmh2)
|
|
||||||
fmh2->update(pos.moved_piece(move), to_sq(move), bonus);
|
|
||||||
|
|
||||||
// Decrease all the other played quiet moves
|
// Decrease all the other played quiet moves
|
||||||
for (int i = 0; i < quietsCnt; ++i)
|
for (int i = 0; i < quietsCnt; ++i)
|
||||||
{
|
{
|
||||||
thisThread->history.update(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
|
|
||||||
thisThread->fromTo.update(c, quiets[i], -bonus);
|
thisThread->fromTo.update(c, quiets[i], -bonus);
|
||||||
|
thisThread->history.update(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
|
||||||
if (cmh)
|
update_cm_stats(ss, pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
|
||||||
cmh->update(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
|
|
||||||
|
|
||||||
if (fmh1)
|
|
||||||
fmh1->update(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
|
|
||||||
|
|
||||||
if (fmh2)
|
|
||||||
fmh2->update(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue