From: Marco Costalba Date: Sat, 22 Apr 2017 07:03:17 +0000 (+0200) Subject: Assorted code style issues X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=b48439e90643cb6f65f9e34d1421976883c12efc;hp=6b9a22b40d37d27ad10cafd8697d96e90a586f8a Assorted code style issues I have removed the check for pieceCount[PAWN] > FILE_NB because totally useless. No functional change. --- diff --git a/src/endgame.cpp b/src/endgame.cpp index d3824780..136ee0f6 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -652,7 +652,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { if (relative_rank(strongSide, pawnSq) <= RANK_5) return SCALE_FACTOR_DRAW; - + Bitboard path = forward_bb(strongSide, pawnSq); if (path & pos.pieces(weakSide, KING)) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index f13ddf25..2f60edda 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -117,7 +117,7 @@ namespace { // MobilityBonus[PieceType-2][attacked] contains bonuses for middle and end game, // indexed by piece type and number of attacked squares in the mobility area. - const Score MobilityBonus[4][32] = { + const Score MobilityBonus[][32] = { { S(-75,-76), S(-57,-54), S( -9,-28), S( -2,-10), S( 6, 5), S( 14, 12), // Knights S( 22, 26), S( 29, 29), S( 36, 29) }, { S(-48,-59), S(-20,-23), S( 16, -3), S( 26, 13), S( 38, 24), S( 51, 42), // Bishops @@ -144,7 +144,7 @@ namespace { // RookOnFile[semiopen/open] contains bonuses for each rook when there is no // friendly pawn on the rook file. - const Score RookOnFile[2] = { S(20, 7), S(45, 20) }; + const Score RookOnFile[] = { S(20, 7), S(45, 20) }; // ThreatByMinor/ByRook[attacked PieceType] contains bonuses according to // which piece type attacks which one. Attacks on lesser pieces which are @@ -159,7 +159,7 @@ namespace { // ThreatByKing[on one/on many] contains bonuses for king attacks on // pawns or pieces which are not pawn-defended. - const Score ThreatByKing[2] = { S(3, 62), S(9, 138) }; + const Score ThreatByKing[] = { S(3, 62), S(9, 138) }; // Passed[mg/eg][Rank] contains midgame and endgame bonuses for passed pawns. // We don't use a Score because we process the two components independently. @@ -176,11 +176,11 @@ namespace { // Protector[PieceType-2][distance] contains a protecting bonus for our king, // indexed by piece type and distance between the piece and the king. - const Score Protector[4][8] = { + const Score Protector[][8] = { { S(0, 0), S( 7, 9), S( 7, 1), S( 1, 5), S(-10,-4), S( -1,-4), S( -7,-3), S(-16,-10) }, // Knight { S(0, 0), S(11, 8), S(-7,-1), S(-1,-2), S( -1,-7), S(-11,-3), S( -9,-1), S(-16, -1) }, // Bishop { S(0, 0), S(10, 0), S(-2, 2), S(-5, 4), S( -6, 2), S(-14,-3), S( -2,-9), S(-12, -7) }, // Rook - { S(0, 0), S( 3,-5), S( 2,-5), S(-4, 0), S( -9,-6), S(-4, 7), S(-13,-7), S(-10, -7) } // Queen + { S(0, 0), S( 3,-5), S( 2,-5), S(-4, 0), S( -9,-6), S( -4, 7), S(-13,-7), S(-10, -7) } // Queen }; // Assorted bonuses and penalties used by evaluation @@ -211,13 +211,14 @@ namespace { const int KingAttackWeights[PIECE_TYPE_NB] = { 0, 0, 78, 56, 45, 11 }; // Penalties for enemy's safe checks - const int QueenCheck = 810; - const int RookCheck = 888; - const int BishopCheck = 400; - const int KnightCheck = 790; + const int QueenCheck = 810; + const int RookCheck = 888; + const int BishopCheck = 400; + const int KnightCheck = 790; - // Threshold for lazy evaluation - const Value LazyThreshold = Value(1500); + // Threshold for lazy and space evaluation + const Value LazyThreshold = Value(1500); + const Value SpaceThreshold = Value(12222); // eval_init() initializes king and attack bitboards for a given color // adding pawn attacks. To be done at the beginning of the evaluation. @@ -262,8 +263,8 @@ namespace { template Score evaluate_pieces(const Position& pos, EvalInfo& ei, Score* mobility) { - const PieceType NextPt = (Us == WHITE ? Pt : PieceType(Pt + 1)); const Color Them = (Us == WHITE ? BLACK : WHITE); + const PieceType NextPt = (Us == WHITE ? Pt : PieceType(Pt + 1)); const Bitboard OutpostRanks = (Us == WHITE ? Rank4BB | Rank5BB | Rank6BB : Rank5BB | Rank4BB | Rank3BB); const Square* pl = pos.squares(Us); @@ -531,10 +532,10 @@ namespace { safeThreats = (shift(b) | shift(b)) & weak; + score += ThreatBySafePawn * popcount(safeThreats); + if (weak ^ safeThreats) score += ThreatByHangingPawn; - - score += ThreatBySafePawn * popcount(safeThreats); } // Squares strongly protected by the opponent, either because they attack the @@ -839,7 +840,7 @@ Value Eval::evaluate(const Position& pos) { - evaluate_passer_pawns(pos, ei); // Evaluate space for both sides, only during opening - if (pos.non_pawn_material() >= 12222) + if (pos.non_pawn_material() >= SpaceThreshold) score += evaluate_space(pos, ei) - evaluate_space(pos, ei); @@ -862,7 +863,7 @@ Value Eval::evaluate(const Position& pos) { Trace::add(IMBALANCE, ei.me->imbalance()); Trace::add(PAWN, ei.pe->pawns_score()); Trace::add(MOBILITY, mobility[WHITE], mobility[BLACK]); - if (pos.non_pawn_material() >= 12222) + if (pos.non_pawn_material() >= SpaceThreshold) Trace::add(SPACE, evaluate_space(pos, ei) , evaluate_space(pos, ei)); Trace::add(TOTAL, score); diff --git a/src/material.cpp b/src/material.cpp index 56ad39d3..e5b8ddf2 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -53,9 +53,9 @@ namespace { { 101, 100, -37, 141, 268, 0 } // Queen }; - // PawnsSet[count] contains a bonus/malus indexed by number of pawns - const int PawnsSet[FILE_NB + 1] = { - 24, -32, 107, -51, 117, -9, -126, -21, 31 + // PawnSet[pawn count] contains a bonus/malus indexed by number of pawns + const int PawnSet[] = { + 24, -32, 107, -51, 117, -9, -126, -21, 31 }; // Endgame evaluation and scaling functions are accessed directly and not through @@ -94,7 +94,7 @@ namespace { const Color Them = (Us == WHITE ? BLACK : WHITE); - int bonus = PawnsSet[pieceCount[Us][PAWN]]; + int bonus = PawnSet[pieceCount[Us][PAWN]]; // Second-degree polynomial material imbalance by Tord Romstad for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1) diff --git a/src/misc.cpp b/src/misc.cpp index 11833440..42dc0b06 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -207,8 +207,8 @@ void prefetch(void* addr) { void prefetch2(void* addr) { - prefetch(addr); - prefetch((uint8_t*)addr + 64); + prefetch(addr); + prefetch((uint8_t*)addr + 64); } namespace WinProcGroup { diff --git a/src/movepick.cpp b/src/movepick.cpp index cc795280..7fe8971b 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -34,11 +34,11 @@ namespace { QSEARCH_RECAPTURES, QRECAPTURES }; - // An insertion sort, which sorts moves in descending order up to and including a given limit. - // The order of moves smaller than the limit is left unspecified. - // To keep the implementation simple, *begin is always included in the list of sorted moves. - void partial_insertion_sort(ExtMove* begin, ExtMove* end, int limit) - { + // partial_insertion_sort() sorts moves in descending order up to and including + // a given limit. The order of moves smaller than the limit is left unspecified. + // To keep the implementation simple, *begin is always included in the sorted moves. + void partial_insertion_sort(ExtMove* begin, ExtMove* end, int limit) { + for (ExtMove *sortedEnd = begin + 1, *p = begin + 1; p < end; ++p) if (p->value >= limit) { @@ -54,10 +54,10 @@ namespace { // pick_best() finds 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 moves, e.g., the possible captures. - Move pick_best(ExtMove* begin, ExtMove* end) - { - std::swap(*begin, *std::max_element(begin, end)); - return *begin; + Move pick_best(ExtMove* begin, ExtMove* end) { + + std::swap(*begin, *std::max_element(begin, end)); + return *begin; } } // namespace @@ -118,7 +118,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Value th) ttMove = ttm && pos.pseudo_legal(ttm) && pos.capture(ttm) - && pos.see_ge(ttm, threshold)? ttm : MOVE_NONE; + && pos.see_ge(ttm, threshold) ? ttm : MOVE_NONE; stage += (ttMove == MOVE_NONE); } @@ -241,7 +241,6 @@ Move MovePicker::next_move(bool skipQuiets) { cur = endBadCaptures; endMoves = generate(pos, cur); score(); - partial_insertion_sort(cur, endMoves, -4000 * depth / ONE_PLY); ++stage; diff --git a/src/movepick.h b/src/movepick.h index 3614439f..1a81dbde 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -21,7 +21,6 @@ #ifndef MOVEPICK_H_INCLUDED #define MOVEPICK_H_INCLUDED -#include // For std::max #include // For std::memset #include "movegen.h" @@ -42,11 +41,11 @@ struct HistoryStats { Square from = from_sq(m); Square to = to_sq(m); - const int denom = 324; + const int D = 324; - assert(abs(int(v)) <= denom); // Needed for stability. + assert(abs(int(v)) <= D); // Consistency check for below formula - table[c][from][to] -= table[c][from][to] * abs(int(v)) / denom; + table[c][from][to] -= table[c][from][to] * abs(int(v)) / D; table[c][from][to] += int(v) * 32; } @@ -66,15 +65,14 @@ struct Stats { const T* operator[](Piece pc) const { return table[pc]; } T* operator[](Piece pc) { return table[pc]; } void clear() { std::memset(table, 0, sizeof(table)); } - void fill(const int& v) { std::fill(&table[0][0], &table[PIECE_NB-1][SQUARE_NB-1]+1, v); }; void update(Piece pc, Square to, Move m) { table[pc][to] = m; } void update(Piece pc, Square to, int v) { - const int denom = 936; + const int D = 936; - assert(abs(int(v)) <= denom); // Needed for stability. + assert(abs(int(v)) <= D); // Consistency check for below formula - table[pc][to] -= table[pc][to] * abs(int(v)) / denom; + table[pc][to] -= table[pc][to] * abs(int(v)) / D; table[pc][to] += int(v) * 32; } diff --git a/src/pawns.cpp b/src/pawns.cpp index cee74413..0e57f01f 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -32,10 +32,10 @@ namespace { #define S(mg, eg) make_score(mg, eg) // Isolated pawn penalty by opposed flag - const Score Isolated[2] = { S(45, 40), S(30, 27) }; + const Score Isolated[] = { S(45, 40), S(30, 27) }; // Backward pawn penalty by opposed flag - const Score Backward[2] = { S(56, 33), S(41, 19) }; + const Score Backward[] = { S(56, 33), S(41, 19) }; // Unsupported pawn penalty for pawns which are neither isolated or backward const Score Unsupported = S(17, 8); diff --git a/src/position.cpp b/src/position.cpp index 7d0cde21..e20c822f 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1192,7 +1192,6 @@ bool Position::pos_is_ok(int* failedStep) const { } if (step == Lists) - { for (Piece pc : Pieces) { if (pieceCount[pc] != popcount(pieces(color_of(pc), type_of(pc)))) @@ -1202,9 +1201,6 @@ bool Position::pos_is_ok(int* failedStep) const { if (board[pieceList[pc][i]] != pc || index[pieceList[pc][i]] != i) return false; } - if (pieceCount[PAWN] > FILE_NB) - return false; - } if (step == Castling) for (Color c = WHITE; c <= BLACK; ++c) diff --git a/src/search.cpp b/src/search.cpp index 433129d9..db2d933d 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -75,7 +75,7 @@ namespace { int FutilityMoveCounts[2][16]; // [improving][depth] int Reductions[2][2][64][64]; // [pv][improving][depth][moveNumber] - // Threshold used for countermoves based pruning. + // Threshold used for countermoves based pruning const int CounterMovePruneThreshold = 0; template Depth reduction(bool i, Depth d, int mn) { @@ -195,8 +195,10 @@ void Search::clear() { th->counterMoves.clear(); th->history.clear(); th->counterMoveHistory.clear(); - th->counterMoveHistory[NO_PIECE][0].fill(CounterMovePruneThreshold-1); th->resetCalls = true; + CounterMoveStats& cm = th->counterMoveHistory[NO_PIECE][0]; + int* t = &cm[NO_PIECE][0]; + std::fill(t, t + sizeof(cm), CounterMovePruneThreshold - 1); } Threads.main()->previousScore = VALUE_INFINITE; @@ -562,9 +564,10 @@ namespace { if (thisThread->resetCalls.load(std::memory_order_relaxed)) { thisThread->resetCalls = false; + // At low node count increase the checking rate to about 0.1% of nodes // otherwise use a default value. - thisThread->callsCnt = Limits.nodes ? std::min((int64_t)4096, Limits.nodes / 1024) + thisThread->callsCnt = Limits.nodes ? std::min(4096, int(Limits.nodes / 1024)) : 4096; } @@ -889,7 +892,7 @@ moves_loop: // When in check search starts from here if (value < rBeta) extension = ONE_PLY; } - else if ( givesCheck + else if ( givesCheck && !moveCountPruning && pos.see_ge(move, VALUE_ZERO)) extension = ONE_PLY; @@ -904,10 +907,11 @@ moves_loop: // When in check search starts from here { if ( !captureOrPromotion && !givesCheck - && (!pos.advanced_pawn_push(move) || pos.non_pawn_material() >= 5000)) + && (!pos.advanced_pawn_push(move) || pos.non_pawn_material() >= Value(5000))) { // Move count based pruning - if (moveCountPruning) { + if (moveCountPruning) + { skipQuiets = true; continue; } @@ -1126,11 +1130,11 @@ moves_loop: // When in check search starts from here && is_ok((ss-1)->currentMove)) update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, stat_bonus(depth)); - if(!excludedMove) + if (!excludedMove) tte->save(posKey, value_to_tt(bestValue, ss->ply), - bestValue >= beta ? BOUND_LOWER : - PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER, - depth, bestMove, ss->staticEval, TT.generation()); + bestValue >= beta ? BOUND_LOWER : + PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER, + depth, bestMove, ss->staticEval, TT.generation()); assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE); diff --git a/src/syzygy/tbprobe.cpp b/src/syzygy/tbprobe.cpp index 2dd50a66..d56ba05a 100644 --- a/src/syzygy/tbprobe.cpp +++ b/src/syzygy/tbprobe.cpp @@ -978,8 +978,8 @@ uint8_t* set_sizes(PairsData* d, uint8_t* data) { d->flags = *data++; if (d->flags & TBFlag::SingleValue) { - d->blocksNum = d->span = - d->blockLengthSize = d->sparseIndexSize = 0; // Broken MSVC zero-init + d->blocksNum = d->blockLengthSize = 0; + d->span = d->sparseIndexSize = 0; // Broken MSVC zero-init d->minSymLen = *data++; // Here we store the single value return data; }