From e0a00c499654850108749ca6fd686f79188ac1f9 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Tue, 28 Jun 2011 16:16:43 +0200 Subject: [PATCH] Retire one piece_list() overload No functional change. Signed-off-by: Marco Costalba --- src/endgame.cpp | 54 ++++++++++++++++++++++++------------------------ src/evaluate.cpp | 4 ++-- src/movegen.cpp | 14 ++++++------- src/pawns.cpp | 4 ++-- src/position.cpp | 4 ++-- src/position.h | 11 +++------- 6 files changed, 43 insertions(+), 48 deletions(-) diff --git a/src/endgame.cpp b/src/endgame.cpp index c8c491fd..c1c703a3 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -196,7 +196,7 @@ Value Endgame::apply(const Position& pos) const { Square winnerKSq = pos.king_square(strongerSide); Square loserKSq = pos.king_square(weakerSide); - Square bishopSquare = pos.piece_list(strongerSide, BISHOP, 0); + Square bishopSquare = pos.piece_list(strongerSide, BISHOP)[0]; // kbnk_mate_table() tries to drive toward corners A1 or H8, // if we have a bishop that cannot reach the above squares we @@ -231,14 +231,14 @@ Value Endgame::apply(const Position& pos) const { { wksq = pos.king_square(WHITE); bksq = pos.king_square(BLACK); - wpsq = pos.piece_list(WHITE, PAWN, 0); + wpsq = pos.piece_list(WHITE, PAWN)[0]; stm = pos.side_to_move(); } else { wksq = flip_square(pos.king_square(BLACK)); bksq = flip_square(pos.king_square(WHITE)); - wpsq = flip_square(pos.piece_list(BLACK, PAWN, 0)); + wpsq = flip_square(pos.piece_list(BLACK, PAWN)[0]); stm = opposite_color(pos.side_to_move()); } @@ -276,9 +276,9 @@ Value Endgame::apply(const Position& pos) const { int tempo = (pos.side_to_move() == strongerSide); wksq = pos.king_square(strongerSide); - wrsq = pos.piece_list(strongerSide, ROOK, 0); + wrsq = pos.piece_list(strongerSide, ROOK)[0]; bksq = pos.king_square(weakerSide); - bpsq = pos.piece_list(weakerSide, PAWN, 0); + bpsq = pos.piece_list(weakerSide, PAWN)[0]; if (strongerSide == BLACK) { @@ -347,7 +347,7 @@ Value Endgame::apply(const Position& pos) const { assert(pos.piece_count(weakerSide, KNIGHT) == 1); Square defendingKSq = pos.king_square(weakerSide); - Square nSq = pos.piece_list(weakerSide, KNIGHT, 0); + Square nSq = pos.piece_list(weakerSide, KNIGHT)[0]; int d = square_distance(defendingKSq, nSq); Value result = Value(10) @@ -394,7 +394,7 @@ Value Endgame::apply(const Position& pos) const { Value result = BishopValueEndgame; Square wksq = pos.king_square(strongerSide); Square bksq = pos.king_square(weakerSide); - Square nsq = pos.piece_list(weakerSide, KNIGHT, 0); + Square nsq = pos.piece_list(weakerSide, KNIGHT)[0]; // Bonus for attacking king close to defending king result += Value(DistanceBonus[square_distance(wksq, bksq)]); @@ -437,13 +437,13 @@ ScaleFactor Endgame::apply(const Position& pos) const { // be detected even when the weaker side has some pawns. Bitboard pawns = pos.pieces(PAWN, strongerSide); - File pawnFile = square_file(pos.piece_list(strongerSide, PAWN, 0)); + File pawnFile = square_file(pos.piece_list(strongerSide, PAWN)[0]); // All pawns are on a single rook file ? if ( (pawnFile == FILE_A || pawnFile == FILE_H) && (pawns & ~file_bb(pawnFile)) == EmptyBoardBB) { - Square bishopSq = pos.piece_list(strongerSide, BISHOP, 0); + Square bishopSq = pos.piece_list(strongerSide, BISHOP)[0]; Square queeningSq = relative_square(strongerSide, make_square(pawnFile, RANK_8)); Square kingSq = pos.king_square(weakerSide); @@ -496,7 +496,7 @@ ScaleFactor Endgame::apply(const Position& pos) const { && (pos.pieces(PAWN, weakerSide) & rank_bb(relative_rank(weakerSide, RANK_2))) && (pos.attacks_from(kingSq) & pos.pieces(PAWN, weakerSide))) { - Square rsq = pos.piece_list(weakerSide, ROOK, 0); + Square rsq = pos.piece_list(weakerSide, ROOK)[0]; if (pos.attacks_from(rsq, strongerSide) & pos.pieces(PAWN, weakerSide)) return SCALE_FACTOR_ZERO; } @@ -520,10 +520,10 @@ ScaleFactor Endgame::apply(const Position& pos) const { assert(pos.piece_count(weakerSide, PAWN) == 0); Square wksq = pos.king_square(strongerSide); - Square wrsq = pos.piece_list(strongerSide, ROOK, 0); - Square wpsq = pos.piece_list(strongerSide, PAWN, 0); + Square wrsq = pos.piece_list(strongerSide, ROOK)[0]; + Square wpsq = pos.piece_list(strongerSide, PAWN)[0]; Square bksq = pos.king_square(weakerSide); - Square brsq = pos.piece_list(weakerSide, ROOK, 0); + Square brsq = pos.piece_list(weakerSide, ROOK)[0]; // Orient the board in such a way that the stronger side is white, and the // pawn is on the left half of the board. @@ -637,8 +637,8 @@ ScaleFactor Endgame::apply(const Position& pos) const { assert(pos.non_pawn_material(weakerSide) == RookValueMidgame); assert(pos.piece_count(weakerSide, PAWN) == 1); - Square wpsq1 = pos.piece_list(strongerSide, PAWN, 0); - Square wpsq2 = pos.piece_list(strongerSide, PAWN, 1); + Square wpsq1 = pos.piece_list(strongerSide, PAWN)[0]; + Square wpsq2 = pos.piece_list(strongerSide, PAWN)[1]; Square bksq = pos.king_square(weakerSide); // Does the stronger side have a passed pawn? @@ -716,9 +716,9 @@ ScaleFactor Endgame::apply(const Position& pos) const { assert(pos.piece_count(weakerSide, BISHOP) == 1); assert(pos.piece_count(weakerSide, PAWN) == 0); - Square pawnSq = pos.piece_list(strongerSide, PAWN, 0); - Square strongerBishopSq = pos.piece_list(strongerSide, BISHOP, 0); - Square weakerBishopSq = pos.piece_list(weakerSide, BISHOP, 0); + Square pawnSq = pos.piece_list(strongerSide, PAWN)[0]; + Square strongerBishopSq = pos.piece_list(strongerSide, BISHOP)[0]; + Square weakerBishopSq = pos.piece_list(weakerSide, BISHOP)[0]; Square weakerKingSq = pos.king_square(weakerSide); // Case 1: Defending king blocks the pawn, and cannot be driven away @@ -771,15 +771,15 @@ ScaleFactor Endgame::apply(const Position& pos) const { assert(pos.piece_count(weakerSide, BISHOP) == 1); assert(pos.piece_count(weakerSide, PAWN) == 0); - Square wbsq = pos.piece_list(strongerSide, BISHOP, 0); - Square bbsq = pos.piece_list(weakerSide, BISHOP, 0); + Square wbsq = pos.piece_list(strongerSide, BISHOP)[0]; + Square bbsq = pos.piece_list(weakerSide, BISHOP)[0]; if (!opposite_color_squares(wbsq, bbsq)) return SCALE_FACTOR_NONE; Square ksq = pos.king_square(weakerSide); - Square psq1 = pos.piece_list(strongerSide, PAWN, 0); - Square psq2 = pos.piece_list(strongerSide, PAWN, 1); + Square psq1 = pos.piece_list(strongerSide, PAWN)[0]; + Square psq2 = pos.piece_list(strongerSide, PAWN)[1]; Rank r1 = square_rank(psq1); Rank r2 = square_rank(psq2); Square blockSq1, blockSq2; @@ -847,8 +847,8 @@ ScaleFactor Endgame::apply(const Position& pos) const { assert(pos.piece_count(weakerSide, KNIGHT) == 1); assert(pos.piece_count(weakerSide, PAWN) == 0); - Square pawnSq = pos.piece_list(strongerSide, PAWN, 0); - Square strongerBishopSq = pos.piece_list(strongerSide, BISHOP, 0); + Square pawnSq = pos.piece_list(strongerSide, PAWN)[0]; + Square strongerBishopSq = pos.piece_list(strongerSide, BISHOP)[0]; Square weakerKingSq = pos.king_square(weakerSide); if ( square_file(weakerKingSq) == square_file(pawnSq) @@ -873,7 +873,7 @@ ScaleFactor Endgame::apply(const Position& pos) const { assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO); assert(pos.piece_count(weakerSide, PAWN) == 0); - Square pawnSq = pos.piece_list(strongerSide, PAWN, 0); + Square pawnSq = pos.piece_list(strongerSide, PAWN)[0]; Square weakerKingSq = pos.king_square(weakerSide); if ( pawnSq == relative_square(strongerSide, SQ_A7) @@ -909,14 +909,14 @@ ScaleFactor Endgame::apply(const Position& pos) const { { wksq = pos.king_square(WHITE); bksq = pos.king_square(BLACK); - wpsq = pos.piece_list(WHITE, PAWN, 0); + wpsq = pos.piece_list(WHITE, PAWN)[0]; stm = pos.side_to_move(); } else { wksq = flip_square(pos.king_square(BLACK)); bksq = flip_square(pos.king_square(WHITE)); - wpsq = flip_square(pos.piece_list(BLACK, PAWN, 0)); + wpsq = flip_square(pos.piece_list(BLACK, PAWN)[0]); stm = opposite_color(pos.side_to_move()); } diff --git a/src/evaluate.cpp b/src/evaluate.cpp index f7ae1977..6ae46f41 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -486,11 +486,11 @@ namespace { const BitCountType Full = HasPopCnt ? CNT_POPCNT : CpuIs64Bit ? CNT64 : CNT32; const BitCountType Max15 = HasPopCnt ? CNT_POPCNT : CpuIs64Bit ? CNT64_MAX15 : CNT32_MAX15; const Color Them = (Us == WHITE ? BLACK : WHITE); - const Square* ptr = pos.piece_list_begin(Us, Piece); + const Square* pl = pos.piece_list(Us, Piece); ei.attackedBy[Us][Piece] = EmptyBoardBB; - while ((s = *ptr++) != SQ_NONE) + while ((s = *pl++) != SQ_NONE) { // Find attacked squares, including x-ray attacks for bishops and rooks if (Piece == KNIGHT || Piece == QUEEN) diff --git a/src/movegen.cpp b/src/movegen.cpp index 9b4cc130..9b41f4f4 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -64,9 +64,9 @@ namespace { Bitboard checkSqs, b; Square from; - const Square* ptr = pos.piece_list_begin(us, Pt); + const Square* pl = pos.piece_list(us, Pt); - if ((from = *ptr++) == SQ_NONE) + if ((from = *pl++) == SQ_NONE) return mlist; checkSqs = pos.attacks_from(ksq) & pos.empty_squares(); @@ -84,7 +84,7 @@ namespace { b = pos.attacks_from(from) & checkSqs; SERIALIZE_MOVES(b); - } while ((from = *ptr++) != SQ_NONE); + } while ((from = *pl++) != SQ_NONE); return mlist; } @@ -111,15 +111,15 @@ namespace { Bitboard b; Square from; - const Square* ptr = pos.piece_list_begin(us, Pt); + const Square* pl = pos.piece_list(us, Pt); - if (*ptr != SQ_NONE) + if (*pl != SQ_NONE) { do { - from = *ptr; + from = *pl; b = pos.attacks_from(from) & target; SERIALIZE_MOVES(b); - } while (*++ptr != SQ_NONE); + } while (*++pl != SQ_NONE); } return mlist; } diff --git a/src/pawns.cpp b/src/pawns.cpp index 3ad88fb2..c099153a 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -127,10 +127,10 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns, Rank r; bool passed, isolated, doubled, opposed, chain, backward, candidate; Score value = SCORE_ZERO; - const Square* ptr = pos.piece_list_begin(Us, PAWN); + const Square* pl = pos.piece_list(Us, PAWN); // Loop through all pawns of the current color and score each pawn - while ((s = *ptr++) != SQ_NONE) + while ((s = *pl++) != SQ_NONE) { assert(pos.piece_on(s) == make_piece(Us, PAWN)); diff --git a/src/position.cpp b/src/position.cpp index eb3cb895..8a902502 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1965,10 +1965,10 @@ 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)) != make_piece(c, pt)) + if (piece_on(piece_list(c, pt)[i]) != make_piece(c, pt)) return false; - if (index[piece_list(c, pt, i)] != i) + if (index[piece_list(c, pt)[i]] != i) return false; } diff --git a/src/position.h b/src/position.h index 9e4a6e4c..e7fc9a2e 100644 --- a/src/position.h +++ b/src/position.h @@ -166,8 +166,7 @@ public: bool in_check() const; // Piece lists - Square piece_list(Color c, PieceType pt, int index) const; - const Square* piece_list_begin(Color c, PieceType pt) const; + const Square* piece_list(Color c, PieceType pt) const; // Information about attacks to or from a given square Bitboard attackers_to(Square s) const; @@ -357,11 +356,7 @@ inline int Position::piece_count(Color c, PieceType pt) const { return pieceCount[c][pt]; } -inline Square Position::piece_list(Color c, PieceType pt, int idx) const { - return pieceList[c][pt][idx]; -} - -inline const Square* Position::piece_list_begin(Color c, PieceType pt) const { +inline const Square* Position::piece_list(Color c, PieceType pt) const { return pieceList[c][pt]; } @@ -472,7 +467,7 @@ inline int Position::full_moves() const { inline bool Position::opposite_colored_bishops() const { return piece_count(WHITE, BISHOP) == 1 && piece_count(BLACK, BISHOP) == 1 - && opposite_color_squares(piece_list(WHITE, BISHOP, 0), piece_list(BLACK, BISHOP, 0)); + && opposite_color_squares(piece_list(WHITE, BISHOP)[0], piece_list(BLACK, BISHOP)[0]); } inline bool Position::has_pawn_on_7th(Color c) const { -- 2.39.2