1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00

Assorted trivial cleanups (July 2019)

No functional change
This commit is contained in:
Alain SAVARD 2019-08-14 22:15:41 +02:00 committed by Stéphane Nicolet
parent 66a3c2968b
commit 7efc39d683
7 changed files with 31 additions and 27 deletions

View file

@ -11,6 +11,7 @@ Ajith Chandy Jose (ajithcj)
Alain Savard (Rocky640) Alain Savard (Rocky640)
alayan-stk-2 alayan-stk-2
Alexander Kure Alexander Kure
Alexander Pagel (Lolligerhans)
Ali AlZhrani (Cooffe) Ali AlZhrani (Cooffe)
Andrew Grant (AndyGrant) Andrew Grant (AndyGrant)
Andrey Neporada (nepal) Andrey Neporada (nepal)
@ -82,6 +83,7 @@ Lub van den Berg (ElbertoOne)
Luca Brivio (lucabrivio) Luca Brivio (lucabrivio)
Lucas Braesch (lucasart) Lucas Braesch (lucasart)
Lyudmil Antonov (lantonov) Lyudmil Antonov (lantonov)
Maciej Żenczykowski (zenczykowski)
Matthew Lai (matthewlai) Matthew Lai (matthewlai)
Matthew Sullivan Matthew Sullivan
Mark Tenzer (31m059) Mark Tenzer (31m059)

View file

