From cca34e234cc98ed4b61e75a25f8cd0d917c2a3fa Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 28 Sep 2013 05:43:50 -0700 Subject: [PATCH] Drop 'is' prefix from query functions Most but not all. No functional change. --- src/endgame.cpp | 3 +- src/evaluate.cpp | 10 +++---- src/movegen.cpp | 4 +-- src/movepick.cpp | 24 +++++++-------- src/notation.cpp | 8 ++--- src/position.cpp | 72 ++++++++++++++++++++++---------------------- src/position.h | 77 +++++++++++++++++++----------------------------- src/search.cpp | 42 +++++++++++++------------- src/thread.cpp | 8 ++--- src/thread.h | 2 +- 10 files changed, 116 insertions(+), 134 deletions(-) diff --git a/src/endgame.cpp b/src/endgame.cpp index b78d1ba9..b26e0a91 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -627,8 +627,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { Square bksq = pos.king_square(weakerSide); // Does the stronger side have a passed pawn? - if ( pos.pawn_is_passed(strongerSide, wpsq1) - || pos.pawn_is_passed(strongerSide, wpsq2)) + if (pos.pawn_passed(strongerSide, wpsq1) || pos.pawn_passed(strongerSide, wpsq2)) return SCALE_FACTOR_NONE; Rank r = std::max(relative_rank(strongerSide, wpsq1), relative_rank(strongerSide, wpsq2)); diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 63c0f1f8..ec040f63 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -583,9 +583,9 @@ Value do_evaluate(const Position& pos, Value& margin) { const enum Piece P = make_piece(Us, PAWN); Square d = pawn_push(Us) + (file_of(s) == FILE_A ? DELTA_E : DELTA_W); if (pos.piece_on(s + d) == P) - score -= !pos.is_empty(s + d + pawn_push(Us)) ? TrappedBishopA1H1 * 4 - : pos.piece_on(s + d + d) == P ? TrappedBishopA1H1 * 2 - : TrappedBishopA1H1; + score -= !pos.empty(s + d + pawn_push(Us)) ? TrappedBishopA1H1 * 4 + : pos.piece_on(s + d + d) == P ? TrappedBishopA1H1 * 2 + : TrappedBishopA1H1; } } @@ -797,7 +797,7 @@ Value do_evaluate(const Position& pos, Value& margin) { { Square s = pop_lsb(&b); - assert(pos.pawn_is_passed(Us, s)); + assert(pos.pawn_passed(Us, s)); int r = int(relative_rank(Us, s) - RANK_2); int rr = r * (r - 1); @@ -819,7 +819,7 @@ Value do_evaluate(const Position& pos, Value& margin) { ebonus -= Value(square_distance(pos.king_square(Us), blockSq + pawn_push(Us)) * rr); // If the pawn is free to advance, increase bonus - if (pos.is_empty(blockSq)) + if (pos.empty(blockSq)) { squaresToQueen = forward_bb(Us, s); diff --git a/src/movegen.cpp b/src/movegen.cpp index fab5e461..03bc7a09 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -61,7 +61,7 @@ namespace { (mlist++)->move = make(kfrom, rfrom); - if (Checks && !pos.move_gives_check((mlist - 1)->move, CheckInfo(pos))) + if (Checks && !pos.gives_check((mlist - 1)->move, CheckInfo(pos))) mlist--; return mlist; @@ -414,7 +414,7 @@ ExtMove* generate(const Position& pos, ExtMove* mlist) { : generate(pos, mlist); while (cur != end) if ( (pinned || from_sq(cur->move) == ksq || type_of(cur->move) == ENPASSANT) - && !pos.pl_move_is_legal(cur->move, pinned)) + && !pos.legal(cur->move, pinned)) cur->move = (--end)->move; else cur++; diff --git a/src/movepick.cpp b/src/movepick.cpp index 643c8368..e2428554 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -86,7 +86,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& else stage = MAIN_SEARCH; - ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE); + ttMove = (ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE); end += (ttMove != MOVE_NONE); } @@ -108,7 +108,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& // Skip TT move if is not a capture or a promotion, this avoids qsearch // tree explosion due to a possible perpetual check or similar rare cases // when TT table is full. - if (ttm && !pos.is_capture_or_promotion(ttm)) + if (ttm && !pos.capture_or_promotion(ttm)) ttm = MOVE_NONE; } else @@ -118,7 +118,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& ttm = MOVE_NONE; } - ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE); + ttMove = (ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE); end += (ttMove != MOVE_NONE); } @@ -131,9 +131,9 @@ MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, Piece // In ProbCut we generate only captures better than parent's captured piece captureThreshold = PieceValue[MG][pt]; - ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE); + ttMove = (ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE); - if (ttMove && (!pos.is_capture(ttMove) || pos.see(ttMove) <= captureThreshold)) + if (ttMove && (!pos.capture(ttMove) || pos.see(ttMove) <= captureThreshold)) ttMove = MOVE_NONE; end += (ttMove != MOVE_NONE); @@ -163,7 +163,7 @@ void MovePicker::score() { { m = it->move; it->score = PieceValue[MG][pos.piece_on(to_sq(m))] - - type_of(pos.piece_moved(m)); + - type_of(pos.moved_piece(m)); if (type_of(m) == PROMOTION) it->score += PieceValue[MG][promotion_type(m)] - PieceValue[MG][PAWN]; @@ -181,7 +181,7 @@ void MovePicker::score() { for (ExtMove* it = moves; it != end; ++it) { m = it->move; - it->score = history[pos.piece_moved(m)][to_sq(m)]; + it->score = history[pos.moved_piece(m)][to_sq(m)]; } } @@ -199,11 +199,11 @@ void MovePicker::score() { if ((seeScore = pos.see_sign(m)) < 0) it->score = seeScore - HistoryStats::Max; // At the bottom - else if (pos.is_capture(m)) + else if (pos.capture(m)) it->score = PieceValue[MG][pos.piece_on(to_sq(m))] - - type_of(pos.piece_moved(m)) + HistoryStats::Max; + - type_of(pos.moved_piece(m)) + HistoryStats::Max; else - it->score = history[pos.piece_moved(m)][to_sq(m)]; + it->score = history[pos.moved_piece(m)][to_sq(m)]; } } @@ -317,9 +317,9 @@ Move MovePicker::next_move() { case KILLERS_S1: move = (cur++)->move; if ( move != MOVE_NONE - && pos.is_pseudo_legal(move) + && pos.pseudo_legal(move) && move != ttMove - && !pos.is_capture(move)) + && !pos.capture(move)) return move; break; diff --git a/src/notation.cpp b/src/notation.cpp index c96b9dbe..06573c78 100644 --- a/src/notation.cpp +++ b/src/notation.cpp @@ -133,7 +133,7 @@ const string move_to_san(Position& pos, Move m) { while (b) { Move move = make_move(pop_lsb(&b), to); - if (!pos.pl_move_is_legal(move, pos.pinned_pieces())) + if (!pos.legal(move, pos.pinned_pieces())) others ^= from_sq(move); } @@ -149,10 +149,10 @@ const string move_to_san(Position& pos, Move m) { san += square_to_string(from); } } - else if (pos.is_capture(m)) + else if (pos.capture(m)) san = file_to_char(file_of(from)); - if (pos.is_capture(m)) + if (pos.capture(m)) san += 'x'; san += square_to_string(to); @@ -161,7 +161,7 @@ const string move_to_san(Position& pos, Move m) { san += string("=") + PieceToChar[WHITE][promotion_type(m)]; } - if (pos.move_gives_check(m, CheckInfo(pos))) + if (pos.gives_check(m, CheckInfo(pos))) { StateInfo st; pos.do_move(m, st); diff --git a/src/position.cpp b/src/position.cpp index 4cb7e306..28b39c8d 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -340,11 +340,11 @@ const string Position::fen() const { { Square sq = file | rank; - if (is_empty(sq)) + if (empty(sq)) { int emptyCnt = 1; - for ( ; file < FILE_H && is_empty(++sq); ++file) + for ( ; file < FILE_H && empty(++sq); ++file) emptyCnt++; ss << emptyCnt; @@ -472,9 +472,9 @@ Bitboard Position::attacks_from(Piece p, Square s, Bitboard occ) { } -/// Position::pl_move_is_legal() tests whether a pseudo-legal move is legal +/// Position::legal() tests whether a pseudo-legal move is legal -bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { +bool Position::legal(Move m, Bitboard pinned) const { assert(is_ok(m)); assert(pinned == pinned_pieces()); @@ -482,7 +482,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { Color us = sideToMove; Square from = from_sq(m); - assert(color_of(piece_moved(m)) == us); + assert(color_of(moved_piece(m)) == us); assert(piece_on(king_square(us)) == make_piece(us, KING)); // En passant captures are a tricky special case. Because they are rather @@ -497,7 +497,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { Bitboard b = (pieces() ^ from ^ capsq) | to; assert(to == ep_square()); - assert(piece_moved(m) == make_piece(us, PAWN)); + assert(moved_piece(m) == make_piece(us, PAWN)); assert(piece_on(capsq) == make_piece(them, PAWN)); assert(piece_on(to) == NO_PIECE); @@ -519,16 +519,16 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { } -/// Position::is_pseudo_legal() takes a random move and tests whether the move -/// is pseudo legal. It is used to validate moves from TT that can be corrupted +/// Position::pseudo_legal() takes a random move and tests whether the move is +/// pseudo legal. It is used to validate moves from TT that can be corrupted /// due to SMP concurrent access or hash position key aliasing. -bool Position::is_pseudo_legal(const Move m) const { +bool Position::pseudo_legal(const Move m) const { Color us = sideToMove; Square from = from_sq(m); Square to = to_sq(m); - Piece pc = piece_moved(m); + Piece pc = moved_piece(m); // Use a slower but simpler function for uncommon cases if (type_of(m) != NORMAL) @@ -581,7 +581,7 @@ bool Position::is_pseudo_legal(const Move m) const { case DELTA_N: case DELTA_S: // Pawn push. The destination square must be empty. - if (!is_empty(to)) + if (!empty(to)) return false; break; @@ -590,8 +590,8 @@ bool Position::is_pseudo_legal(const Move m) const { // rank, and both the destination square and the square between the // source and destination squares must be empty. if ( rank_of(to) != RANK_4 - || !is_empty(to) - || !is_empty(from + DELTA_N)) + || !empty(to) + || !empty(from + DELTA_N)) return false; break; @@ -600,8 +600,8 @@ bool Position::is_pseudo_legal(const Move m) const { // rank, and both the destination square and the square between the // source and destination squares must be empty. if ( rank_of(to) != RANK_5 - || !is_empty(to) - || !is_empty(from + DELTA_S)) + || !empty(to) + || !empty(from + DELTA_S)) return false; break; @@ -639,11 +639,11 @@ bool Position::is_pseudo_legal(const Move m) const { /// Position::move_gives_check() tests whether a pseudo-legal move gives a check -bool Position::move_gives_check(Move m, const CheckInfo& ci) const { +bool Position::gives_check(Move m, const CheckInfo& ci) const { assert(is_ok(m)); assert(ci.dcCandidates == discovered_check_candidates()); - assert(color_of(piece_moved(m)) == sideToMove); + assert(color_of(moved_piece(m)) == sideToMove); Square from = from_sq(m); Square to = to_sq(m); @@ -710,7 +710,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const { void Position::do_move(Move m, StateInfo& newSt) { CheckInfo ci(*this); - do_move(m, newSt, ci, move_gives_check(m, ci)); + do_move(m, newSt, ci, gives_check(m, ci)); } void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck) { @@ -744,11 +744,11 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI Square to = to_sq(m); Piece pc = piece_on(from); PieceType pt = type_of(pc); - PieceType capture = type_of(m) == ENPASSANT ? PAWN : type_of(piece_on(to)); + PieceType captured = type_of(m) == ENPASSANT ? PAWN : type_of(piece_on(to)); assert(color_of(pc) == us); assert(piece_on(to) == NO_PIECE || color_of(piece_on(to)) == them || type_of(m) == CASTLE); - assert(capture != KING); + assert(captured != KING); if (type_of(m) == CASTLE) { @@ -758,7 +758,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI Square rfrom = to; // Castle is encoded as "king captures friendly rook" Square rto = relative_square(us, kingSide ? SQ_F1 : SQ_D1); to = relative_square(us, kingSide ? SQ_G1 : SQ_C1); - capture = NO_PIECE_TYPE; + captured = NO_PIECE_TYPE; do_castle(from, to, rfrom, rto); @@ -766,13 +766,13 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI k ^= Zobrist::psq[us][ROOK][rfrom] ^ Zobrist::psq[us][ROOK][rto]; } - if (capture) + if (captured) { Square capsq = to; // If the captured piece is a pawn, update pawn hash key, otherwise // update non-pawn material. - if (capture == PAWN) + if (captured == PAWN) { if (type_of(m) == ENPASSANT) { @@ -790,18 +790,18 @@ 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][capture]; + st->npMaterial[them] -= PieceValue[MG][captured]; // Update board and piece lists - remove_piece(capsq, them, capture); + remove_piece(capsq, them, captured); // Update material hash key and prefetch access to materialTable - k ^= Zobrist::psq[them][capture][capsq]; - st->materialKey ^= Zobrist::psq[them][capture][pieceCount[them][capture]]; + k ^= Zobrist::psq[them][captured][capsq]; + st->materialKey ^= Zobrist::psq[them][captured][pieceCount[them][captured]]; prefetch((char*)thisThread->materialTable[st->materialKey]); // Update incremental scores - st->psq -= psq[them][capture][capsq]; + st->psq -= psq[them][captured][capsq]; // Reset rule 50 counter st->rule50 = 0; @@ -878,7 +878,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI st->psq += psq[us][pt][to] - psq[us][pt][from]; // Set capture piece - st->capturedType = capture; + st->capturedType = captured; // Update the key with the final value st->key = k; @@ -928,10 +928,10 @@ void Position::undo_move(Move m) { Square from = from_sq(m); Square to = to_sq(m); PieceType pt = type_of(piece_on(to)); - PieceType capture = st->capturedType; + PieceType captured = st->capturedType; - assert(is_empty(from) || type_of(m) == CASTLE); - assert(capture != KING); + assert(empty(from) || type_of(m) == CASTLE); + assert(captured != KING); if (type_of(m) == PROMOTION) { @@ -952,14 +952,14 @@ void Position::undo_move(Move m) { Square rfrom = to; // Castle is encoded as "king captures friendly rook" Square rto = relative_square(us, kingSide ? SQ_F1 : SQ_D1); to = relative_square(us, kingSide ? SQ_G1 : SQ_C1); - capture = NO_PIECE_TYPE; + captured = NO_PIECE_TYPE; pt = KING; do_castle(to, from, rto, rfrom); } else move_piece(to, from, us, pt); // Put the piece back at the source square - if (capture) + if (captured) { Square capsq = to; @@ -973,7 +973,7 @@ void Position::undo_move(Move m) { assert(piece_on(capsq) == NO_PIECE); } - put_piece(capsq, them, capture); // Restore the captured piece + put_piece(capsq, them, captured); // Restore the captured piece } // Finally point our state pointer back to the previous state @@ -1049,7 +1049,7 @@ int Position::see_sign(Move m) const { // Early return if SEE cannot be negative because captured piece value // is not less then capturing one. Note that king moves always return // here because king midgame value is set to 0. - if (PieceValue[MG][piece_moved(m)] <= PieceValue[MG][piece_on(to_sq(m))]) + if (PieceValue[MG][moved_piece(m)] <= PieceValue[MG][piece_on(to_sq(m))]) return 1; return see(m); diff --git a/src/position.h b/src/position.h index bf387dc6..9dd9e79e 100644 --- a/src/position.h +++ b/src/position.h @@ -43,10 +43,10 @@ struct CheckInfo { }; -/// The StateInfo struct stores information we need to restore a Position +/// The StateInfo struct stores information needed to restore a Position /// object to its previous state when we retract a move. Whenever a move -/// is made on the board (by calling Position::do_move), a StateInfo object -/// must be passed as a parameter. +/// is made on the board (by calling Position::do_move), a StateInfo +/// object must be passed as a parameter. struct StateInfo { Key pawnKey, materialKey; @@ -67,27 +67,10 @@ struct StateInfo { const size_t StateCopySize64 = offsetof(StateInfo, key) / sizeof(uint64_t) + 1; -/// The position data structure. A position consists of the following data: -/// -/// * For each piece type, a bitboard representing the squares occupied -/// by pieces of that type. -/// * For each color, a bitboard representing the squares occupied by -/// pieces of that color. -/// * A bitboard of all occupied squares. -/// * A bitboard of all checking pieces. -/// * A 64-entry array of pieces, indexed by the squares of the board. -/// * The current side to move. -/// * Information about the castling rights for both sides. -/// * The initial files of the kings and both pairs of rooks. This is -/// used to implement the Chess960 castling rules. -/// * The en passant square (which is SQ_NONE if no en passant capture is -/// possible). -/// * The squares of the kings for both sides. -/// * Hash keys for the position itself, the current pawn structure, and -/// the current material situation. -/// * Hash keys for all previous positions in the game for detecting -/// repetition draws. -/// * A counter for detecting 50 move rule draws. +/// The Position class stores the information regarding the board representation +/// like pieces, side to move, hash keys, castling info, etc. The most important +/// methods are do_move() and undo_move(), used by the search to update node info +/// when traversing the search tree. class Position { public: @@ -112,7 +95,7 @@ public: Piece piece_on(Square s) const; Square king_square(Color c) const; Square ep_square() const; - bool is_empty(Square s) const; + bool empty(Square s) const; template int count(Color c) const; template const Square* list(Color c) const; @@ -136,20 +119,20 @@ public: template Bitboard attacks_from(Square s, Color c) const; // Properties of moves - bool move_gives_check(Move m, const CheckInfo& ci) const; - bool pl_move_is_legal(Move m, Bitboard pinned) const; - bool is_pseudo_legal(const Move m) const; - bool is_capture(Move m) const; - bool is_capture_or_promotion(Move m) const; - bool is_passed_pawn_push(Move m) const; - Piece piece_moved(Move m) const; + bool legal(Move m, Bitboard pinned) const; + bool pseudo_legal(const Move m) const; + bool capture(Move m) const; + bool capture_or_promotion(Move m) const; + bool gives_check(Move m, const CheckInfo& ci) const; + bool passed_pawn_push(Move m) const; + Piece moved_piece(Move m) const; PieceType captured_piece_type() const; // Piece specific - bool pawn_is_passed(Color c, Square s) const; + bool pawn_passed(Color c, Square s) const; bool pawn_on_7th(Color c) const; - bool opposite_bishops() const; bool bishop_pair(Color c) const; + bool opposite_bishops() const; // Doing and undoing moves void do_move(Move m, StateInfo& st); @@ -239,11 +222,11 @@ inline Piece Position::piece_on(Square s) const { return board[s]; } -inline Piece Position::piece_moved(Move m) const { +inline Piece Position::moved_piece(Move m) const { return board[from_sq(m)]; } -inline bool Position::is_empty(Square s) const { +inline bool Position::empty(Square s) const { return board[s] == NO_PIECE; } @@ -340,10 +323,16 @@ inline Bitboard Position::pinned_pieces() const { return hidden_checkers(king_square(sideToMove), ~sideToMove); } -inline bool Position::pawn_is_passed(Color c, Square s) const { +inline bool Position::pawn_passed(Color c, Square s) const { return !(pieces(~c, PAWN) & passed_pawn_mask(c, s)); } +inline bool Position::passed_pawn_push(Move m) const { + + return type_of(moved_piece(m)) == PAWN + && pawn_passed(sideToMove, to_sq(m)); +} + inline Key Position::key() const { return st->key; } @@ -364,12 +353,6 @@ inline Value Position::non_pawn_material(Color c) const { return st->npMaterial[c]; } -inline bool Position::is_passed_pawn_push(Move m) const { - - return type_of(piece_moved(m)) == PAWN - && pawn_is_passed(sideToMove, to_sq(m)); -} - inline int Position::game_ply() const { return gamePly; } @@ -395,17 +378,17 @@ inline bool Position::is_chess960() const { return chess960; } -inline bool Position::is_capture_or_promotion(Move m) const { +inline bool Position::capture_or_promotion(Move m) const { assert(is_ok(m)); - return type_of(m) ? type_of(m) != CASTLE : !is_empty(to_sq(m)); + return type_of(m) ? type_of(m) != CASTLE : !empty(to_sq(m)); } -inline bool Position::is_capture(Move m) const { +inline bool Position::capture(Move m) const { // Note that castle is coded as "king captures the rook" assert(is_ok(m)); - return (!is_empty(to_sq(m)) && type_of(m) != CASTLE) || type_of(m) == ENPASSANT; + return (!empty(to_sq(m)) && type_of(m) != CASTLE) || type_of(m) == ENPASSANT; } inline PieceType Position::captured_piece_type() const { diff --git a/src/search.cpp b/src/search.cpp index 789492fd..5ef8bc7f 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -170,7 +170,7 @@ static size_t perft(Position& pos, Depth depth) { for (MoveList it(pos); *it; ++it) { - pos.do_move(*it, st, ci, pos.move_gives_check(*it, ci)); + pos.do_move(*it, st, ci, pos.gives_check(*it, ci)); cnt += leaf ? MoveList(pos).size() : ::perft(pos, depth - ONE_PLY); pos.undo_move(*it); } @@ -584,7 +584,7 @@ namespace { if ( ttValue >= beta && ttMove - && !pos.is_capture_or_promotion(ttMove) + && !pos.capture_or_promotion(ttMove) && ttMove != ss->killers[0]) { ss->killers[1] = ss->killers[0]; @@ -738,10 +738,10 @@ namespace { CheckInfo ci(pos); while ((move = mp.next_move()) != MOVE_NONE) - if (pos.pl_move_is_legal(move, ci.pinned)) + if (pos.legal(move, ci.pinned)) { ss->currentMove = move; - pos.do_move(move, st, ci, pos.move_gives_check(move, ci)); + pos.do_move(move, st, ci, pos.gives_check(move, ci)); value = -search(pos, ss+1, -rbeta, -rbeta+1, rdepth, !cutNode); pos.undo_move(move); if (value >= rbeta) @@ -803,7 +803,7 @@ moves_loop: // When in check and at SpNode search starts from here if (SpNode) { // Shared counter cannot be decremented later if move turns out to be illegal - if (!pos.pl_move_is_legal(move, ci.pinned)) + if (!pos.legal(move, ci.pinned)) continue; moveCount = ++splitPoint->moveCount; @@ -823,10 +823,10 @@ moves_loop: // When in check and at SpNode search starts from here } ext = DEPTH_ZERO; - captureOrPromotion = pos.is_capture_or_promotion(move); - givesCheck = pos.move_gives_check(move, ci); + captureOrPromotion = pos.capture_or_promotion(move); + givesCheck = pos.gives_check(move, ci); dangerous = givesCheck - || pos.is_passed_pawn_push(move) + || pos.passed_pawn_push(move) || type_of(move) == CASTLE; // Step 12. Extend checks @@ -841,7 +841,7 @@ moves_loop: // When in check and at SpNode search starts from here if ( singularExtensionNode && move == ttMove && !ext - && pos.pl_move_is_legal(move, ci.pinned) + && pos.legal(move, ci.pinned) && abs(ttValue) < VALUE_KNOWN_WIN) { assert(ttValue != VALUE_NONE); @@ -884,7 +884,7 @@ moves_loop: // When in check and at SpNode search starts from here // but fixing this made program slightly weaker. Depth predictedDepth = newDepth - reduction(improving, depth, moveCount); futilityValue = ss->staticEval + ss->evalMargin + futility_margin(predictedDepth, moveCount) - + Gains[pos.piece_moved(move)][to_sq(move)]; + + Gains[pos.moved_piece(move)][to_sq(move)]; if (futilityValue < beta) { @@ -917,7 +917,7 @@ moves_loop: // When in check and at SpNode search starts from here ss->futilityMoveCount = 0; // Check for legality only before to do the move - if (!RootNode && !SpNode && !pos.pl_move_is_legal(move, ci.pinned)) + if (!RootNode && !SpNode && !pos.legal(move, ci.pinned)) { moveCount--; continue; @@ -1088,7 +1088,7 @@ moves_loop: // When in check and at SpNode search starts from here // Quiet best move: update killers, history and countermoves if ( bestValue >= beta - && !pos.is_capture_or_promotion(bestMove) + && !pos.capture_or_promotion(bestMove) && !inCheck) { if (ss->killers[0] != bestMove) @@ -1100,11 +1100,11 @@ moves_loop: // When in check and at SpNode search starts from here // Increase history value of the cut-off move and decrease all the other // played non-capture moves. Value bonus = Value(int(depth) * int(depth)); - History.update(pos.piece_moved(bestMove), to_sq(bestMove), bonus); + History.update(pos.moved_piece(bestMove), to_sq(bestMove), bonus); for (int i = 0; i < quietCount - 1; ++i) { Move m = quietsSearched[i]; - History.update(pos.piece_moved(m), to_sq(m), -bonus); + History.update(pos.moved_piece(m), to_sq(m), -bonus); } if (is_ok((ss-1)->currentMove)) @@ -1220,7 +1220,7 @@ moves_loop: // When in check and at SpNode search starts from here { assert(is_ok(move)); - givesCheck = pos.move_gives_check(move, ci); + givesCheck = pos.gives_check(move, ci); // Futility pruning if ( !PvNode @@ -1229,7 +1229,7 @@ moves_loop: // When in check and at SpNode search starts from here && move != ttMove && type_of(move) != PROMOTION && futilityBase > -VALUE_KNOWN_WIN - && !pos.is_passed_pawn_push(move)) + && !pos.passed_pawn_push(move)) { futilityValue = futilityBase + PieceValue[EG][pos.piece_on(to_sq(move))] @@ -1254,7 +1254,7 @@ moves_loop: // When in check and at SpNode search starts from here // Detect non-capture evasions that are candidate to be pruned evasionPrunable = InCheck && bestValue > VALUE_MATED_IN_MAX_PLY - && !pos.is_capture(move) + && !pos.capture(move) && !pos.can_castle(pos.side_to_move()); // Don't search moves with negative SEE values @@ -1266,7 +1266,7 @@ moves_loop: // When in check and at SpNode search starts from here continue; // Check for legality only before to do the move - if (!pos.pl_move_is_legal(move, ci.pinned)) + if (!pos.legal(move, ci.pinned)) continue; ss->currentMove = move; @@ -1406,7 +1406,7 @@ moves_loop: // When in check and at SpNode search starts from here // If the threatened piece has value less than or equal to the value of the // threat piece, don't prune moves which defend it. - if ( pos.is_capture(second) + if ( pos.capture(second) && ( PieceValue[MG][pos.piece_on(m2from)] >= PieceValue[MG][pos.piece_on(m2to)] || type_of(pos.piece_on(m2from)) == KING)) { @@ -1547,8 +1547,8 @@ void RootMove::extract_pv_from_tt(Position& pos) { tte = TT.probe(pos.key()); } while ( tte - && pos.is_pseudo_legal(m = tte->move()) // Local copy, TT could change - && pos.pl_move_is_legal(m, pos.pinned_pieces()) + && pos.pseudo_legal(m = tte->move()) // Local copy, TT could change + && pos.legal(m, pos.pinned_pieces()) && ply < MAX_PLY && (!pos.is_draw() || ply < 2)); diff --git a/src/thread.cpp b/src/thread.cpp index 7d85db86..782537d7 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -157,14 +157,14 @@ bool Thread::cutoff_occurred() const { } -// Thread::is_available_to() checks whether the thread is available to help the +// Thread::available_to() checks whether the thread is available to help the // thread 'master' at a split point. An obvious requirement is that thread must // be idle. With more than two threads, this is not sufficient: If the thread is // the master of some split point, it is only available as a slave to the slaves // which are busy searching the split point at the top of slaves split point // stack (the "helpful master concept" in YBWC terminology). -bool Thread::is_available_to(const Thread* master) const { +bool Thread::available_to(const Thread* master) const { if (searching) return false; @@ -241,7 +241,7 @@ void ThreadPool::read_uci_options() { Thread* ThreadPool::available_slave(const Thread* master) const { for (const_iterator it = begin(); it != end(); ++it) - if ((*it)->is_available_to(master)) + if ((*it)->available_to(master)) return *it; return NULL; @@ -330,7 +330,7 @@ void Thread::split(Position& pos, const Stack* ss, Value alpha, Value beta, Valu // We have returned from the idle loop, which means that all threads are // finished. Note that setting 'searching' and decreasing splitPointsSize is - // done under lock protection to avoid a race with Thread::is_available_to(). + // done under lock protection to avoid a race with Thread::available_to(). Threads.mutex.lock(); sp.mutex.lock(); } diff --git a/src/thread.h b/src/thread.h index 56d000f3..d3dd1867 100644 --- a/src/thread.h +++ b/src/thread.h @@ -114,7 +114,7 @@ struct Thread : public ThreadBase { Thread(); virtual void idle_loop(); bool cutoff_occurred() const; - bool is_available_to(const Thread* master) const; + bool available_to(const Thread* master) const; template void split(Position& pos, const Search::Stack* ss, Value alpha, Value beta, Value* bestValue, Move* bestMove, -- 2.39.2