From: Lucas Braesch Date: Thu, 3 Oct 2013 04:01:38 +0000 (+0800) Subject: Use prefix operators wherever possible X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=7f142d68179919a507204e7980fff4f79648dbbc Use prefix operators wherever possible No functional change. --- diff --git a/src/bitbase.cpp b/src/bitbase.cpp index e4428d2d..37b05649 100644 --- a/src/bitbase.cpp +++ b/src/bitbase.cpp @@ -87,17 +87,17 @@ void Bitbases::init_kpk() { db.reserve(IndexMax); // Initialize db with known win / draw positions - for (idx = 0; idx < IndexMax; idx++) + for (idx = 0; idx < IndexMax; ++idx) db.push_back(KPKPosition(idx)); // Iterate through the positions until no more of the unknown positions can be // changed to either wins or draws (15 cycles needed). while (repeat) - for (repeat = idx = 0; idx < IndexMax; idx++) + for (repeat = idx = 0; idx < IndexMax; ++idx) repeat |= (db[idx] == UNKNOWN && db[idx].classify(db) != UNKNOWN); // Map 32 results into one KPKBitbase[] entry - for (idx = 0; idx < IndexMax; idx++) + for (idx = 0; idx < IndexMax; ++idx) if (db[idx] == WIN) KPKBitbase[idx / 32] |= 1 << (idx & 0x1F); } diff --git a/src/bitboard.cpp b/src/bitboard.cpp index cbece63c..ae653b1c 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -197,7 +197,7 @@ void Bitboards::init() { for (Color c = WHITE; c <= BLACK; ++c) for (PieceType pt = PAWN; pt <= KING; ++pt) for (Square s = SQ_A1; s <= SQ_H8; ++s) - for (int k = 0; steps[pt][k]; k++) + for (int k = 0; steps[pt][k]; ++k) { Square to = s + Square(c == WHITE ? steps[pt][k] : -steps[pt][k]); diff --git a/src/evaluate.cpp b/src/evaluate.cpp index ec040f63..558e7d13 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -499,7 +499,7 @@ Value do_evaluate(const Position& pos, Value& margin) { if (b & ei.kingRing[Them]) { - ei.kingAttackersCount[Us]++; + ++ei.kingAttackersCount[Us]; ei.kingAttackersWeight[Us] += KingAttackWeights[Piece]; Bitboard bb = (b & ei.attackedBy[Them][KING]); if (bb) diff --git a/src/material.cpp b/src/material.cpp index 0f1e19b9..8d0b7f3a 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -113,7 +113,7 @@ namespace { + RedundantQueen * pieceCount[Us][QUEEN]; // Second-degree polynomial material imbalance by Tord Romstad - for (pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++) + for (pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1) { pc = pieceCount[Us][pt1]; if (!pc) @@ -121,7 +121,7 @@ namespace { v = LinearCoefficients[pt1]; - for (pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++) + for (pt2 = NO_PIECE_TYPE; pt2 <= pt1; ++pt2) v += QuadraticCoefficientsSameColor[pt1][pt2] * pieceCount[Us][pt2] + QuadraticCoefficientsOppositeColor[pt1][pt2] * pieceCount[Them][pt2]; diff --git a/src/misc.cpp b/src/misc.cpp index 5bf7bae8..a9b1f17e 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -63,9 +63,9 @@ const string engine_info(bool to_uci) { static uint64_t hits[2], means[2]; -void dbg_hit_on(bool b) { hits[0]++; if (b) hits[1]++; } +void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; } void dbg_hit_on_c(bool c, bool b) { if (c) dbg_hit_on(b); } -void dbg_mean_of(int v) { means[0]++; means[1] += v; } +void dbg_mean_of(int v) { ++means[0]; means[1] += v; } void dbg_print() { diff --git a/src/movegen.cpp b/src/movegen.cpp index 03bc7a09..96dd89c5 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -62,7 +62,7 @@ namespace { (mlist++)->move = make(kfrom, rfrom); if (Checks && !pos.gives_check((mlist - 1)->move, CheckInfo(pos))) - mlist--; + --mlist; return mlist; } @@ -359,7 +359,7 @@ ExtMove* generate(const Position& pos, ExtMove* mlist) { // evasions so to skip known illegal moves avoiding useless legality check later. do { - checkersCnt++; + ++checkersCnt; checksq = pop_lsb(&b); assert(color_of(pos.piece_on(checksq)) == ~us); @@ -417,7 +417,7 @@ ExtMove* generate(const Position& pos, ExtMove* mlist) { && !pos.legal(cur->move, pinned)) cur->move = (--end)->move; else - cur++; + ++cur; return end; } diff --git a/src/movegen.h b/src/movegen.h index 2a4cda90..c93252a7 100644 --- a/src/movegen.h +++ b/src/movegen.h @@ -42,7 +42,7 @@ template struct MoveList { explicit MoveList(const Position& pos) : cur(mlist), last(generate(pos, mlist)) { last->move = MOVE_NONE; } - void operator++() { cur++; } + void operator++() { ++cur; } Move operator*() const { return cur->move; } size_t size() const { return last - mlist; } bool contains(Move m) const { diff --git a/src/movepick.cpp b/src/movepick.cpp index e2428554..8baf32a4 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -299,7 +299,7 @@ Move MovePicker::next_move() { switch (stage) { case MAIN_SEARCH: case EVASION: case QSEARCH_0: case QSEARCH_1: case PROBCUT: - cur++; + ++cur; return ttMove; case CAPTURES_S1: diff --git a/src/pawns.cpp b/src/pawns.cpp index c5a48e93..37db2cf5 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -227,7 +227,7 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) { Rank rkUs, rkThem; File kf = std::max(FILE_B, std::min(FILE_G, file_of(ksq))); - for (int f = kf - 1; f <= kf + 1; f++) + for (int f = kf - 1; f <= kf + 1; ++f) { b = ourPawns & FileBB[f]; rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1; diff --git a/src/position.cpp b/src/position.cpp index 28b39c8d..bef7a0fe 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -128,7 +128,7 @@ void Position::init() { for (File f = FILE_A; f <= FILE_H; ++f) Zobrist::enpassant[f] = rk.rand(); - for (int cr = CASTLES_NONE; cr <= ALL_CASTLES; cr++) + for (int cr = CASTLES_NONE; cr <= ALL_CASTLES; ++cr) { Bitboard b = cr; while (b) @@ -345,7 +345,7 @@ const string Position::fen() const { int emptyCnt = 1; for ( ; file < FILE_H && empty(++sq); ++file) - emptyCnt++; + ++emptyCnt; ss << emptyCnt; } @@ -718,7 +718,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI assert(is_ok(m)); assert(&newSt != st); - nodes++; + ++nodes; Key k = st->key; // Copy some fields of old state to our new StateInfo object except the ones @@ -734,9 +734,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI // Increment ply counters.In particular rule50 will be later reset it to zero // in case of a capture or a pawn move. - gamePly++; - st->rule50++; - st->pliesFromNull++; + ++gamePly; + ++st->rule50; + ++st->pliesFromNull; Color us = sideToMove; Color them = ~us; @@ -978,7 +978,7 @@ void Position::undo_move(Move m) { // Finally point our state pointer back to the previous state st = st->previous; - gamePly--; + --gamePly; assert(pos_is_ok()); } @@ -1019,7 +1019,7 @@ void Position::do_null_move(StateInfo& newSt) { st->key ^= Zobrist::side; prefetch((char*)TT.first_entry(st->key)); - st->rule50++; + ++st->rule50; st->pliesFromNull = 0; sideToMove = ~sideToMove; @@ -1106,7 +1106,7 @@ int Position::see(Move m, int asymmThreshold) const { // Add the new entry to the swap list swapList[slIndex] = -swapList[slIndex - 1] + PieceValue[MG][captured]; - slIndex++; + ++slIndex; // Locate and remove the next least valuable attacker captured = min_attacker(byTypeBB, to, stmAttackers, occupied, attackers); @@ -1150,7 +1150,7 @@ void Position::clear() { st = &startState; for (int i = 0; i < PIECE_TYPE_NB; ++i) - for (int j = 0; j < 16; j++) + for (int j = 0; j < 16; ++j) pieceList[WHITE][i][j] = pieceList[BLACK][i][j] = SQ_NONE; } @@ -1368,7 +1368,7 @@ bool Position::pos_is_ok(int* failedStep) const { for (Square s = SQ_A1; s <= SQ_H8; ++s) if (type_of(piece_on(s)) == KING) - kingCount[color_of(piece_on(s))]++; + ++kingCount[color_of(piece_on(s))]; if (kingCount[0] != 1 || kingCount[1] != 1) return false; diff --git a/src/search.cpp b/src/search.cpp index 5ef8bc7f..dcf3e613 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -131,7 +131,7 @@ void Search::init() { int mc; // moveCount // Init reductions array - for (hd = 1; hd < 64; hd++) for (mc = 1; mc < 64; mc++) + for (hd = 1; hd < 64; ++hd) for (mc = 1; mc < 64; ++mc) { double pvRed = log(double(hd)) * log(double(mc)) / 3.0; double nonPVRed = 0.33 + log(double(hd)) * log(double(mc)) / 2.25; @@ -146,11 +146,11 @@ void Search::init() { } // Init futility margins array - for (d = 1; d < 16; d++) for (mc = 0; mc < 64; mc++) + for (d = 1; d < 16; ++d) for (mc = 0; mc < 64; ++mc) FutilityMargins[d][mc] = Value(112 * int(log(double(d * d) / 2) / log(2.0) + 1.001) - 8 * mc + 45); // Init futility move count array - for (d = 0; d < 32; d++) + for (d = 0; d < 32; ++d) { FutilityMoveCounts[0][d] = int(3 + 0.3 * pow(double(d ), 1.8)) * 3/4 + (2 < d && d < 5); FutilityMoveCounts[1][d] = int(3 + 0.3 * pow(double(d + 0.98), 1.8)); @@ -341,7 +341,7 @@ namespace { RootMoves[i].prevScore = RootMoves[i].score; // MultiPV loop. We perform a full root search for each PV line - for (PVIdx = 0; PVIdx < PVSize; PVIdx++) + for (PVIdx = 0; PVIdx < PVSize; ++PVIdx) { // Reset aspiration window starting size if (depth >= 5) @@ -810,7 +810,7 @@ moves_loop: // When in check and at SpNode search starts from here splitPoint->mutex.unlock(); } else - moveCount++; + ++moveCount; if (RootNode) { @@ -919,7 +919,7 @@ moves_loop: // When in check and at SpNode search starts from here // Check for legality only before to do the move if (!RootNode && !SpNode && !pos.legal(move, ci.pinned)) { - moveCount--; + --moveCount; continue; } @@ -1017,7 +1017,7 @@ moves_loop: // When in check and at SpNode search starts from here // iteration. This information is used for time management: When // the best move changes frequently, we allocate some more time. if (!pvMove) - BestMoveChanges++; + ++BestMoveChanges; } else // All other moves but the PV are set to the lowest value, this @@ -1443,7 +1443,7 @@ moves_loop: // When in check and at SpNode search starts from here static RKISS rk; // PRNG sequence should be not deterministic - for (int i = Time::now() % 50; i > 0; i--) + for (int i = Time::now() % 50; i > 0; --i) rk.rand(); // RootMoves are already sorted by score in descending order @@ -1514,7 +1514,7 @@ moves_loop: // When in check and at SpNode search starts from here << " multipv " << i + 1 << " pv"; - for (size_t j = 0; RootMoves[i].pv[j] != MOVE_NONE; j++) + for (size_t j = 0; RootMoves[i].pv[j] != MOVE_NONE; ++j) s << " " << move_to_uci(RootMoves[i].pv[j], pos.is_chess960()); } @@ -1730,7 +1730,7 @@ void check_time() { // Loop across all split points and sum accumulated SplitPoint nodes plus // all the currently active positions nodes. for (size_t i = 0; i < Threads.size(); ++i) - for (int j = 0; j < Threads[i]->splitPointsSize; j++) + for (int j = 0; j < Threads[i]->splitPointsSize; ++j) { SplitPoint& sp = Threads[i]->splitPoints[j]; diff --git a/src/thread.cpp b/src/thread.cpp index 782537d7..735cc97c 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -296,7 +296,7 @@ void Thread::split(Position& pos, const Stack* ss, Value alpha, Value beta, Valu Threads.mutex.lock(); sp.mutex.lock(); - splitPointsSize++; + ++splitPointsSize; activeSplitPoint = &sp; activePosition = NULL; @@ -336,7 +336,7 @@ void Thread::split(Position& pos, const Stack* ss, Value alpha, Value beta, Valu } searching = true; - splitPointsSize--; + --splitPointsSize; activeSplitPoint = sp.parentSplitPoint; activePosition = &pos; pos.set_nodes_searched(pos.nodes_searched() + sp.nodes); diff --git a/src/timeman.cpp b/src/timeman.cpp index 62b7eb11..34dbcc6e 100644 --- a/src/timeman.cpp +++ b/src/timeman.cpp @@ -114,7 +114,7 @@ void TimeManager::init(const Search::LimitsType& limits, int currentPly, Color u // We calculate optimum time usage for different hypothetic "moves to go"-values and choose the // minimum of calculated search time values. Usually the greatest hypMTG gives the minimum values. - for (hypMTG = 1; hypMTG <= (limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon); hypMTG++) + for (hypMTG = 1; hypMTG <= (limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon); ++hypMTG) { // Calculate thinking time for hypothetic "moves to go"-value hypMyTime = limits.time[us] diff --git a/src/tt.cpp b/src/tt.cpp index 11173e0a..d2ff8704 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -73,7 +73,7 @@ const TTEntry* TranspositionTable::probe(const Key key) const { const TTEntry* tte = first_entry(key); uint32_t key32 = key >> 32; - for (unsigned i = 0; i < ClusterSize; ++i, tte++) + for (unsigned i = 0; i < ClusterSize; ++i, ++tte) if (tte->key() == key32) return tte; @@ -97,7 +97,7 @@ void TranspositionTable::store(const Key key, Value v, Bound b, Depth d, Move m, tte = replace = first_entry(key); - for (unsigned i = 0; i < ClusterSize; ++i, tte++) + for (unsigned i = 0; i < ClusterSize; ++i, ++tte) { if (!tte->key() || tte->key() == key32) // Empty or overwrite old { diff --git a/src/tt.h b/src/tt.h index 3113751a..3953d1c9 100644 --- a/src/tt.h +++ b/src/tt.h @@ -78,7 +78,7 @@ class TranspositionTable { public: ~TranspositionTable() { free(mem); } - void new_search() { generation++; } + void new_search() { ++generation; } const TTEntry* probe(const Key key) const; TTEntry* first_entry(const Key key) const; diff --git a/src/ucioption.cpp b/src/ucioption.cpp index af2332bc..8e9a9233 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -94,7 +94,7 @@ void init(OptionsMap& o) { std::ostream& operator<<(std::ostream& os, const OptionsMap& om) { - for (size_t idx = 0; idx < om.size(); idx++) + for (size_t idx = 0; idx < om.size(); ++idx) for (OptionsMap::const_iterator it = om.begin(); it != om.end(); ++it) if (it->second.idx == idx) {