From e82382703c96cfc480555e9db29d999e1f54a38f Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Tue, 25 Dec 2012 17:59:35 +0100 Subject: [PATCH] Retire Position::in_check() It is redundant with Position::checkers() No functional change. --- src/endgame.cpp | 2 +- src/evaluate.cpp | 4 ++-- src/movegen.cpp | 10 +++++----- src/movepick.cpp | 6 +++--- src/position.cpp | 6 +++--- src/position.h | 5 ----- src/search.cpp | 6 +++--- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/endgame.cpp b/src/endgame.cpp index c0d317b7..d60ce396 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -133,7 +133,7 @@ Value Endgame::operator()(const Position& pos) const { // Stalemate detection with lone king if ( pos.side_to_move() == weakerSide - && !pos.in_check() + && !pos.checkers() && !MoveList(pos).size()) { return VALUE_DRAW; } diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 8d9d01a7..1f396f75 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -361,7 +361,7 @@ namespace { template Value do_evaluate(const Position& pos, Value& margin) { - assert(!pos.in_check()); + assert(!pos.checkers()); EvalInfo ei; Score score, mobilityWhite, mobilityBlack; @@ -1014,7 +1014,7 @@ Value do_evaluate(const Position& pos, Value& margin) { // Opponent king cannot block because path is defended and position // is not in check. So only friendly pieces can be blockers. - assert(!pos.in_check()); + assert(!pos.checkers()); assert((queeningPath & pos.pieces()) == (queeningPath & pos.pieces(c))); // Add moves needed to free the path from friendly pieces and retest condition diff --git a/src/movegen.cpp b/src/movegen.cpp index be848cf1..3848611c 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -44,7 +44,7 @@ namespace { Square kto = relative_square(us, Side == KING_SIDE ? SQ_G1 : SQ_C1); Bitboard enemies = pos.pieces(~us); - assert(!pos.in_check()); + assert(!pos.checkers()); const int K = Chess960 ? kto > kfrom ? -1 : 1 : Side == KING_SIDE ? -1 : 1; @@ -307,7 +307,7 @@ template MoveStack* generate(const Position& pos, MoveStack* mlist) { assert(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS); - assert(!pos.in_check()); + assert(!pos.checkers()); Color us = pos.side_to_move(); Bitboard target; @@ -335,7 +335,7 @@ template MoveStack* generate(const Position&, MoveStack*); template<> MoveStack* generate(const Position& pos, MoveStack* mlist) { - assert(!pos.in_check()); + assert(!pos.checkers()); Color us = pos.side_to_move(); CheckInfo ci(pos); @@ -366,7 +366,7 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { template<> MoveStack* generate(const Position& pos, MoveStack* mlist) { - assert(pos.in_check()); + assert(pos.checkers()); Square from, checksq; int checkersCnt = 0; @@ -432,7 +432,7 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { Bitboard pinned = pos.pinned_pieces(); Square ksq = pos.king_square(pos.side_to_move()); - end = pos.in_check() ? generate(pos, mlist) + end = pos.checkers() ? generate(pos, mlist) : generate(pos, mlist); while (cur != end) if ( (pinned || from_sq(cur->move) == ksq || type_of(cur->move) == ENPASSANT) diff --git a/src/movepick.cpp b/src/movepick.cpp index ba99df0d..794fbde9 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -68,7 +68,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, endBadCaptures = moves + MAX_MOVES - 1; ss = s; - if (p.in_check()) + if (p.checkers()) phase = EVASION; else @@ -96,7 +96,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, assert(d <= DEPTH_ZERO); - if (p.in_check()) + if (p.checkers()) phase = EVASION; else if (d > DEPTH_QS_NO_CHECKS) @@ -126,7 +126,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, MovePicker::MovePicker(const Position& p, Move ttm, const History& h, PieceType pt) : pos(p), H(h), cur(moves), end(moves) { - assert(!pos.in_check()); + assert(!pos.checkers()); phase = PROBCUT; diff --git a/src/position.cpp b/src/position.cpp index ef5fd970..e69528ad 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -617,7 +617,7 @@ bool Position::is_pseudo_legal(const Move m) const { // Evasions generator already takes care to avoid some kind of illegal moves // and pl_move_is_legal() relies on this. So we have to take care that the // same kind of moves are filtered out here. - if (in_check()) + if (checkers()) { if (type_of(pc) != KING) { @@ -1144,7 +1144,7 @@ void Position::do_castle_move(Move m) { template void Position::do_null_move(StateInfo& backupSt) { - assert(!in_check()); + assert(!checkers()); // Back up the information necessary to undo the null move to the supplied // StateInfo object. Note that differently from normal case here backupSt @@ -1428,7 +1428,7 @@ bool Position::is_draw() const { && (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMg)) return true; - if (st->rule50 > 99 && (!in_check() || MoveList(*this).size())) + if (st->rule50 > 99 && (!checkers() || MoveList(*this).size())) return true; if (CheckRepetition) diff --git a/src/position.h b/src/position.h index e575c3ef..7fb840b6 100644 --- a/src/position.h +++ b/src/position.h @@ -122,7 +122,6 @@ public: Square castle_rook_square(Color c, CastlingSide s) const; // Checking - bool in_check() const; Bitboard checkers() const; Bitboard discovered_check_candidates() const; Bitboard pinned_pieces() const; @@ -330,10 +329,6 @@ inline Bitboard Position::checkers() const { return st->checkersBB; } -inline bool Position::in_check() const { - return st->checkersBB != 0; -} - inline Bitboard Position::discovered_check_candidates() const { return hidden_checkers(); } diff --git a/src/search.cpp b/src/search.cpp index f7d3a9fd..bfcb53c9 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -188,7 +188,7 @@ void Search::think() { { RootMoves.push_back(MOVE_NONE); sync_cout << "info depth 0 score " - << score_to_uci(RootPos.in_check() ? -VALUE_MATE : VALUE_DRAW) + << score_to_uci(RootPos.checkers() ? -VALUE_MATE : VALUE_DRAW) << sync_endl; goto finalize; @@ -491,7 +491,7 @@ namespace { // Step 1. Initialize node Thread* thisThread = pos.this_thread(); moveCount = playedMoveCount = 0; - inCheck = pos.in_check(); + inCheck = pos.checkers(); if (SpNode) { @@ -1081,7 +1081,7 @@ split_point_start: // At split points actual search starts from here const bool PvNode = (NT == PV); assert(NT == PV || NT == NonPV); - assert(InCheck == pos.in_check()); + assert(InCheck == !!pos.checkers()); assert(alpha >= -VALUE_INFINITE && alpha < beta && beta <= VALUE_INFINITE); assert(PvNode || (alpha == beta - 1)); assert(depth <= DEPTH_ZERO); -- 2.39.2