From fbb53524efd94c4b227c72c725c628a4aa5f9f72 Mon Sep 17 00:00:00 2001 From: hxim Date: Mon, 8 Dec 2014 07:53:33 +0800 Subject: [PATCH] Rename some variables for more clarity. No functional change. Resolves #131 --- src/bitboard.cpp | 28 ++++++------ src/bitboard.h | 44 +++++++++---------- src/endgame.cpp | 4 +- src/misc.h | 2 +- src/movegen.cpp | 112 +++++++++++++++++++++++------------------------ src/movegen.h | 10 ++--- src/movepick.cpp | 2 +- src/pawns.cpp | 8 ++-- src/pawns.h | 2 +- src/position.cpp | 42 +++++++++--------- src/position.h | 10 ++--- src/search.cpp | 40 ++++++++--------- src/search.h | 4 +- src/thread.cpp | 14 +++--- 14 files changed, 161 insertions(+), 161 deletions(-) diff --git a/src/bitboard.cpp b/src/bitboard.cpp index 5a4c8b6b..2a7ef100 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -24,15 +24,15 @@ #include "bitcount.h" #include "rkiss.h" -Bitboard RMasks[SQUARE_NB]; -Bitboard RMagics[SQUARE_NB]; -Bitboard* RAttacks[SQUARE_NB]; -unsigned RShifts[SQUARE_NB]; +Bitboard RookMasks[SQUARE_NB]; +Bitboard RookMagics[SQUARE_NB]; +Bitboard* RookAttacks[SQUARE_NB]; +unsigned RookShifts[SQUARE_NB]; -Bitboard BMasks[SQUARE_NB]; -Bitboard BMagics[SQUARE_NB]; -Bitboard* BAttacks[SQUARE_NB]; -unsigned BShifts[SQUARE_NB]; +Bitboard BishopMasks[SQUARE_NB]; +Bitboard BishopMagics[SQUARE_NB]; +Bitboard* BishopAttacks[SQUARE_NB]; +unsigned BishopShifts[SQUARE_NB]; Bitboard SquareBB[SQUARE_NB]; Bitboard FileBB[FILE_NB]; @@ -58,8 +58,8 @@ namespace { int MS1BTable[256]; Square BSFTable[SQUARE_NB]; - Bitboard RTable[0x19000]; // Storage space for rook attacks - Bitboard BTable[0x1480]; // Storage space for bishop attacks + Bitboard RookTable[0x19000]; // Storage space for rook attacks + Bitboard BishopTable[0x1480]; // Storage space for bishop attacks typedef unsigned (Fn)(Square, Bitboard); @@ -195,11 +195,11 @@ void Bitboards::init() { StepAttacksBB[make_piece(c, pt)][s] |= to; } - Square RDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W }; - Square BDeltas[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW }; + Square RookDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W }; + Square BishopDeltas[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW }; - init_magics(RTable, RAttacks, RMagics, RMasks, RShifts, RDeltas, magic_index); - init_magics(BTable, BAttacks, BMagics, BMasks, BShifts, BDeltas, magic_index); + init_magics(RookTable, RookAttacks, RookMagics, RookMasks, RookShifts, RookDeltas, magic_index); + init_magics(BishopTable, BishopAttacks, BishopMagics, BishopMasks, BishopShifts, BishopDeltas, magic_index); for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1) { diff --git a/src/bitboard.h b/src/bitboard.h index 7c4a55f0..f361658a 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -57,15 +57,15 @@ const Bitboard Rank6BB = Rank1BB << (8 * 5); const Bitboard Rank7BB = Rank1BB << (8 * 6); const Bitboard Rank8BB = Rank1BB << (8 * 7); -extern Bitboard RMasks[SQUARE_NB]; -extern Bitboard RMagics[SQUARE_NB]; -extern Bitboard* RAttacks[SQUARE_NB]; -extern unsigned RShifts[SQUARE_NB]; +extern Bitboard RookMasks[SQUARE_NB]; +extern Bitboard RookMagics[SQUARE_NB]; +extern Bitboard* RookAttacks[SQUARE_NB]; +extern unsigned RookShifts[SQUARE_NB]; -extern Bitboard BMasks[SQUARE_NB]; -extern Bitboard BMagics[SQUARE_NB]; -extern Bitboard* BAttacks[SQUARE_NB]; -extern unsigned BShifts[SQUARE_NB]; +extern Bitboard BishopMasks[SQUARE_NB]; +extern Bitboard BishopMagics[SQUARE_NB]; +extern Bitboard* BishopAttacks[SQUARE_NB]; +extern unsigned BishopShifts[SQUARE_NB]; extern Bitboard SquareBB[SQUARE_NB]; extern Bitboard FileBB[FILE_NB]; @@ -230,35 +230,35 @@ inline bool aligned(Square s1, Square s2, Square s3) { /// a square and a bitboard of occupied squares as input, and returns a bitboard /// representing all squares attacked by Pt (bishop or rook) on the given square. template -FORCE_INLINE unsigned magic_index(Square s, Bitboard occ) { +FORCE_INLINE unsigned magic_index(Square s, Bitboard occupied) { - Bitboard* const Masks = Pt == ROOK ? RMasks : BMasks; - Bitboard* const Magics = Pt == ROOK ? RMagics : BMagics; - unsigned* const Shifts = Pt == ROOK ? RShifts : BShifts; + Bitboard* const Masks = Pt == ROOK ? RookMasks : BishopMasks; + Bitboard* const Magics = Pt == ROOK ? RookMagics : BishopMagics; + unsigned* const Shifts = Pt == ROOK ? RookShifts : BishopShifts; if (HasPext) - return unsigned(_pext_u64(occ, Masks[s])); + return unsigned(_pext_u64(occupied, Masks[s])); if (Is64Bit) - return unsigned(((occ & Masks[s]) * Magics[s]) >> Shifts[s]); + return unsigned(((occupied & Masks[s]) * Magics[s]) >> Shifts[s]); - unsigned lo = unsigned(occ) & unsigned(Masks[s]); - unsigned hi = unsigned(occ >> 32) & unsigned(Masks[s] >> 32); + unsigned lo = unsigned(occupied) & unsigned(Masks[s]); + unsigned hi = unsigned(occupied >> 32) & unsigned(Masks[s] >> 32); return (lo * unsigned(Magics[s]) ^ hi * unsigned(Magics[s] >> 32)) >> Shifts[s]; } template -inline Bitboard attacks_bb(Square s, Bitboard occ) { - return (Pt == ROOK ? RAttacks : BAttacks)[s][magic_index(s, occ)]; +inline Bitboard attacks_bb(Square s, Bitboard occupied) { + return (Pt == ROOK ? RookAttacks : BishopAttacks)[s][magic_index(s, occupied)]; } -inline Bitboard attacks_bb(Piece pc, Square s, Bitboard occ) { +inline Bitboard attacks_bb(Piece pc, Square s, Bitboard occupied) { switch (type_of(pc)) { - case BISHOP: return attacks_bb(s, occ); - case ROOK : return attacks_bb(s, occ); - case QUEEN : return attacks_bb(s, occ) | attacks_bb(s, occ); + case BISHOP: return attacks_bb(s, occupied); + case ROOK : return attacks_bb(s, occupied); + case QUEEN : return attacks_bb(s, occupied) | attacks_bb(s, occupied); default : return StepAttacksBB[pc][s]; } } diff --git a/src/endgame.cpp b/src/endgame.cpp index f683edc1..9cc0c372 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -60,8 +60,8 @@ namespace { const int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 }; #ifndef NDEBUG - bool verify_material(const Position& pos, Color c, Value npm, int num_pawns) { - return pos.non_pawn_material(c) == npm && pos.count(c) == num_pawns; + bool verify_material(const Position& pos, Color c, Value npm, int pawnsCnt) { + return pos.non_pawn_material(c) == npm && pos.count(c) == pawnsCnt; } #endif diff --git a/src/misc.h b/src/misc.h index 34ef0325..420347f4 100644 --- a/src/misc.h +++ b/src/misc.h @@ -46,7 +46,7 @@ namespace Time { template struct HashTable { HashTable() : table(Size, Entry()) {} - Entry* operator[](Key k) { return &table[(uint32_t)k & (Size - 1)]; } + Entry* operator[](Key key) { return &table[(uint32_t)key & (Size - 1)]; } private: std::vector table; diff --git a/src/movegen.cpp b/src/movegen.cpp index dab830ba..98c5419a 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -25,12 +25,12 @@ namespace { template - ExtMove* generate_castling(const Position& pos, ExtMove* mlist, Color us, const CheckInfo* ci) { + ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us, const CheckInfo* ci) { static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO); if (pos.castling_impeded(Cr) || !pos.can_castle(Cr)) - return mlist; + return moveList; // After castling, the rook and king final positions are the same in Chess960 // as they would be in standard chess. @@ -46,27 +46,27 @@ namespace { for (Square s = kto; s != kfrom; s += K) if (pos.attackers_to(s) & enemies) - return mlist; + return moveList; // Because we generate only legal castling moves we need to verify that // when moving the castling rook we do not discover some hidden checker. // For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1. if (Chess960 && (attacks_bb(kto, pos.pieces() ^ rfrom) & pos.pieces(~us, ROOK, QUEEN))) - return mlist; + return moveList; Move m = make(kfrom, rfrom); if (Checks && !pos.gives_check(m, *ci)) - return mlist; + return moveList; - (mlist++)->move = m; + (moveList++)->move = m; - return mlist; + return moveList; } template - inline ExtMove* generate_promotions(ExtMove* mlist, Bitboard pawnsOn7, + inline ExtMove* generate_promotions(ExtMove* moveList, Bitboard pawnsOn7, Bitboard target, const CheckInfo* ci) { Bitboard b = shift_bb(pawnsOn7) & target; @@ -76,29 +76,29 @@ namespace { Square to = pop_lsb(&b); if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS) - (mlist++)->move = make(to - Delta, to, QUEEN); + (moveList++)->move = make(to - Delta, to, QUEEN); if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS) { - (mlist++)->move = make(to - Delta, to, ROOK); - (mlist++)->move = make(to - Delta, to, BISHOP); - (mlist++)->move = make(to - Delta, to, KNIGHT); + (moveList++)->move = make(to - Delta, to, ROOK); + (moveList++)->move = make(to - Delta, to, BISHOP); + (moveList++)->move = make(to - Delta, to, KNIGHT); } // Knight promotion is the only promotion that can give a direct check // that's not already included in the queen promotion. if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ci->ksq)) - (mlist++)->move = make(to - Delta, to, KNIGHT); + (moveList++)->move = make(to - Delta, to, KNIGHT); else (void)ci; // Silence a warning under MSVC } - return mlist; + return moveList; } template - ExtMove* generate_pawn_moves(const Position& pos, ExtMove* mlist, + ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target, const CheckInfo* ci) { // Compute our parametrized parameters at compile time, named according to @@ -155,13 +155,13 @@ namespace { while (b1) { Square to = pop_lsb(&b1); - (mlist++)->move = make_move(to - Up, to); + (moveList++)->move = make_move(to - Up, to); } while (b2) { Square to = pop_lsb(&b2); - (mlist++)->move = make_move(to - Up - Up, to); + (moveList++)->move = make_move(to - Up - Up, to); } } @@ -174,9 +174,9 @@ namespace { if (Type == EVASIONS) emptySquares &= target; - mlist = generate_promotions(mlist, pawnsOn7, enemies, ci); - mlist = generate_promotions(mlist, pawnsOn7, enemies, ci); - mlist = generate_promotions(mlist, pawnsOn7, emptySquares, ci); + moveList = generate_promotions(moveList, pawnsOn7, enemies, ci); + moveList = generate_promotions(moveList, pawnsOn7, enemies, ci); + moveList = generate_promotions(moveList, pawnsOn7, emptySquares, ci); } // Standard and en-passant captures @@ -188,13 +188,13 @@ namespace { while (b1) { Square to = pop_lsb(&b1); - (mlist++)->move = make_move(to - Right, to); + (moveList++)->move = make_move(to - Right, to); } while (b2) { Square to = pop_lsb(&b2); - (mlist++)->move = make_move(to - Left, to); + (moveList++)->move = make_move(to - Left, to); } if (pos.ep_square() != SQ_NONE) @@ -205,23 +205,23 @@ namespace { // is the double pushed pawn and so is in the target. Otherwise this // is a discovery check and we are forced to do otherwise. if (Type == EVASIONS && !(target & (pos.ep_square() - Up))) - return mlist; + return moveList; b1 = pawnsNotOn7 & pos.attacks_from(pos.ep_square(), Them); assert(b1); while (b1) - (mlist++)->move = make(pop_lsb(&b1), pos.ep_square()); + (moveList++)->move = make(pop_lsb(&b1), pos.ep_square()); } } - return mlist; + return moveList; } template FORCE_INLINE - ExtMove* generate_moves(const Position& pos, ExtMove* mlist, Color us, + ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us, Bitboard target, const CheckInfo* ci) { assert(Pt != KING && Pt != PAWN); @@ -246,48 +246,48 @@ namespace { b &= ci->checkSq[Pt]; while (b) - (mlist++)->move = make_move(from, pop_lsb(&b)); + (moveList++)->move = make_move(from, pop_lsb(&b)); } - return mlist; + return moveList; } template FORCE_INLINE - ExtMove* generate_all(const Position& pos, ExtMove* mlist, Bitboard target, + ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target, const CheckInfo* ci = NULL) { const bool Checks = Type == QUIET_CHECKS; - mlist = generate_pawn_moves(pos, mlist, target, ci); - mlist = generate_moves(pos, mlist, Us, target, ci); - mlist = generate_moves(pos, mlist, Us, target, ci); - mlist = generate_moves< ROOK, Checks>(pos, mlist, Us, target, ci); - mlist = generate_moves< QUEEN, Checks>(pos, mlist, Us, target, ci); + moveList = generate_pawn_moves(pos, moveList, target, ci); + moveList = generate_moves(pos, moveList, Us, target, ci); + moveList = generate_moves(pos, moveList, Us, target, ci); + moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target, ci); + moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target, ci); if (Type != QUIET_CHECKS && Type != EVASIONS) { Square ksq = pos.king_square(Us); Bitboard b = pos.attacks_from(ksq) & target; while (b) - (mlist++)->move = make_move(ksq, pop_lsb(&b)); + (moveList++)->move = make_move(ksq, pop_lsb(&b)); } if (Type != CAPTURES && Type != EVASIONS && pos.can_castle(Us)) { if (pos.is_chess960()) { - mlist = generate_castling::right, Checks, true>(pos, mlist, Us, ci); - mlist = generate_castling::right, Checks, true>(pos, mlist, Us, ci); + moveList = generate_castling::right, Checks, true>(pos, moveList, Us, ci); + moveList = generate_castling::right, Checks, true>(pos, moveList, Us, ci); } else { - mlist = generate_castling::right, Checks, false>(pos, mlist, Us, ci); - mlist = generate_castling::right, Checks, false>(pos, mlist, Us, ci); + moveList = generate_castling::right, Checks, false>(pos, moveList, Us, ci); + moveList = generate_castling::right, Checks, false>(pos, moveList, Us, ci); } } - return mlist; + return moveList; } @@ -304,7 +304,7 @@ namespace { /// non-captures. Returns a pointer to the end of the move list. template -ExtMove* generate(const Position& pos, ExtMove* mlist) { +ExtMove* generate(const Position& pos, ExtMove* moveList) { assert(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS); assert(!pos.checkers()); @@ -315,8 +315,8 @@ ExtMove* generate(const Position& pos, ExtMove* mlist) { : Type == QUIETS ? ~pos.pieces() : Type == NON_EVASIONS ? ~pos.pieces(us) : 0; - return us == WHITE ? generate_all(pos, mlist, target) - : generate_all(pos, mlist, target); + return us == WHITE ? generate_all(pos, moveList, target) + : generate_all(pos, moveList, target); } // Explicit template instantiations @@ -328,7 +328,7 @@ template ExtMove* generate(const Position&, ExtMove*); /// generate generates all pseudo-legal non-captures and knight /// underpromotions that give check. Returns a pointer to the end of the move list. template<> -ExtMove* generate(const Position& pos, ExtMove* mlist) { +ExtMove* generate(const Position& pos, ExtMove* moveList) { assert(!pos.checkers()); @@ -350,18 +350,18 @@ ExtMove* generate(const Position& pos, ExtMove* mlist) { b &= ~PseudoAttacks[QUEEN][ci.ksq]; while (b) - (mlist++)->move = make_move(from, pop_lsb(&b)); + (moveList++)->move = make_move(from, pop_lsb(&b)); } - return us == WHITE ? generate_all(pos, mlist, ~pos.pieces(), &ci) - : generate_all(pos, mlist, ~pos.pieces(), &ci); + return us == WHITE ? generate_all(pos, moveList, ~pos.pieces(), &ci) + : generate_all(pos, moveList, ~pos.pieces(), &ci); } /// generate generates all pseudo-legal check evasions when the side /// to move is in check. Returns a pointer to the end of the move list. template<> -ExtMove* generate(const Position& pos, ExtMove* mlist) { +ExtMove* generate(const Position& pos, ExtMove* moveList) { assert(pos.checkers()); @@ -382,31 +382,31 @@ ExtMove* generate(const Position& pos, ExtMove* mlist) { // Generate evasions for king, capture and non capture moves Bitboard b = pos.attacks_from(ksq) & ~pos.pieces(us) & ~sliderAttacks; while (b) - (mlist++)->move = make_move(ksq, pop_lsb(&b)); + (moveList++)->move = make_move(ksq, pop_lsb(&b)); if (more_than_one(pos.checkers())) - return mlist; // Double check, only a king move can save the day + return moveList; // Double check, only a king move can save the day // Generate blocking evasions or captures of the checking piece Square checksq = lsb(pos.checkers()); Bitboard target = between_bb(checksq, ksq) | checksq; - return us == WHITE ? generate_all(pos, mlist, target) - : generate_all(pos, mlist, target); + return us == WHITE ? generate_all(pos, moveList, target) + : generate_all(pos, moveList, target); } /// generate generates all the legal moves in the given position template<> -ExtMove* generate(const Position& pos, ExtMove* mlist) { +ExtMove* generate(const Position& pos, ExtMove* moveList) { - ExtMove *end, *cur = mlist; + ExtMove *end, *cur = moveList; Bitboard pinned = pos.pinned_pieces(pos.side_to_move()); Square ksq = pos.king_square(pos.side_to_move()); - end = pos.checkers() ? generate(pos, mlist) - : generate(pos, mlist); + end = pos.checkers() ? generate(pos, moveList) + : generate(pos, moveList); while (cur != end) if ( (pinned || from_sq(cur->move) == ksq || type_of(cur->move) == ENPASSANT) && !pos.legal(cur->move, pinned)) diff --git a/src/movegen.h b/src/movegen.h index c18fa07c..fa697827 100644 --- a/src/movegen.h +++ b/src/movegen.h @@ -34,24 +34,24 @@ enum GenType { class Position; template -ExtMove* generate(const Position& pos, ExtMove* mlist); +ExtMove* generate(const Position& pos, ExtMove* moveList); /// The MoveList struct is a simple wrapper around generate(). It sometimes comes /// in handy to use this class instead of the low level generate() function. template struct MoveList { - explicit MoveList(const Position& pos) : cur(mlist), last(generate(pos, mlist)) { last->move = MOVE_NONE; } + explicit MoveList(const Position& pos) : cur(moveList), last(generate(pos, moveList)) { last->move = MOVE_NONE; } void operator++() { ++cur; } Move operator*() const { return cur->move; } - size_t size() const { return last - mlist; } + size_t size() const { return last - moveList; } bool contains(Move m) const { - for (const ExtMove* it(mlist); it != last; ++it) if (it->move == m) return true; + for (const ExtMove* it(moveList); it != last; ++it) if (it->move == m) return true; return false; } private: - ExtMove mlist[MAX_MOVES]; + ExtMove moveList[MAX_MOVES]; ExtMove *cur, *last; }; diff --git a/src/movepick.cpp b/src/movepick.cpp index b5727f10..9411b5a7 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -51,7 +51,7 @@ namespace { // Unary predicate used by std::partition to split positive values from remaining // ones so as to sort the two sets separately, with the second sort delayed. - inline bool has_positive_value(const ExtMove& ms) { return ms.value > 0; } + inline bool has_positive_value(const ExtMove& move) { return move.value > 0; } // Picks the best move in the range (begin, end) and moves it to the front. // It's faster than sorting all the moves in advance when there are few diff --git a/src/pawns.cpp b/src/pawns.cpp index fe989e9b..16b00ec2 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -268,14 +268,14 @@ Score Entry::do_king_safety(const Position& pos, Square ksq) { kingSquares[Us] = ksq; castlingRights[Us] = pos.can_castle(Us); - minKPdistance[Us] = 0; + minKingPawnDistance[Us] = 0; Bitboard pawns = pos.pieces(Us, PAWN); if (pawns) - while (!(DistanceRingsBB[ksq][minKPdistance[Us]++] & pawns)) {} + while (!(DistanceRingsBB[ksq][minKingPawnDistance[Us]++] & pawns)) {} if (relative_rank(Us, ksq) > RANK_4) - return make_score(0, -16 * minKPdistance[Us]); + return make_score(0, -16 * minKingPawnDistance[Us]); Value bonus = shelter_storm(pos, ksq); @@ -286,7 +286,7 @@ Score Entry::do_king_safety(const Position& pos, Square ksq) { if (pos.can_castle(MakeCastling::right)) bonus = std::max(bonus, shelter_storm(pos, relative_square(Us, SQ_C1))); - return make_score(bonus, -16 * minKPdistance[Us]); + return make_score(bonus, -16 * minKingPawnDistance[Us]); } // Explicit template instantiation diff --git a/src/pawns.h b/src/pawns.h index 5803e36c..807e1b09 100644 --- a/src/pawns.h +++ b/src/pawns.h @@ -70,7 +70,7 @@ struct Entry { Bitboard pawnAttacks[COLOR_NB]; Square kingSquares[COLOR_NB]; Score kingSafety[COLOR_NB]; - int minKPdistance[COLOR_NB]; + int minKingPawnDistance[COLOR_NB]; int castlingRights[COLOR_NB]; int semiopenFiles[COLOR_NB]; int pawnSpan[COLOR_NB]; diff --git a/src/position.cpp b/src/position.cpp index 42256529..ccc66d5b 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -147,13 +147,13 @@ void Position::init() { for (File f = FILE_A; f <= FILE_H; ++f) Zobrist::enpassant[f] = rk.rand(); - for (int cf = NO_CASTLING; cf <= ANY_CASTLING; ++cf) + for (int cr = NO_CASTLING; cr <= ANY_CASTLING; ++cr) { - Bitboard b = cf; + Bitboard b = cr; while (b) { Key k = Zobrist::castling[1ULL << pop_lsb(&b)]; - Zobrist::castling[cf] ^= k ? k : rk.rand(); + Zobrist::castling[cr] ^= k ? k : rk.rand(); } } @@ -363,7 +363,7 @@ void Position::set_castling_right(Color c, Square rfrom) { void Position::set_state(StateInfo* si) const { si->key = si->pawnKey = si->materialKey = 0; - si->npMaterial[WHITE] = si->npMaterial[BLACK] = VALUE_ZERO; + si->nonPawnMaterial[WHITE] = si->nonPawnMaterial[BLACK] = VALUE_ZERO; si->psq = SCORE_ZERO; si->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove); @@ -397,7 +397,7 @@ void Position::set_state(StateInfo* si) const { for (Color c = WHITE; c <= BLACK; ++c) for (PieceType pt = KNIGHT; pt <= QUEEN; ++pt) - si->npMaterial[c] += pieceCount[c][pt] * PieceValue[MG][pt]; + si->nonPawnMaterial[c] += pieceCount[c][pt] * PieceValue[MG][pt]; } @@ -456,7 +456,7 @@ const string Position::fen() const { Phase Position::game_phase() const { - Value npm = st->npMaterial[WHITE] + st->npMaterial[BLACK]; + Value npm = st->nonPawnMaterial[WHITE] + st->nonPawnMaterial[BLACK]; npm = std::max(EndgameLimit, std::min(npm, MidgameLimit)); @@ -492,16 +492,16 @@ Bitboard Position::check_blockers(Color c, Color kingColor) const { /// Position::attackers_to() computes a bitboard of all pieces which attack a -/// given square. Slider attacks use the occ bitboard to indicate occupancy. +/// given square. Slider attacks use the occupied bitboard to indicate occupancy. -Bitboard Position::attackers_to(Square s, Bitboard occ) const { +Bitboard Position::attackers_to(Square s, Bitboard occupied) const { - return (attacks_from(s, BLACK) & pieces(WHITE, PAWN)) - | (attacks_from(s, WHITE) & pieces(BLACK, PAWN)) - | (attacks_from(s) & pieces(KNIGHT)) - | (attacks_bb(s, occ) & pieces(ROOK, QUEEN)) - | (attacks_bb(s, occ) & pieces(BISHOP, QUEEN)) - | (attacks_from(s) & pieces(KING)); + return (attacks_from(s, BLACK) & pieces(WHITE, PAWN)) + | (attacks_from(s, WHITE) & pieces(BLACK, PAWN)) + | (attacks_from(s) & pieces(KNIGHT)) + | (attacks_bb(s, occupied) & pieces(ROOK, QUEEN)) + | (attacks_bb(s, occupied) & pieces(BISHOP, QUEEN)) + | (attacks_from(s) & pieces(KING)); } @@ -526,15 +526,15 @@ bool Position::legal(Move m, Bitboard pinned) const { Square ksq = king_square(us); Square to = to_sq(m); Square capsq = to - pawn_push(us); - Bitboard occ = (pieces() ^ from ^ capsq) | to; + Bitboard occupied = (pieces() ^ from ^ capsq) | to; assert(to == ep_square()); assert(moved_piece(m) == make_piece(us, PAWN)); assert(piece_on(capsq) == make_piece(~us, PAWN)); assert(piece_on(to) == NO_PIECE); - return !(attacks_bb< ROOK>(ksq, occ) & pieces(~us, QUEEN, ROOK)) - && !(attacks_bb(ksq, occ) & pieces(~us, QUEEN, BISHOP)); + return !(attacks_bb< ROOK>(ksq, occupied) & pieces(~us, QUEEN, ROOK)) + && !(attacks_bb(ksq, occupied) & pieces(~us, QUEEN, BISHOP)); } // If the moving piece is a king, check whether the destination @@ -767,7 +767,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI st->pawnKey ^= Zobrist::psq[them][PAWN][capsq]; } else - st->npMaterial[them] -= PieceValue[MG][captured]; + st->nonPawnMaterial[them] -= PieceValue[MG][captured]; // Update board and piece lists remove_piece(capsq, them, captured); @@ -837,7 +837,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI st->psq += psq[us][promotion][to] - psq[us][PAWN][to]; // Update material - st->npMaterial[us] += PieceValue[MG][promotion]; + st->nonPawnMaterial[us] += PieceValue[MG][promotion]; } // Update pawn hash key and prefetch access to pawnsTable @@ -1234,8 +1234,8 @@ bool Position::pos_is_ok(int* step) const { if ( st->key != si.key || st->pawnKey != si.pawnKey || st->materialKey != si.materialKey - || st->npMaterial[WHITE] != si.npMaterial[WHITE] - || st->npMaterial[BLACK] != si.npMaterial[BLACK] + || st->nonPawnMaterial[WHITE] != si.nonPawnMaterial[WHITE] + || st->nonPawnMaterial[BLACK] != si.nonPawnMaterial[BLACK] || st->psq != si.psq || st->checkersBB != si.checkersBB) return false; diff --git a/src/position.h b/src/position.h index b66cc67f..a2ceb990 100644 --- a/src/position.h +++ b/src/position.h @@ -50,7 +50,7 @@ struct CheckInfo { struct StateInfo { Key pawnKey, materialKey; - Value npMaterial[COLOR_NB]; + Value nonPawnMaterial[COLOR_NB]; int castlingRights, rule50, pliesFromNull; Score psq; Square epSquare; @@ -78,8 +78,8 @@ class Position { public: Position() {} - Position(const Position& pos, Thread* t) { *this = pos; thisThread = t; } - Position(const std::string& f, bool c960, Thread* t) { set(f, c960, t); } + Position(const Position& pos, Thread* th) { *this = pos; thisThread = th; } + Position(const std::string& f, bool c960, Thread* th) { set(f, c960, th); } Position& operator=(const Position&); static void init(); @@ -114,7 +114,7 @@ public: // Attacks to/from a given square Bitboard attackers_to(Square s) const; - Bitboard attackers_to(Square s, Bitboard occ) const; + Bitboard attackers_to(Square s, Bitboard occupied) const; Bitboard attacks_from(Piece pc, Square s) const; template Bitboard attacks_from(Square s) const; template Bitboard attacks_from(Square s, Color c) const; @@ -346,7 +346,7 @@ inline Score Position::psq_score() const { } inline Value Position::non_pawn_material(Color c) const { - return st->npMaterial[c]; + return st->nonPawnMaterial[c]; } inline int Position::game_ply() const { diff --git a/src/search.cpp b/src/search.cpp index 5ea00331..5b22b8e9 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -195,9 +195,9 @@ void Search::think() { TimeMgr.init(Limits, RootPos.game_ply(), RootPos.side_to_move()); - int cf = Options["Contempt"] * PawnValueEg / 100; // From centipawns - DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(cf); - DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(cf); + int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns + DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(contempt); + DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(contempt); TB::Hits = 0; TB::RootInTB = false; @@ -324,7 +324,7 @@ namespace { // Save the last iteration's scores before first PV line is searched and // all the move scores except the (new) PV are set to -VALUE_INFINITE. for (size_t i = 0; i < RootMoves.size(); ++i) - RootMoves[i].prevScore = RootMoves[i].score; + RootMoves[i].previousScore = RootMoves[i].score; // MultiPV loop. We perform a full root search for each PV line for (PVIdx = 0; PVIdx < std::min(multiPV, RootMoves.size()) && !Signals.stop; ++PVIdx) @@ -333,8 +333,8 @@ namespace { if (depth >= 5 * ONE_PLY) { delta = Value(16); - alpha = std::max(RootMoves[PVIdx].prevScore - delta,-VALUE_INFINITE); - beta = std::min(RootMoves[PVIdx].prevScore + delta, VALUE_INFINITE); + alpha = std::max(RootMoves[PVIdx].previousScore - delta,-VALUE_INFINITE); + beta = std::min(RootMoves[PVIdx].previousScore + delta, VALUE_INFINITE); } // Start with a small aspiration window and, in the case of a fail @@ -461,7 +461,7 @@ namespace { SplitPoint* splitPoint; Key posKey; Move ttMove, move, excludedMove, bestMove; - Depth ext, newDepth, predictedDepth; + Depth extension, newDepth, predictedDepth; Value bestValue, value, ttValue, eval, nullValue, futilityValue; bool inCheck, givesCheck, singularExtensionNode, improving; bool captureOrPromotion, dangerous, doFullDepthSearch; @@ -789,7 +789,7 @@ moves_loop: // When in check and at SpNode search starts from here if (PvNode) (ss+1)->pv = NULL; - ext = DEPTH_ZERO; + extension = DEPTH_ZERO; captureOrPromotion = pos.capture_or_promotion(move); givesCheck = type_of(move) == NORMAL && !ci.dcCandidates @@ -802,7 +802,7 @@ moves_loop: // When in check and at SpNode search starts from here // Step 12. Extend checks if (givesCheck && pos.see_sign(move) >= VALUE_ZERO) - ext = ONE_PLY; + extension = ONE_PLY; // Singular extension search. If all moves but one fail low on a search of // (alpha-s, beta-s), and just one fails high on (alpha, beta), then that move @@ -811,7 +811,7 @@ moves_loop: // When in check and at SpNode search starts from here // ttValue minus a margin then we extend the ttMove. if ( singularExtensionNode && move == ttMove - && !ext + && !extension && pos.legal(move, ci.pinned)) { Value rBeta = ttValue - 2 * depth / ONE_PLY; @@ -822,11 +822,11 @@ moves_loop: // When in check and at SpNode search starts from here ss->excludedMove = MOVE_NONE; if (value < rBeta) - ext = ONE_PLY; + extension = ONE_PLY; } // Update the current move (this must be done after singular extension search) - newDepth = depth - ONE_PLY + ext; + newDepth = depth - ONE_PLY + extension; // Step 13. Pruning at shallow depth (exclude PV nodes) if ( !PvNode @@ -1386,7 +1386,7 @@ moves_loop: // When in check and at SpNode search starts from here // RootMoves are already sorted by score in descending order int variance = std::min(RootMoves[0].score - RootMoves[candidates - 1].score, PawnValueMg); int weakness = 120 - 2 * level; - int max_s = -VALUE_INFINITE; + int maxScore = -VALUE_INFINITE; best = MOVE_NONE; // Choose best move. For each move score we add two terms both dependent on @@ -1394,19 +1394,19 @@ moves_loop: // When in check and at SpNode search starts from here // then we choose the move with the resulting highest score. for (size_t i = 0; i < candidates; ++i) { - int s = RootMoves[i].score; + int score = RootMoves[i].score; // Don't allow crazy blunders even at very low skills - if (i > 0 && RootMoves[i - 1].score > s + 2 * PawnValueMg) + if (i > 0 && RootMoves[i - 1].score > score + 2 * PawnValueMg) break; // This is our magic formula - s += ( weakness * int(RootMoves[0].score - s) - + variance * (rk.rand() % weakness)) / 128; + score += ( weakness * int(RootMoves[0].score - score) + + variance * (rk.rand() % weakness)) / 128; - if (s > max_s) + if (score > maxScore) { - max_s = s; + maxScore = score; best = RootMoves[i].pv[0]; } } @@ -1437,7 +1437,7 @@ moves_loop: // When in check and at SpNode search starts from here continue; Depth d = updated ? depth : depth - ONE_PLY; - Value v = updated ? RootMoves[i].score : RootMoves[i].prevScore; + Value v = updated ? RootMoves[i].score : RootMoves[i].previousScore; bool tb = TB::RootInTB && abs(v) < VALUE_MATE - MAX_PLY; v = tb ? TB::Score : v; diff --git a/src/search.h b/src/search.h index 71b4b8a8..9151f840 100644 --- a/src/search.h +++ b/src/search.h @@ -56,7 +56,7 @@ struct Stack { /// all non-pv moves. struct RootMove { - RootMove(Move m) : score(-VALUE_INFINITE), prevScore(-VALUE_INFINITE), pv(1, m) {} + RootMove(Move m) : score(-VALUE_INFINITE), previousScore(-VALUE_INFINITE), pv(1, m) {} bool operator<(const RootMove& m) const { return score > m.score; } // Ascending sort bool operator==(const Move& m) const { return pv[0] == m; } @@ -64,7 +64,7 @@ struct RootMove { void insert_pv_in_tt(Position& pos); Value score; - Value prevScore; + Value previousScore; std::vector pv; }; diff --git a/src/thread.cpp b/src/thread.cpp index 4fc0953e..ca87e1dd 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -69,12 +69,12 @@ void ThreadBase::notify_one() { } -// wait_for() set the thread to sleep until condition 'b' turns true +// wait_for() set the thread to sleep until 'condition' turns true -void ThreadBase::wait_for(volatile const bool& b) { +void ThreadBase::wait_for(volatile const bool& condition) { mutex.lock(); - while (!b) sleepCondition.wait(mutex); + while (!condition) sleepCondition.wait(mutex); mutex.unlock(); } @@ -341,10 +341,10 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes void ThreadPool::wait_for_think_finished() { - MainThread* t = main(); - t->mutex.lock(); - while (t->thinking) sleepCondition.wait(t->mutex); - t->mutex.unlock(); + MainThread* th = main(); + th->mutex.lock(); + while (th->thinking) sleepCondition.wait(th->mutex); + th->mutex.unlock(); } -- 2.39.2