@ -377,6 +377,8 @@ inline Square pop_lsb(Bitboard* b) {
/// frontmost_sq() returns the most advanced square for the given color /// frontmost_sq() returns the most advanced square for the given color
inline Square frontmost_sq(Color c, Bitboard b) { return c == WHITE ? msb(b) : lsb(b); } inline Square frontmost_sq(Color c, Bitboard b) {
return c == WHITE ? msb(b) : lsb(b);
}
#endif // #ifndef BITBOARD_H_INCLUDED #endif // #ifndef BITBOARD_H_INCLUDED

View file

@ -505,9 +505,6 @@ namespace {
// Enemies not strongly protected and under our attack // Enemies not strongly protected and under our attack
weak = pos.pieces(Them) & ~stronglyProtected & attackedBy[Us][ALL_PIECES]; weak = pos.pieces(Them) & ~stronglyProtected & attackedBy[Us][ALL_PIECES];
// Safe or protected squares
safe = ~attackedBy[Them][ALL_PIECES] | attackedBy[Us][ALL_PIECES];
// Bonus according to the kind of attacking pieces // Bonus according to the kind of attacking pieces
if (defended | weak) if (defended | weak)
{ {
@ -544,6 +541,14 @@ namespace {
score += RestrictedPiece * popcount(b); score += RestrictedPiece * popcount(b);
// Protected or unattacked squares
safe = ~attackedBy[Them][ALL_PIECES] | attackedBy[Us][ALL_PIECES];
// Bonus for attacking enemy pieces with our relatively safe pawns
b = pos.pieces(Us, PAWN) & safe;
b = pawn_attacks_bb<Us>(b) & nonPawnEnemies;
score += ThreatBySafePawn * popcount(b);
// Find squares where our pawns can push on the next move // Find squares where our pawns can push on the next move
b = shift<Up>(pos.pieces(Us, PAWN)) & ~pos.pieces(); b = shift<Up>(pos.pieces(Us, PAWN)) & ~pos.pieces();
b |= shift<Up>(b & TRank3BB) & ~pos.pieces(); b |= shift<Up>(b & TRank3BB) & ~pos.pieces();
@ -555,12 +560,6 @@ namespace {
b = pawn_attacks_bb<Us>(b) & nonPawnEnemies; b = pawn_attacks_bb<Us>(b) & nonPawnEnemies;
score += ThreatByPawnPush * popcount(b); score += ThreatByPawnPush * popcount(b);
// Our safe or protected pawns
b = pos.pieces(Us, PAWN) & safe;
b = pawn_attacks_bb<Us>(b) & nonPawnEnemies;
score += ThreatBySafePawn * popcount(b);
// Bonus for threats on the next moves against enemy queen // Bonus for threats on the next moves against enemy queen
if (pos.count<QUEEN>(Them) == 1) if (pos.count<QUEEN>(Them) == 1)
{ {

View file

@ -52,8 +52,8 @@ namespace {
// Danger of enemy pawns moving toward our king by [distance from edge][rank]. // Danger of enemy pawns moving toward our king by [distance from edge][rank].
// RANK_1 = 0 is used for files where the enemy has no pawn, or their pawn // RANK_1 = 0 is used for files where the enemy has no pawn, or their pawn
// is behind our king. // is behind our king. Note that UnblockedStorm[0][1-2] accommodate opponent pawn
// [0][1-2] accommodate opponent pawn on edge (likely blocked by our king) // on edge, likely blocked by our king.
constexpr Value UnblockedStorm[int(FILE_NB) / 2][RANK_NB] = { constexpr Value UnblockedStorm[int(FILE_NB) / 2][RANK_NB] = {
{ V( 89), V(-285), V(-185), V(93), V(57), V( 45), V( 51) }, { V( 89), V(-285), V(-185), V(93), V(57), V( 45), V( 51) },
{ V( 44), V( -18), V( 123), V(46), V(39), V( -7), V( 23) }, { V( 44), V( -18), V( 123), V(46), V(39), V( -7), V( 23) },
@ -196,10 +196,10 @@ void Entry::evaluate_shelter(const Position& pos, Square ksq, Score& shelter) {
for (File f = File(center - 1); f <= File(center + 1); ++f) for (File f = File(center - 1); f <= File(center + 1); ++f)
{ {
b = ourPawns & file_bb(f); b = ourPawns & file_bb(f);
Rank ourRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1; int ourRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
b = theirPawns & file_bb(f); b = theirPawns & file_bb(f);
Rank theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1; int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
int d = std::min(f, ~f); int d = std::min(f, ~f);
bonus += make_score(ShelterStrength[d][ourRank], 0); bonus += make_score(ShelterStrength[d][ourRank], 0);
@ -234,7 +234,7 @@ Score Entry::do_king_safety(const Position& pos) {
else while (pawns) else while (pawns)
minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(&pawns))); minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(&pawns)));
Score shelter = make_score(-VALUE_INFINITE, VALUE_ZERO); Score shelter = make_score(-VALUE_INFINITE, 0);
evaluate_shelter<Us>(pos, ksq, shelter); evaluate_shelter<Us>(pos, ksq, shelter);
// If we can castle use the bonus after the castling if it is bigger // If we can castle use the bonus after the castling if it is bigger
@ -244,7 +244,7 @@ Score Entry::do_king_safety(const Position& pos) {
if (pos.can_castle(Us | QUEEN_SIDE)) if (pos.can_castle(Us | QUEEN_SIDE))
evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1), shelter); evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1), shelter);
return shelter - make_score(VALUE_ZERO, 16 * minPawnDist); return shelter - make_score(0, 16 * minPawnDist);
} }
// Explicit template instantiation // Explicit template instantiation

View file

@ -882,7 +882,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
if (end >= 4) if (end >= 4)
{ {
StateInfo* stp = st->previous->previous; StateInfo* stp = st->previous->previous;
for (int i=4; i <= end; i += 2) for (int i = 4; i <= end; i += 2)
{ {
stp = stp->previous->previous; stp = stp->previous->previous;
if (stp->key == st->key) if (stp->key == st->key)

View file

@ -102,15 +102,16 @@ namespace {
Move best = MOVE_NONE; Move best = MOVE_NONE;
}; };
// Breadcrumbs are used to mark nodes as being searched by a given thread. // Breadcrumbs are used to mark nodes as being searched by a given thread
struct Breadcrumb { struct Breadcrumb {
std::atomic<Thread*> thread; std::atomic<Thread*> thread;
std::atomic<Key> key; std::atomic<Key> key;
}; };
std::array<Breadcrumb, 1024> breadcrumbs; std::array<Breadcrumb, 1024> breadcrumbs;
// ThreadHolding keeps track of which thread left breadcrumbs at the given node for potential reductions. // ThreadHolding structure keeps track of which thread left breadcrumbs at the given
// A free node will be marked upon entering the moves loop, and unmarked upon leaving that loop, by the ctor/dtor of this struct. // node for potential reductions. A free node will be marked upon entering the moves
// loop by the constructor, and unmarked upon leaving that loop by the destructor.
struct ThreadHolding { struct ThreadHolding {
explicit ThreadHolding(Thread* thisThread, Key posKey, int ply) { explicit ThreadHolding(Thread* thisThread, Key posKey, int ply) {
location = ply < 8 ? &breadcrumbs[posKey & (breadcrumbs.size() - 1)] : nullptr; location = ply < 8 ? &breadcrumbs[posKey & (breadcrumbs.size() - 1)] : nullptr;
@ -118,7 +119,7 @@ namespace {
owning = false; owning = false;
if (location) if (location)
{ {
// see if another already marked this location, if not, mark it ourselves. // See if another already marked this location, if not, mark it ourselves
Thread* tmp = (*location).thread.load(std::memory_order_relaxed); Thread* tmp = (*location).thread.load(std::memory_order_relaxed);
if (tmp == nullptr) if (tmp == nullptr)
{ {
@ -133,7 +134,7 @@ namespace {
} }
~ThreadHolding() { ~ThreadHolding() {
if (owning) // free the marked location. if (owning) // Free the marked location
(*location).thread.store(nullptr, std::memory_order_relaxed); (*location).thread.store(nullptr, std::memory_order_relaxed);
} }
@ -647,9 +648,9 @@ namespace {
// statScore of the previous grandchild. This influences the reduction rules in // statScore of the previous grandchild. This influences the reduction rules in
// LMR which are based on the statScore of parent position. // LMR which are based on the statScore of parent position.
if (rootNode) if (rootNode)
(ss + 4)->statScore = 0; (ss+4)->statScore = 0;
else else
(ss + 2)->statScore = 0; (ss+2)->statScore = 0;
// Step 4. Transposition table lookup. We don't want the score of a partial // Step 4. Transposition table lookup. We don't want the score of a partial
// search to overwrite a previous full search TT value, so we use a different // search to overwrite a previous full search TT value, so we use a different
@ -680,7 +681,7 @@ namespace {
// Extra penalty for early quiet moves of the previous ply // Extra penalty for early quiet moves of the previous ply
if ((ss-1)->moveCount <= 2 && !pos.captured_piece()) if ((ss-1)->moveCount <= 2 && !pos.captured_piece())
update_continuation_histories(ss-1, pos.piece_on(prevSq), prevSq, -stat_bonus(depth + ONE_PLY)); update_continuation_histories(ss-1, pos.piece_on(prevSq), prevSq, -stat_bonus(depth + ONE_PLY));
} }
// Penalty for a quiet ttMove that fails low // Penalty for a quiet ttMove that fails low
else if (!pos.capture_or_promotion(ttMove)) else if (!pos.capture_or_promotion(ttMove))
@ -908,7 +909,7 @@ moves_loop: // When in check, search starts from here
moveCountPruning = false; moveCountPruning = false;
ttCapture = ttMove && pos.capture_or_promotion(ttMove); ttCapture = ttMove && pos.capture_or_promotion(ttMove);
// Mark this node as being searched. // Mark this node as being searched
ThreadHolding th(thisThread, posKey, ss->ply); ThreadHolding th(thisThread, posKey, ss->ply);
// Step 12. Loop through all pseudo-legal moves until no moves remain // Step 12. Loop through all pseudo-legal moves until no moves remain

View file

@ -367,7 +367,7 @@ TBTable<WDL>::TBTable(const std::string& code) : TBTable() {
hasPawns = pos.pieces(PAWN); hasPawns = pos.pieces(PAWN);
hasUniquePieces = false; hasUniquePieces = false;
for (Color c : {WHITE, BLACK}) for (Color c : { WHITE, BLACK })
for (PieceType pt = PAWN; pt < KING; ++pt) for (PieceType pt = PAWN; pt < KING; ++pt)
if (popcount(pos.pieces(c, pt)) == 1) if (popcount(pos.pieces(c, pt)) == 1)
hasUniquePieces = true; hasUniquePieces = true;