Minor code improvements

- Remove / add empty lines
- fix the `ttcapture` comment
- remove the `bonus` variable for `ttMoveHistory`
- remove unnecessary parentheses / brackets
- refactor the movepick good quiet stage
- rename `endMoves` to `endCur`, as the previous name suggests that it points to the end of all generated moves, which it does not.

closes https://github.com/official-stockfish/Stockfish/pull/6089

No functional change.

Co-Authored-By: xu-shawn <50402888+xu-shawn@users.noreply.github.com>
This commit is contained in:
Nonlinear2
2025-05-25 20:59:27 +02:00
committed by Joost VandeVondele
co-authored by xu-shawn
parent f58d923fe0
commit b1b5893a8e
3 changed files with 25 additions and 27 deletions
+18 -15
View File
@@ -173,7 +173,7 @@ void MovePicker::score() {
if (KNIGHT <= pt && pt <= QUEEN)
{
static constexpr int bonus[QUEEN + 1] = {0, 0, 144, 144, 256, 517};
int v = (threatByLesser[pt] & to ? -95 : 100 * bool(threatByLesser[pt] & from));
int v = threatByLesser[pt] & to ? -95 : 100 * bool(threatByLesser[pt] & from);
m.value += bonus[pt] * v;
}
@@ -200,7 +200,7 @@ void MovePicker::score() {
template<typename Pred>
Move MovePicker::select(Pred filter) {
for (; cur < endMoves; ++cur)
for (; cur < endCur; ++cur)
if (*cur != ttMove && filter())
return *cur++;
@@ -227,10 +227,10 @@ top:
case PROBCUT_INIT :
case QCAPTURE_INIT :
cur = endBadCaptures = moves;
endMoves = generate<CAPTURES>(pos, cur);
endCur = generate<CAPTURES>(pos, cur);
score<CAPTURES>();
partial_insertion_sort(cur, endMoves, std::numeric_limits<int>::min());
partial_insertion_sort(cur, endCur, std::numeric_limits<int>::min());
++stage;
goto top;
@@ -250,10 +250,10 @@ top:
if (!skipQuiets)
{
cur = endBadQuiets = endBadCaptures;
endMoves = generate<QUIETS>(pos, cur);
endCur = generate<QUIETS>(pos, cur);
score<QUIETS>();
partial_insertion_sort(cur, endMoves, -3560 * depth);
partial_insertion_sort(cur, endCur, -3560 * depth);
}
++stage;
@@ -261,13 +261,16 @@ top:
case GOOD_QUIET :
if (!skipQuiets && select([&]() {
return cur->value > -14000 ? true : (*endBadQuiets++ = *cur, false);
if (cur->value > -14000)
return true;
*endBadQuiets++ = *cur;
return false;
}))
return *(cur - 1);
// Prepare the pointers to loop over the bad captures
cur = moves;
endMoves = endBadCaptures;
cur = moves;
endCur = endBadCaptures;
++stage;
[[fallthrough]];
@@ -277,8 +280,8 @@ top:
return *(cur - 1);
// Prepare the pointers to loop over the bad quiets
cur = endBadCaptures;
endMoves = endBadQuiets;
cur = endBadCaptures;
endCur = endBadQuiets;
++stage;
[[fallthrough]];
@@ -290,11 +293,11 @@ top:
return Move::none();
case EVASION_INIT :
cur = moves;
endMoves = generate<EVASIONS>(pos, cur);
cur = moves;
endCur = generate<EVASIONS>(pos, cur);
score<EVASIONS>();
partial_insertion_sort(cur, endMoves, std::numeric_limits<int>::min());
partial_insertion_sort(cur, endCur, std::numeric_limits<int>::min());
++stage;
[[fallthrough]];
@@ -317,7 +320,7 @@ bool MovePicker::can_move_king_or_pawn() {
// SEE negative captures shouldn't be returned in GOOD_CAPTURE stage
assert(stage > GOOD_CAPTURE && stage != EVASION_INIT);
for (ExtMove* m = moves; m < endMoves; ++m)
for (ExtMove* m = moves; m < endCur; ++m)
{
PieceType movedPieceType = type_of(pos.moved_piece(*m));
if ((movedPieceType == PAWN || movedPieceType == KING) && pos.legal(*m))