From 17c511922277e49eacdede3c92491ee32c303c30 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Mon, 31 Aug 2009 16:09:52 +0200 Subject: [PATCH] Retire pieces_of_color_and_type() It is used mainly in a bunch of inline oneliners just below its definition. So substitute it with the explicit definition and avoid information hiding. No functional change. Signed-off-by: Marco Costalba --- src/evaluate.cpp | 2 +- src/movegen.cpp | 2 +- src/position.cpp | 13 +++++++------ src/position.h | 23 +++++++++-------------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 7f7df3c5..a291ec46 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -930,7 +930,7 @@ namespace { b3 |= (b2 & pos.pieces_of_color(them)); // There are no enemy pawns in the pawn's path - assert((b2 & pos.pieces_of_color_and_type(them, PAWN)) == EmptyBoardBB); + assert((b2 & pos.pieces_of_color(them) & pos.pieces_of_type(PAWN)) == EmptyBoardBB); // Are any of the squares in the pawn's path attacked or occupied by the enemy? if (b3 == EmptyBoardBB) diff --git a/src/movegen.cpp b/src/movegen.cpp index bfeb7247..bf8293b1 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -832,7 +832,7 @@ namespace { MoveStack* generate_piece_checks(const Position& pos, MoveStack* mlist, Color us, Bitboard dc, Square ksq) { - Bitboard target = pos.pieces_of_color_and_type(us, Piece); + Bitboard target = pos.pieces_of_color(us) & pos.pieces_of_type(Piece); // Discovered checks Bitboard b = target & dc; diff --git a/src/position.cpp b/src/position.cpp index 0208d2a2..9b8f7798 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1382,11 +1382,12 @@ int Position::see(Square from, Square to) const { // Locate the least valuable attacker to the destination square // and use it to initialize from square. + stmAttackers = attackers & pieces_of_color(us); PieceType pt; - for (pt = PAWN; !(attackers & pieces_of_color_and_type(us, pt)); pt++) + for (pt = PAWN; !(stmAttackers & pieces_of_type(pt)); pt++) assert(pt < KING); - from = first_1(attackers & pieces_of_color_and_type(us, pt)); + from = first_1(stmAttackers & pieces_of_type(pt)); piece = piece_on(from); } @@ -1633,7 +1634,7 @@ Value Position::compute_value() const { for (Color c = WHITE; c <= BLACK; c++) for (PieceType pt = PAWN; pt <= KING; pt++) { - b = pieces_of_color_and_type(c, pt); + b = pieces_of_color(c) & pieces_of_type(pt); while(b) { s = pop_1st_bit(&b); @@ -1659,7 +1660,7 @@ Value Position::compute_non_pawn_material(Color c) const { for (PieceType pt = KNIGHT; pt <= QUEEN; pt++) { - Bitboard b = pieces_of_color_and_type(c, pt); + Bitboard b = pieces_of_color(c) & pieces_of_type(pt); while (b) { assert(piece_on(first_1(b)) == piece_of_color_and_type(c, pt)); @@ -2011,7 +2012,7 @@ bool Position::is_ok(int* failedStep) const { if (debugPieceCounts) for (Color c = WHITE; c <= BLACK; c++) for (PieceType pt = PAWN; pt <= KING; pt++) - if (pieceCount[c][pt] != count_1s(pieces_of_color_and_type(c, pt))) + if (pieceCount[c][pt] != count_1s(pieces_of_color(c) & pieces_of_type(pt))) return false; if (failedStep) (*failedStep)++; @@ -2021,7 +2022,7 @@ bool Position::is_ok(int* failedStep) const { for(PieceType pt = PAWN; pt <= KING; pt++) for(int i = 0; i < pieceCount[c][pt]; i++) { - if (piece_on(piece_list(c, pt, i)) != piece_of_color_and_type(c, pt)) + if (piece_on(piece_list(c, pt, i)) != (pieces_of_color(c) & pieces_of_type(pt))) return false; if (index[piece_list(c, pt, i)] != i) diff --git a/src/position.h b/src/position.h index d1d511d7..16e72519 100644 --- a/src/position.h +++ b/src/position.h @@ -133,7 +133,7 @@ public: }; // Constructors - Position() {}; + Position() {} Position(const Position& pos); Position(const std::string& fen); @@ -163,7 +163,6 @@ public: Bitboard occupied_squares() const; Bitboard pieces_of_color(Color c) const; Bitboard pieces_of_type(PieceType pt) const; - Bitboard pieces_of_color_and_type(Color c, PieceType pt) const; Bitboard pawns() const; Bitboard knights() const; Bitboard bishops() const; @@ -414,10 +413,6 @@ inline Bitboard Position::pieces_of_type(PieceType pt) const { return byTypeBB[pt]; } -inline Bitboard Position::pieces_of_color_and_type(Color c, PieceType pt) const { - return pieces_of_color(c) & pieces_of_type(pt); -} - inline Bitboard Position::pawns() const { return pieces_of_type(PAWN); } @@ -455,35 +450,35 @@ inline Bitboard Position::sliders() const { } inline Bitboard Position::pawns(Color c) const { - return pieces_of_color_and_type(c, PAWN); + return pieces_of_color(c) & pieces_of_type(PAWN); } inline Bitboard Position::knights(Color c) const { - return pieces_of_color_and_type(c, KNIGHT); + return pieces_of_color(c) & pieces_of_type(KNIGHT); } inline Bitboard Position::bishops(Color c) const { - return pieces_of_color_and_type(c, BISHOP); + return pieces_of_color(c) & pieces_of_type(BISHOP); } inline Bitboard Position::rooks(Color c) const { - return pieces_of_color_and_type(c, ROOK); + return pieces_of_color(c) & pieces_of_type(ROOK); } inline Bitboard Position::queens(Color c) const { - return pieces_of_color_and_type(c, QUEEN); + return pieces_of_color(c) & pieces_of_type(QUEEN); } inline Bitboard Position::kings(Color c) const { - return pieces_of_color_and_type(c, KING); + return pieces_of_color(c) & pieces_of_type(KING); } inline Bitboard Position::rooks_and_queens(Color c) const { - return rooks_and_queens() & pieces_of_color(c); + return pieces_of_color(c) & rooks_and_queens(); } inline Bitboard Position::bishops_and_queens(Color c) const { - return bishops_and_queens() & pieces_of_color(c); + return pieces_of_color(c) & bishops_and_queens(); } inline int Position::piece_count(Color c, PieceType pt) const { -- 2.39.2