From c2d42ea8339b49e52a116e488214a14fda09d413 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 25 Dec 2011 11:50:59 +0100 Subject: [PATCH] Rename getters functions removing 'get_' prefix Follow the suggested Qt style: http://doc.qt.nokia.com/qq/qq13-apis.html It seems to me simpler and easier to read. No functional change. Signed-off-by: Marco Costalba --- src/benchmark.cpp | 4 ++-- src/book.cpp | 2 +- src/endgame.cpp | 2 +- src/evaluate.cpp | 4 ++-- src/material.cpp | 6 +++--- src/material.h | 4 ++-- src/misc.cpp | 4 ++-- src/misc.h | 2 +- src/movepick.cpp | 8 ++++---- src/movepick.h | 4 ++-- src/pawns.cpp | 6 +++--- src/pawns.h | 10 +++++----- src/position.cpp | 24 ++++++++++++------------ src/position.h | 16 ++++++++-------- src/search.cpp | 30 +++++++++++++++--------------- src/uci.cpp | 10 +++++----- 16 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/benchmark.cpp b/src/benchmark.cpp index 9f32dbae..876b270f 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -107,7 +107,7 @@ void benchmark(int argc, char* argv[]) { // Ok, let's start the benchmark ! totalNodes = 0; - time = get_system_time(); + time = system_time(); for (size_t i = 0; i < fenList.size(); i++) { @@ -131,7 +131,7 @@ void benchmark(int argc, char* argv[]) { } } - time = get_system_time() - time; + time = system_time() - time; cerr << "\n===============================" << "\nTotal time (ms) : " << time diff --git a/src/book.cpp b/src/book.cpp index 427ae56e..494c9c11 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -349,7 +349,7 @@ namespace { /// Book c'tor. Make random number generation less deterministic, for book moves Book::Book() : bookSize(0) { - for (int i = abs(get_system_time() % 10000); i > 0; i--) + for (int i = abs(system_time() % 10000); i > 0; i--) RKiss.rand(); } diff --git a/src/endgame.cpp b/src/endgame.cpp index 82801317..d2877227 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -87,7 +87,7 @@ namespace { fen += string(1, '0' + int(8 - keyCode.length())) + "/8/8/8/8/8/8/8 w - - 0 10"; // Build a Position out of the fen string and get its material key - return Position(fen, false, 0).get_material_key(); + return Position(fen, false, 0).material_key(); } } // namespace diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 6d95fd58..5d8d7b99 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -288,7 +288,7 @@ Value do_evaluate(const Position& pos, Value& margin) { margins[WHITE] = margins[BLACK] = VALUE_ZERO; // Probe the material hash table - ei.mi = Threads[pos.thread()].materialTable.get_material_info(pos); + ei.mi = Threads[pos.thread()].materialTable.material_info(pos); score += ei.mi->material_value(); // If we have a specialized evaluation function for the current material @@ -300,7 +300,7 @@ Value do_evaluate(const Position& pos, Value& margin) { } // Probe the pawn hash table - ei.pi = Threads[pos.thread()].pawnTable.get_pawn_info(pos); + ei.pi = Threads[pos.thread()].pawnTable.pawn_info(pos); score += ei.pi->pawns_value(); // Initialize attack and king safety bitboards diff --git a/src/material.cpp b/src/material.cpp index 27a88f86..cf1019ac 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -90,15 +90,15 @@ void MaterialInfoTable::init() { Base::init(); if (!funcs) funcs = new Endgames( MaterialInfoTable::~MaterialInfoTable() { delete funcs; } -/// MaterialInfoTable::get_material_info() takes a position object as input, +/// MaterialInfoTable::material_info() takes a position object as input, /// computes or looks up a MaterialInfo object, and returns a pointer to it. /// If the material configuration is not already present in the table, it /// is stored there, so we don't have to recompute everything when the /// same material configuration occurs again. -MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) const { +MaterialInfo* MaterialInfoTable::material_info(const Position& pos) const { - Key key = pos.get_material_key(); + Key key = pos.material_key(); MaterialInfo* mi = probe(key); // If mi->key matches the position's material hash key, it means that we diff --git a/src/material.h b/src/material.h index e33fc87b..94c2d637 100644 --- a/src/material.h +++ b/src/material.h @@ -68,13 +68,13 @@ private: /// The MaterialInfoTable class represents a pawn hash table. The most important -/// method is get_material_info, which returns a pointer to a MaterialInfo object. +/// method is material_info(), which returns a pointer to a MaterialInfo object. class MaterialInfoTable : public SimpleHash { public: ~MaterialInfoTable(); void init(); - MaterialInfo* get_material_info(const Position& pos) const; + MaterialInfo* material_info(const Position& pos) const; static Phase game_phase(const Position& pos); private: diff --git a/src/misc.cpp b/src/misc.cpp index 4d91c0fb..5912514c 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -134,9 +134,9 @@ void dbg_before() { dbg_hit_on(false); } void dbg_after() { dbg_hit_on(true); dbg_hit_cnt0--; } -/// get_system_time() returns the current system time, measured in milliseconds +/// system_time() returns the current system time, measured in milliseconds -int get_system_time() { +int system_time() { #if defined(_MSC_VER) struct _timeb t; diff --git a/src/misc.h b/src/misc.h index 303514f7..c5ca5387 100644 --- a/src/misc.h +++ b/src/misc.h @@ -28,7 +28,7 @@ extern const std::string engine_name(); extern const std::string engine_authors(); -extern int get_system_time(); +extern int system_time(); extern int cpu_count(); extern void timed_wait(WaitCondition*, Lock*, int); extern void prefetch(char* addr); diff --git a/src/movepick.cpp b/src/movepick.cpp index 589c27b3..b992d235 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -232,7 +232,7 @@ void MovePicker::go_next_phase() { /// MovePicker::score_captures(), MovePicker::score_noncaptures() and /// MovePicker::score_evasions() assign a numerical move ordering score /// to each move in a move list. The moves with highest scores will be -/// picked first by get_next_move(). +/// picked first by next_move(). void MovePicker::score_captures() { // Winning and equal captures in the main search are ordered by MVV/LVA. @@ -300,14 +300,14 @@ void MovePicker::score_evasions() { } } -/// MovePicker::get_next_move() is the most important method of the MovePicker -/// class. It returns a new pseudo legal move every time it is called, until there +/// MovePicker::next_move() is the most important method of the MovePicker class. +/// It returns a new pseudo legal move every time it is called, until there /// are no more moves left. It picks the move with the biggest score from a list /// of generated moves taking care not to return the tt move if has already been /// searched previously. Note that this function is not thread safe so should be /// lock protected by caller when accessed through a shared MovePicker object. -Move MovePicker::get_next_move() { +Move MovePicker::next_move() { Move move; diff --git a/src/movepick.h b/src/movepick.h index b2a8dc98..9f2be291 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -28,7 +28,7 @@ /// MovePicker is a class which is used to pick one pseudo legal move at a time /// from the current position. It is initialized with a Position object and a few /// moves we have reason to believe are good. The most important method is -/// MovePicker::get_next_move(), which returns a new pseudo legal move each time +/// MovePicker::next_move(), which returns a new pseudo legal move each time /// it is called, until there are no moves left, when MOVE_NONE is returned. /// In order to improve the efficiency of the alpha beta algorithm, MovePicker /// attempts to return the moves which are most likely to get a cut-off first. @@ -41,7 +41,7 @@ public: MovePicker(const Position&, Move, Depth, const History&, Search::Stack*, Value); MovePicker(const Position&, Move, Depth, const History&, Square recaptureSq); MovePicker(const Position&, Move, const History&, PieceType parentCapture); - Move get_next_move(); + Move next_move(); private: void score_captures(); diff --git a/src/pawns.cpp b/src/pawns.cpp index 3aede5ad..2906b045 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -72,14 +72,14 @@ namespace { } -/// PawnInfoTable::get_pawn_info() takes a position object as input, computes +/// PawnInfoTable::pawn_info() takes a position object as input, computes /// a PawnInfo object, and returns a pointer to it. The result is also stored /// in an hash table, so we don't have to recompute everything when the same /// pawn structure occurs again. -PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) const { +PawnInfo* PawnInfoTable::pawn_info(const Position& pos) const { - Key key = pos.get_pawn_key(); + Key key = pos.pawn_key(); PawnInfo* pi = probe(key); // If pi->key matches the position's pawn hash key, it means that we diff --git a/src/pawns.h b/src/pawns.h index fec0395f..4d65bea2 100644 --- a/src/pawns.h +++ b/src/pawns.h @@ -29,9 +29,9 @@ const int PawnTableSize = 16384; /// PawnInfo is a class which contains various information about a pawn /// structure. Currently, it only includes a middle game and an end game /// pawn structure evaluation, and a bitboard of passed pawns. We may want -/// to add further information in the future. A lookup to the pawn hash table -/// (performed by calling the get_pawn_info method in a PawnInfoTable object) -/// returns a pointer to a PawnInfo object. +/// to add further information in the future. A lookup to the pawn hash +/// table (performed by calling the pawn_info method in a PawnInfoTable +/// object) returns a pointer to a PawnInfo object. class PawnInfo { @@ -63,11 +63,11 @@ private: /// The PawnInfoTable class represents a pawn hash table. The most important -/// method is get_pawn_info, which returns a pointer to a PawnInfo object. +/// method is pawn_info, which returns a pointer to a PawnInfo object. class PawnInfoTable : public SimpleHash { public: - PawnInfo* get_pawn_info(const Position& pos) const; + PawnInfo* pawn_info(const Position& pos) const; private: template diff --git a/src/position.cpp b/src/position.cpp index 66890a5f..9a49501c 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -731,7 +731,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI assert(&newSt != st); nodes++; - Key key = st->key; + Key k = st->key; // Copy some fields of old state to our new StateInfo object except the ones // which are recalculated from scratch anyway, then switch our state pointer @@ -750,7 +750,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI st = &newSt; // Update side to move - key ^= zobSideToMove; + k ^= zobSideToMove; // Increment the 50 moves rule draw counter. Resetting it to zero in the // case of non-reversible moves is taken care of later. @@ -759,7 +759,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI if (is_castle(m)) { - st->key = key; + st->key = k; do_castle_move(m); return; } @@ -820,7 +820,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI pieceList[them][capture][pieceCount[them][capture]] = SQ_NONE; // Update hash keys - key ^= zobrist[them][capture][capsq]; + k ^= zobrist[them][capture][capsq]; st->materialKey ^= zobrist[them][capture][pieceCount[them][capture]]; // Update incremental scores @@ -831,12 +831,12 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI } // Update hash key - key ^= zobrist[us][pt][from] ^ zobrist[us][pt][to]; + k ^= zobrist[us][pt][from] ^ zobrist[us][pt][to]; // Reset en passant square if (st->epSquare != SQ_NONE) { - key ^= zobEp[st->epSquare]; + k ^= zobEp[st->epSquare]; st->epSquare = SQ_NONE; } @@ -844,13 +844,13 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI if ( st->castleRights != CASTLES_NONE && (castleRightsMask[from] & castleRightsMask[to]) != ALL_CASTLES) { - key ^= zobCastle[st->castleRights]; + k ^= zobCastle[st->castleRights]; st->castleRights &= castleRightsMask[from] & castleRightsMask[to]; - key ^= zobCastle[st->castleRights]; + k ^= zobCastle[st->castleRights]; } // Prefetch TT access as soon as we know key is updated - prefetch((char*)TT.first_entry(key)); + prefetch((char*)TT.first_entry(k)); // Move the piece Bitboard move_bb = make_move_bb(from, to); @@ -874,7 +874,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI && (attacks_from(from + pawn_push(us), us) & pieces(PAWN, them))) { st->epSquare = Square((from + to) / 2); - key ^= zobEp[st->epSquare]; + k ^= zobEp[st->epSquare]; } if (is_promotion(m)) @@ -899,7 +899,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI pieceList[us][promotion][index[to]] = to; // Update hash keys - key ^= zobrist[us][PAWN][to] ^ zobrist[us][promotion][to]; + k ^= zobrist[us][PAWN][to] ^ zobrist[us][promotion][to]; st->pawnKey ^= zobrist[us][PAWN][to]; st->materialKey ^= zobrist[us][promotion][pieceCount[us][promotion]++] ^ zobrist[us][PAWN][pieceCount[us][PAWN]]; @@ -930,7 +930,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI st->capturedType = capture; // Update the key with the final value - st->key = key; + st->key = k; // Update checkers bitboard, piece must be already moved st->checkersBB = 0; diff --git a/src/position.h b/src/position.h index e1bdf39e..989694be 100644 --- a/src/position.h +++ b/src/position.h @@ -173,10 +173,10 @@ public: int see_sign(Move m) const; // Accessing hash keys - Key get_key() const; - Key get_exclusion_key() const; - Key get_pawn_key() const; - Key get_material_key() const; + Key key() const; + Key exclusion_key() const; + Key pawn_key() const; + Key material_key() const; // Incremental evaluation Score value() const; @@ -394,19 +394,19 @@ inline bool Position::pawn_is_passed(Color c, Square s) const { return !(pieces(PAWN, flip(c)) & passed_pawn_mask(c, s)); } -inline Key Position::get_key() const { +inline Key Position::key() const { return st->key; } -inline Key Position::get_exclusion_key() const { +inline Key Position::exclusion_key() const { return st->key ^ zobExclusion; } -inline Key Position::get_pawn_key() const { +inline Key Position::pawn_key() const { return st->pawnKey; } -inline Key Position::get_material_key() const { +inline Key Position::material_key() const { return st->materialKey; } diff --git a/src/search.cpp b/src/search.cpp index 639cd02a..4cf8f471 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -190,7 +190,7 @@ namespace { MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, Stack* ss, Value b) : MovePicker(p, ttm, d, h, ss, b), mp(ss->sp->mp) {} - Move get_next_move() { return mp->get_next_move(); } + Move next_move() { return mp->next_move(); } MovePicker* mp; }; @@ -653,7 +653,7 @@ namespace { // We don't want the score of a partial search to overwrite a previous full search // TT value, so we use a different position key in case of an excluded move. excludedMove = ss->excludedMove; - posKey = excludedMove ? pos.get_exclusion_key() : pos.get_key(); + posKey = excludedMove ? pos.exclusion_key() : pos.key(); tte = TT.probe(posKey); ttMove = RootNode ? RootMoves[PVIdx].pv[0] : tte ? tte->move() : MOVE_NONE; @@ -816,7 +816,7 @@ namespace { MovePicker mp(pos, ttMove, H, pos.captured_piece_type()); CheckInfo ci(pos); - while ((move = mp.get_next_move()) != MOVE_NONE) + while ((move = mp.next_move()) != MOVE_NONE) if (pos.pl_move_is_legal(move, ci.pinned)) { pos.do_move(move, st, ci, pos.move_gives_check(move, ci)); @@ -867,7 +867,7 @@ split_point_start: // At split points actual search starts from here // Step 11. Loop through moves // Loop through all pseudo-legal moves until no moves remain or a beta cutoff occurs while ( bestValue < beta - && (move = mp.get_next_move()) != MOVE_NONE + && (move = mp.next_move()) != MOVE_NONE && !thread.cutoff_occurred()) { assert(is_ok(move)); @@ -1220,7 +1220,7 @@ split_point_start: // At split points actual search starts from here // Transposition table lookup. At PV nodes, we don't use the TT for // pruning, but only for move ordering. - tte = TT.probe(pos.get_key()); + tte = TT.probe(pos.key()); ttMove = (tte ? tte->move() : MOVE_NONE); if (!PvNode && tte && can_return_tt(tte, ttDepth, beta, ss->ply)) @@ -1252,7 +1252,7 @@ split_point_start: // At split points actual search starts from here if (bestValue >= beta) { if (!tte) - TT.store(pos.get_key(), value_to_tt(bestValue, ss->ply), VALUE_TYPE_LOWER, DEPTH_NONE, MOVE_NONE, ss->eval, evalMargin); + TT.store(pos.key(), value_to_tt(bestValue, ss->ply), VALUE_TYPE_LOWER, DEPTH_NONE, MOVE_NONE, ss->eval, evalMargin); return bestValue; } @@ -1273,7 +1273,7 @@ split_point_start: // At split points actual search starts from here // Loop through the moves until no moves remain or a beta cutoff occurs while ( bestValue < beta - && (move = mp.get_next_move()) != MOVE_NONE) + && (move = mp.next_move()) != MOVE_NONE) { assert(is_ok(move)); @@ -1373,7 +1373,7 @@ split_point_start: // At split points actual search starts from here vt = bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT; - TT.store(pos.get_key(), value_to_tt(bestValue, ss->ply), vt, ttDepth, move, ss->eval, evalMargin); + TT.store(pos.key(), value_to_tt(bestValue, ss->ply), vt, ttDepth, move, ss->eval, evalMargin); assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE); @@ -1602,9 +1602,9 @@ split_point_start: // At split points actual search starts from here static int searchStartTime; if (reset) - searchStartTime = get_system_time(); + searchStartTime = system_time(); - return get_system_time() - searchStartTime; + return system_time() - searchStartTime; } @@ -1768,7 +1768,7 @@ split_point_start: // At split points actual search starts from here static RKISS rk; // PRNG sequence should be not deterministic - for (int i = abs(get_system_time() % 50); i > 0; i--) + for (int i = abs(system_time() % 50); i > 0; i--) rk.rand(); // RootMoves are already sorted by score in descending order @@ -1821,7 +1821,7 @@ split_point_start: // At split points actual search starts from here pv.push_back(m); pos.do_move(m, *st++); - while ( (tte = TT.probe(pos.get_key())) != NULL + while ( (tte = TT.probe(pos.key())) != NULL && tte->move() != MOVE_NONE && pos.is_pseudo_legal(tte->move()) && pos.pl_move_is_legal(tte->move(), pos.pinned_pieces()) @@ -1853,7 +1853,7 @@ split_point_start: // At split points actual search starts from here assert(pv[ply] != MOVE_NONE && pos.is_pseudo_legal(pv[ply])); do { - k = pos.get_key(); + k = pos.key(); tte = TT.probe(k); // Don't overwrite existing correct entries @@ -1971,9 +1971,9 @@ void do_timer_event() { static int lastInfoTime; int e = elapsed_time(); - if (get_system_time() - lastInfoTime >= 1000 || !lastInfoTime) + if (system_time() - lastInfoTime >= 1000 || !lastInfoTime) { - lastInfoTime = get_system_time(); + lastInfoTime = system_time(); dbg_print_mean(); dbg_print_hit_rate(); diff --git a/src/uci.cpp b/src/uci.cpp index 559f8788..b875eaf7 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -117,9 +117,9 @@ void uci_loop() { } else if (token == "key") - cout << "key: " << hex << pos.get_key() - << "\nmaterial key: " << pos.get_material_key() - << "\npawn key: " << pos.get_pawn_key() << endl; + cout << "key: " << hex << pos.key() + << "\nmaterial key: " << pos.material_key() + << "\npawn key: " << pos.pawn_key() << endl; else if (token == "uci") cout << "id name " << engine_name() @@ -251,11 +251,11 @@ namespace { if (!(is >> depth)) return; - time = get_system_time(); + time = system_time(); int64_t n = Search::perft(pos, depth * ONE_PLY); - time = get_system_time() - time; + time = system_time() - time; std::cout << "\nNodes " << n << "\nTime (ms) " << time -- 2.39.2