Rename piece_count and piece_list
authorMarco Costalba <mcostalba@gmail.com>
Sun, 16 Jun 2013 09:59:40 +0000 (11:59 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 16 Jun 2013 11:21:10 +0000 (13:21 +0200)
No functional change.

src/endgame.cpp
src/evaluate.cpp
src/material.cpp
src/movegen.cpp
src/pawns.cpp
src/position.cpp
src/position.h

index 52786cd..cff5e69 100644 (file)
@@ -130,7 +130,7 @@ template<>
 Value Endgame<KXK>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
-  assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO);
+  assert(!pos.count<PAWN>(weakerSide));
 
   // Stalemate detection with lone king
   if (    pos.side_to_move() == weakerSide
@@ -143,12 +143,12 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
   Square loserKSq = pos.king_square(weakerSide);
 
   Value result =   pos.non_pawn_material(strongerSide)
-                 + pos.piece_count(strongerSide, PAWN) * PawnValueEg
+                 + pos.count<PAWN>(strongerSide) * PawnValueEg
                  + MateTable[loserKSq]
                  + DistanceBonus[square_distance(winnerKSq, loserKSq)];
 
-  if (   pos.piece_count(strongerSide, QUEEN)
-      || pos.piece_count(strongerSide, ROOK)
+  if (   pos.count<QUEEN>(strongerSide)
+      || pos.count<ROOK>(strongerSide)
       || pos.bishop_pair(strongerSide)) {
     result += VALUE_KNOWN_WIN;
   }
@@ -162,16 +162,16 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
 template<>
 Value Endgame<KBNK>::operator()(const Position& pos) const {
 
-  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
-  assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO);
   assert(pos.non_pawn_material(strongerSide) == KnightValueMg + BishopValueMg);
-  assert(pos.piece_count(strongerSide, BISHOP) == 1);
-  assert(pos.piece_count(strongerSide, KNIGHT) == 1);
-  assert(pos.piece_count(strongerSide, PAWN) == 0);
+  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
+  assert(pos.count<BISHOP>(strongerSide) == 1);
+  assert(pos.count<KNIGHT>(strongerSide) == 1);
+  assert(pos.count<  PAWN>(strongerSide) == 0);
+  assert(pos.count<  PAWN>(weakerSide  ) == 0);
 
   Square winnerKSq = pos.king_square(strongerSide);
   Square loserKSq = pos.king_square(weakerSide);
-  Square bishopSq = pos.piece_list(strongerSide, BISHOP)[0];
+  Square bishopSq = pos.list<BISHOP>(strongerSide)[0];
 
   // kbnk_mate_table() tries to drive toward corners A1 or H8,
   // if we have a bishop that cannot reach the above squares we
@@ -196,8 +196,8 @@ Value Endgame<KPK>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
   assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
-  assert(pos.piece_count(strongerSide, PAWN) == 1);
-  assert(pos.piece_count(weakerSide, PAWN) == 0);
+  assert(pos.count<PAWN>(strongerSide) == 1);
+  assert(pos.count<PAWN>(weakerSide  ) == 0);
 
   Square wksq, bksq, wpsq;
   Color us;
@@ -206,14 +206,14 @@ Value Endgame<KPK>::operator()(const Position& pos) const {
   {
       wksq = pos.king_square(WHITE);
       bksq = pos.king_square(BLACK);
-      wpsq = pos.piece_list(WHITE, PAWN)[0];
+      wpsq = pos.list<PAWN>(WHITE)[0];
       us   = pos.side_to_move();
   }
   else
   {
       wksq = ~pos.king_square(BLACK);
       bksq = ~pos.king_square(WHITE);
-      wpsq = ~pos.piece_list(BLACK, PAWN)[0];
+      wpsq = ~pos.list<PAWN>(BLACK)[0];
       us   = ~pos.side_to_move();
   }
 
@@ -241,17 +241,17 @@ template<>
 Value Endgame<KRKP>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == RookValueMg);
-  assert(pos.piece_count(strongerSide, PAWN) == 0);
   assert(pos.non_pawn_material(weakerSide) == 0);
-  assert(pos.piece_count(weakerSide, PAWN) == 1);
+  assert(pos.count<PAWN>(strongerSide) == 0);
+  assert(pos.count<PAWN>(weakerSide  ) == 1);
 
   Square wksq, wrsq, bksq, bpsq;
   int tempo = (pos.side_to_move() == strongerSide);
 
   wksq = pos.king_square(strongerSide);
-  wrsq = pos.piece_list(strongerSide, ROOK)[0];
   bksq = pos.king_square(weakerSide);
-  bpsq = pos.piece_list(weakerSide, PAWN)[0];
+  wrsq = pos.list<ROOK>(strongerSide)[0];
+  bpsq = pos.list<PAWN>(weakerSide)[0];
 
   if (strongerSide == BLACK)
   {
@@ -298,10 +298,10 @@ template<>
 Value Endgame<KRKB>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == RookValueMg);
-  assert(pos.piece_count(strongerSide, PAWN) == 0);
-  assert(pos.non_pawn_material(weakerSide) == BishopValueMg);
-  assert(pos.piece_count(weakerSide, PAWN) == 0);
-  assert(pos.piece_count(weakerSide, BISHOP) == 1);
+  assert(pos.non_pawn_material(weakerSide  ) == BishopValueMg);
+  assert(pos.count<BISHOP>(weakerSide  ) == 1);
+  assert(pos.count<  PAWN>(weakerSide  ) == 0);
+  assert(pos.count<  PAWN>(strongerSide) == 0);
 
   Value result = Value(MateTable[pos.king_square(weakerSide)]);
   return strongerSide == pos.side_to_move() ? result : -result;
@@ -314,15 +314,15 @@ template<>
 Value Endgame<KRKN>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == RookValueMg);
-  assert(pos.piece_count(strongerSide, PAWN) == 0);
-  assert(pos.non_pawn_material(weakerSide) == KnightValueMg);
-  assert(pos.piece_count(weakerSide, PAWN) == 0);
-  assert(pos.piece_count(weakerSide, KNIGHT) == 1);
+  assert(pos.non_pawn_material(weakerSide  ) == KnightValueMg);
+  assert(pos.count<KNIGHT>(weakerSide  ) == 1);
+  assert(pos.count<  PAWN>(weakerSide  ) == 0);
+  assert(pos.count<  PAWN>(strongerSide) == 0);
 
   const int penalty[8] = { 0, 10, 14, 20, 30, 42, 58, 80 };
 
   Square bksq = pos.king_square(weakerSide);
-  Square bnsq = pos.piece_list(weakerSide, KNIGHT)[0];
+  Square bnsq = pos.list<KNIGHT>(weakerSide)[0];
   Value result = Value(MateTable[bksq] + penalty[square_distance(bksq, bnsq)]);
   return strongerSide == pos.side_to_move() ? result : -result;
 }
@@ -335,13 +335,13 @@ template<>
 Value Endgame<KQKP>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == QueenValueMg);
-  assert(pos.piece_count(strongerSide, PAWN) == 0);
-  assert(pos.non_pawn_material(weakerSide) == 0);
-  assert(pos.piece_count(weakerSide, PAWN) == 1);
+  assert(pos.non_pawn_material(weakerSide  ) == VALUE_ZERO);
+  assert(pos.count<PAWN>(strongerSide) == 0);
+  assert(pos.count<PAWN>(weakerSide  ) == 1);
 
   Square winnerKSq = pos.king_square(strongerSide);
   Square loserKSq = pos.king_square(weakerSide);
-  Square pawnSq = pos.piece_list(weakerSide, PAWN)[0];
+  Square pawnSq = pos.list<PAWN>(weakerSide)[0];
 
   Value result =  QueenValueEg
                 - PawnValueEg
@@ -368,9 +368,9 @@ template<>
 Value Endgame<KQKR>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == QueenValueMg);
-  assert(pos.piece_count(strongerSide, PAWN) == 0);
-  assert(pos.non_pawn_material(weakerSide) == RookValueMg);
-  assert(pos.piece_count(weakerSide, PAWN) == 0);
+  assert(pos.non_pawn_material(weakerSide  ) == RookValueMg);
+  assert(pos.count<PAWN>(strongerSide) == 0);
+  assert(pos.count<PAWN>(weakerSide  ) == 0);
 
   Square winnerKSq = pos.king_square(strongerSide);
   Square loserKSq = pos.king_square(weakerSide);
@@ -386,16 +386,16 @@ Value Endgame<KQKR>::operator()(const Position& pos) const {
 template<>
 Value Endgame<KBBKN>::operator()(const Position& pos) const {
 
-  assert(pos.piece_count(strongerSide, BISHOP) == 2);
-  assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMg);
-  assert(pos.piece_count(weakerSide, KNIGHT) == 1);
-  assert(pos.non_pawn_material(weakerSide) == KnightValueMg);
+  assert(pos.non_pawn_material(strongerSide) == 2 * BishopValueMg);
+  assert(pos.non_pawn_material(weakerSide  ) == KnightValueMg);
+  assert(pos.count<BISHOP>(strongerSide) == 2);
+  assert(pos.count<KNIGHT>(weakerSide  ) == 1);
   assert(!pos.pieces(PAWN));
 
   Value result = BishopValueEg;
   Square wksq = pos.king_square(strongerSide);
   Square bksq = pos.king_square(weakerSide);
-  Square nsq = pos.piece_list(weakerSide, KNIGHT)[0];
+  Square nsq = pos.list<KNIGHT>(weakerSide)[0];
 
   // Bonus for attacking king close to defending king
   result += Value(DistanceBonus[square_distance(wksq, bksq)]);
@@ -430,20 +430,20 @@ template<>
 ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
-  assert(pos.piece_count(strongerSide, BISHOP) == 1);
-  assert(pos.piece_count(strongerSide, PAWN) >= 1);
+  assert(pos.count<BISHOP>(strongerSide) == 1);
+  assert(pos.count<  PAWN>(strongerSide) >= 1);
 
   // No assertions about the material of weakerSide, because we want draws to
   // be detected even when the weaker side has some pawns.
 
   Bitboard pawns = pos.pieces(strongerSide, PAWN);
-  File pawnFile = file_of(pos.piece_list(strongerSide, PAWN)[0]);
+  File pawnFile = file_of(pos.list<PAWN>(strongerSide)[0]);
 
   // All pawns are on a single rook file ?
   if (    (pawnFile == FILE_A || pawnFile == FILE_H)
       && !(pawns & ~file_bb(pawnFile)))
   {
-      Square bishopSq = pos.piece_list(strongerSide, BISHOP)[0];
+      Square bishopSq = pos.list<BISHOP>(strongerSide)[0];
       Square queeningSq = relative_square(strongerSide, pawnFile | RANK_8);
       Square kingSq = pos.king_square(weakerSide);
 
@@ -477,7 +477,7 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
   if (    (pawnFile == FILE_B || pawnFile == FILE_G)
       && !(pos.pieces(PAWN) & ~file_bb(pawnFile))
       && pos.non_pawn_material(weakerSide) == 0
-      && pos.piece_count(weakerSide, PAWN) >= 1)
+      && pos.count<PAWN>(weakerSide) >= 1)
   {
       // Get weaker pawn closest to opponent's queening square
       Bitboard wkPawns = pos.pieces(weakerSide, PAWN);
@@ -485,7 +485,7 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
 
       Square strongerKingSq = pos.king_square(strongerSide);
       Square weakerKingSq = pos.king_square(weakerSide);
-      Square bishopSq = pos.piece_list(strongerSide, BISHOP)[0];
+      Square bishopSq = pos.list<BISHOP>(strongerSide)[0];
 
       // Draw if weaker pawn is on rank 7, bishop can't attack the pawn, and
       // weaker king can stop opposing opponent's king from penetrating.
@@ -505,19 +505,19 @@ template<>
 ScaleFactor Endgame<KQKRPs>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == QueenValueMg);
-  assert(pos.piece_count(strongerSide, QUEEN) == 1);
-  assert(pos.piece_count(strongerSide, PAWN) == 0);
-  assert(pos.piece_count(weakerSide, ROOK) == 1);
-  assert(pos.piece_count(weakerSide, PAWN) >= 1);
+  assert(pos.count<QUEEN>(strongerSide) == 1);
+  assert(pos.count< PAWN>(strongerSide) == 0);
+  assert(pos.count< ROOK>(weakerSide  ) == 1);
+  assert(pos.count< PAWN>(weakerSide  ) >= 1);
 
   Square kingSq = pos.king_square(weakerSide);
-  if (   relative_rank(weakerSide, kingSq) <= RANK_2
-      && relative_rank(weakerSide, pos.king_square(strongerSide)) >= RANK_4
+  if (    relative_rank(weakerSide, kingSq) <= RANK_2
+      &&  relative_rank(weakerSide, pos.king_square(strongerSide)) >= RANK_4
       && (pos.pieces(weakerSide, ROOK) & rank_bb(relative_rank(weakerSide, RANK_3)))
       && (pos.pieces(weakerSide, PAWN) & rank_bb(relative_rank(weakerSide, RANK_2)))
       && (pos.attacks_from<KING>(kingSq) & pos.pieces(weakerSide, PAWN)))
   {
-      Square rsq = pos.piece_list(weakerSide, ROOK)[0];
+      Square rsq = pos.list<ROOK>(weakerSide)[0];
       if (pos.attacks_from<PAWN>(rsq, strongerSide) & pos.pieces(weakerSide, PAWN))
           return SCALE_FACTOR_DRAW;
   }
@@ -535,15 +535,15 @@ template<>
 ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == RookValueMg);
-  assert(pos.piece_count(strongerSide, PAWN) == 1);
-  assert(pos.non_pawn_material(weakerSide) == RookValueMg);
-  assert(pos.piece_count(weakerSide, PAWN) == 0);
+  assert(pos.non_pawn_material(weakerSide)   == RookValueMg);
+  assert(pos.count<PAWN>(strongerSide) == 1);
+  assert(pos.count<PAWN>(weakerSide  ) == 0);
 
   Square wksq = pos.king_square(strongerSide);
-  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 wrsq = pos.list<ROOK>(strongerSide)[0];
+  Square wpsq = pos.list<PAWN>(strongerSide)[0];
+  Square brsq = pos.list<ROOK>(weakerSide)[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.
@@ -653,12 +653,12 @@ template<>
 ScaleFactor Endgame<KRPPKRP>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == RookValueMg);
-  assert(pos.piece_count(strongerSide, PAWN) == 2);
-  assert(pos.non_pawn_material(weakerSide) == RookValueMg);
-  assert(pos.piece_count(weakerSide, PAWN) == 1);
+  assert(pos.non_pawn_material(weakerSide)   == RookValueMg);
+  assert(pos.count<PAWN>(strongerSide) == 2);
+  assert(pos.count<PAWN>(weakerSide  ) == 1);
 
-  Square wpsq1 = pos.piece_list(strongerSide, PAWN)[0];
-  Square wpsq2 = pos.piece_list(strongerSide, PAWN)[1];
+  Square wpsq1 = pos.list<PAWN>(strongerSide)[0];
+  Square wpsq2 = pos.list<PAWN>(strongerSide)[1];
   Square bksq = pos.king_square(weakerSide);
 
   // Does the stronger side have a passed pawn?
@@ -691,9 +691,9 @@ template<>
 ScaleFactor Endgame<KPsK>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
-  assert(pos.piece_count(strongerSide, PAWN) >= 2);
-  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
-  assert(pos.piece_count(weakerSide, PAWN) == 0);
+  assert(pos.non_pawn_material(weakerSide)   == VALUE_ZERO);
+  assert(pos.count<PAWN>(strongerSide) >= 2);
+  assert(pos.count<PAWN>(weakerSide  ) == 0);
 
   Square ksq = pos.king_square(weakerSide);
   Bitboard pawns = pos.pieces(strongerSide, PAWN);
@@ -728,15 +728,15 @@ template<>
 ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
-  assert(pos.piece_count(strongerSide, BISHOP) == 1);
-  assert(pos.piece_count(strongerSide, PAWN) == 1);
-  assert(pos.non_pawn_material(weakerSide) == BishopValueMg);
-  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];
+  assert(pos.non_pawn_material(weakerSide  ) == BishopValueMg);
+  assert(pos.count<BISHOP>(strongerSide) == 1);
+  assert(pos.count<BISHOP>(weakerSide  ) == 1);
+  assert(pos.count<  PAWN>(strongerSide) == 1);
+  assert(pos.count<  PAWN>(weakerSide  ) == 0);
+
+  Square pawnSq = pos.list<PAWN>(strongerSide)[0];
+  Square strongerBishopSq = pos.list<BISHOP>(strongerSide)[0];
+  Square weakerBishopSq = pos.list<BISHOP>(weakerSide)[0];
   Square weakerKingSq = pos.king_square(weakerSide);
 
   // Case 1: Defending king blocks the pawn, and cannot be driven away
@@ -783,21 +783,21 @@ template<>
 ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
-  assert(pos.piece_count(strongerSide, BISHOP) == 1);
-  assert(pos.piece_count(strongerSide, PAWN) == 2);
-  assert(pos.non_pawn_material(weakerSide) == BishopValueMg);
-  assert(pos.piece_count(weakerSide, BISHOP) == 1);
-  assert(pos.piece_count(weakerSide, PAWN) == 0);
+  assert(pos.non_pawn_material(weakerSide  ) == BishopValueMg);
+  assert(pos.count<BISHOP>(strongerSide) == 1);
+  assert(pos.count<BISHOP>(weakerSide  ) == 1);
+  assert(pos.count<  PAWN>(strongerSide) == 2);
+  assert(pos.count<  PAWN>(weakerSide  ) == 0);
 
-  Square wbsq = pos.piece_list(strongerSide, BISHOP)[0];
-  Square bbsq = pos.piece_list(weakerSide, BISHOP)[0];
+  Square wbsq = pos.list<BISHOP>(strongerSide)[0];
+  Square bbsq = pos.list<BISHOP>(weakerSide)[0];
 
   if (!opposite_colors(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.list<PAWN>(strongerSide)[0];
+  Square psq2 = pos.list<PAWN>(strongerSide)[1];
   Rank r1 = rank_of(psq1);
   Rank r2 = rank_of(psq2);
   Square blockSq1, blockSq2;
@@ -858,14 +858,14 @@ template<>
 ScaleFactor Endgame<KBPKN>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == BishopValueMg);
-  assert(pos.piece_count(strongerSide, BISHOP) == 1);
-  assert(pos.piece_count(strongerSide, PAWN) == 1);
-  assert(pos.non_pawn_material(weakerSide) == KnightValueMg);
-  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];
+  assert(pos.non_pawn_material(weakerSide  ) == KnightValueMg);
+  assert(pos.count<BISHOP>(strongerSide) == 1);
+  assert(pos.count<KNIGHT>(weakerSide  ) == 1);
+  assert(pos.count<  PAWN>(strongerSide) == 1);
+  assert(pos.count<  PAWN>(weakerSide  ) == 0);
+
+  Square pawnSq = pos.list<PAWN>(strongerSide)[0];
+  Square strongerBishopSq = pos.list<BISHOP>(strongerSide)[0];
   Square weakerKingSq = pos.king_square(weakerSide);
 
   if (   file_of(weakerKingSq) == file_of(pawnSq)
@@ -885,12 +885,12 @@ template<>
 ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == KnightValueMg);
-  assert(pos.piece_count(strongerSide, KNIGHT) == 1);
-  assert(pos.piece_count(strongerSide, PAWN) == 1);
-  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
-  assert(pos.piece_count(weakerSide, PAWN) == 0);
+  assert(pos.non_pawn_material(weakerSide  ) == VALUE_ZERO);
+  assert(pos.count<KNIGHT>(strongerSide) == 1);
+  assert(pos.count<  PAWN>(strongerSide) == 1);
+  assert(pos.count<  PAWN>(weakerSide  ) == 0);
 
-  Square pawnSq = pos.piece_list(strongerSide, PAWN)[0];
+  Square pawnSq = pos.list<PAWN>(strongerSide)[0];
   Square weakerKingSq = pos.king_square(weakerSide);
 
   if (   pawnSq == relative_square(strongerSide, SQ_A7)
@@ -910,8 +910,8 @@ ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const {
 template<>
 ScaleFactor Endgame<KNPKB>::operator()(const Position& pos) const {
 
-  Square pawnSq = pos.piece_list(strongerSide, PAWN)[0];
-  Square bishopSq = pos.piece_list(weakerSide, BISHOP)[0];
+  Square pawnSq = pos.list<PAWN>(strongerSide)[0];
+  Square bishopSq = pos.list<BISHOP>(weakerSide)[0];
   Square weakerKingSq = pos.king_square(weakerSide);
 
   // King needs to get close to promoting pawn to prevent knight from blocking.
@@ -932,13 +932,13 @@ template<>
 ScaleFactor Endgame<KPKP>::operator()(const Position& pos) const {
 
   assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
-  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
-  assert(pos.piece_count(WHITE, PAWN) == 1);
-  assert(pos.piece_count(BLACK, PAWN) == 1);
+  assert(pos.non_pawn_material(weakerSide  ) == VALUE_ZERO);
+  assert(pos.count<PAWN>(WHITE) == 1);
+  assert(pos.count<PAWN>(BLACK) == 1);
 
   Square wksq = pos.king_square(strongerSide);
   Square bksq = pos.king_square(weakerSide);
-  Square wpsq = pos.piece_list(strongerSide, PAWN)[0];
+  Square wpsq = pos.list<PAWN>(strongerSide)[0];
   Color us = pos.side_to_move();
 
   if (strongerSide == BLACK)
index f18968c..a19f346 100644 (file)
@@ -391,7 +391,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
       {
           // Check for KBP vs KB with only a single pawn that is almost
           // certainly a draw or at least two pawns.
-          bool one_pawn = (pos.piece_count(WHITE, PAWN) + pos.piece_count(BLACK, PAWN) == 1);
+          bool one_pawn = (pos.count<PAWN>(WHITE) + pos.count<PAWN>(BLACK) == 1);
           sf = one_pawn ? ScaleFactor(8) : ScaleFactor(32);
       }
       else
@@ -440,8 +440,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
     ei.attackedBy[Us][PAWN] = ei.pi->pawn_attacks(Us);
 
     // Init king safety tables only if we are going to use them
-    if (   pos.piece_count(Us, QUEEN)
-        && pos.non_pawn_material(Us) > QueenValueMg + PawnValueMg)
+    if (pos.count<QUEEN>(Us) && pos.non_pawn_material(Us) > QueenValueMg + PawnValueMg)
     {
         ei.kingRing[Them] = b | shift_bb<Down>(b);
         b &= ei.attackedBy[Us][PAWN];
@@ -488,7 +487,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
     Score score = SCORE_ZERO;
 
     const Color Them = (Us == WHITE ? BLACK : WHITE);
-    const Square* pl = pos.piece_list(Us, Piece);
+    const Square* pl = pos.list<Piece>(Us);
 
     ei.attackedBy[Us][Piece] = 0;
 
index c1247b6..ed125dd 100644 (file)
@@ -75,24 +75,24 @@ namespace {
   // Helper templates used to detect a given material distribution
   template<Color Us> bool is_KXK(const Position& pos) {
     const Color Them = (Us == WHITE ? BLACK : WHITE);
-    return   pos.non_pawn_material(Them) == VALUE_ZERO
-          && pos.piece_count(Them, PAWN) == 0
-          && pos.non_pawn_material(Us)   >= RookValueMg;
+    return  !pos.count<PAWN>(Them)
+          && pos.non_pawn_material(Them) == VALUE_ZERO
+          && pos.non_pawn_material(Us) >= RookValueMg;
   }
 
   template<Color Us> bool is_KBPsKs(const Position& pos) {
-    return   pos.non_pawn_material(Us)   == BishopValueMg
-          && pos.piece_count(Us, BISHOP) == 1
-          && pos.piece_count(Us, PAWN)   >= 1;
+    return   pos.non_pawn_material(Us) == BishopValueMg
+          && pos.count<BISHOP>(Us) == 1
+          && pos.count<PAWN  >(Us) >= 1;
   }
 
   template<Color Us> bool is_KQKRPs(const Position& pos) {
     const Color Them = (Us == WHITE ? BLACK : WHITE);
-    return   pos.piece_count(Us, PAWN)    == 0
-          && pos.non_pawn_material(Us)    == QueenValueMg
-          && pos.piece_count(Us, QUEEN)   == 1
-          && pos.piece_count(Them, ROOK)  == 1
-          && pos.piece_count(Them, PAWN)  >= 1;
+    return  !pos.count<PAWN>(Us)
+          && pos.non_pawn_material(Us) == QueenValueMg
+          && pos.count<QUEEN>(Us)  == 1
+          && pos.count<ROOK>(Them) == 1
+          && pos.count<PAWN>(Them) >= 1;
   }
 
   /// imbalance() calculates imbalance comparing piece count of each
@@ -180,8 +180,8 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
       assert((pos.pieces(WHITE, KNIGHT) | pos.pieces(WHITE, BISHOP)));
       assert((pos.pieces(BLACK, KNIGHT) | pos.pieces(BLACK, BISHOP)));
 
-      if (   pos.piece_count(WHITE, BISHOP) + pos.piece_count(WHITE, KNIGHT) <= 2
-          && pos.piece_count(BLACK, BISHOP) + pos.piece_count(BLACK, KNIGHT) <= 2)
+      if (   pos.count<BISHOP>(WHITE) + pos.count<KNIGHT>(WHITE) <= 2
+          && pos.count<BISHOP>(BLACK) + pos.count<KNIGHT>(BLACK) <= 2)
       {
           e->evaluationFunction = &EvaluateKmmKm[pos.side_to_move()];
           return e;
@@ -221,17 +221,17 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
 
   if (npm_w + npm_b == VALUE_ZERO)
   {
-      if (pos.piece_count(BLACK, PAWN) == 0)
+      if (!pos.count<PAWN>(BLACK))
       {
-          assert(pos.piece_count(WHITE, PAWN) >= 2);
+          assert(pos.count<PAWN>(WHITE) >= 2);
           e->scalingFunction[WHITE] = &ScaleKPsK[WHITE];
       }
-      else if (pos.piece_count(WHITE, PAWN) == 0)
+      else if (!pos.count<PAWN>(WHITE))
       {
-          assert(pos.piece_count(BLACK, PAWN) >= 2);
+          assert(pos.count<PAWN>(BLACK) >= 2);
           e->scalingFunction[BLACK] = &ScaleKPsK[BLACK];
       }
-      else if (pos.piece_count(WHITE, PAWN) == 1 && pos.piece_count(BLACK, PAWN) == 1)
+      else if (pos.count<PAWN>(WHITE) == 1 && pos.count<PAWN>(BLACK) == 1)
       {
           // This is a special case because we set scaling functions
           // for both colors instead of only one.
@@ -241,23 +241,23 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
   }
 
   // No pawns makes it difficult to win, even with a material advantage
-  if (pos.piece_count(WHITE, PAWN) == 0 && npm_w - npm_b <= BishopValueMg)
+  if (!pos.count<PAWN>(WHITE) && npm_w - npm_b <= BishopValueMg)
   {
       e->factor[WHITE] = (uint8_t)
-      (npm_w == npm_b || npm_w < RookValueMg ? 0 : NoPawnsSF[std::min(pos.piece_count(WHITE, BISHOP), 2)]);
+      (npm_w == npm_b || npm_w < RookValueMg ? 0 : NoPawnsSF[std::min(pos.count<BISHOP>(WHITE), 2)]);
   }
 
-  if (pos.piece_count(BLACK, PAWN) == 0 && npm_b - npm_w <= BishopValueMg)
+  if (!pos.count<PAWN>(BLACK) && npm_b - npm_w <= BishopValueMg)
   {
       e->factor[BLACK] = (uint8_t)
-      (npm_w == npm_b || npm_b < RookValueMg ? 0 : NoPawnsSF[std::min(pos.piece_count(BLACK, BISHOP), 2)]);
+      (npm_w == npm_b || npm_b < RookValueMg ? 0 : NoPawnsSF[std::min(pos.count<BISHOP>(BLACK), 2)]);
   }
 
   // Compute the space weight
   if (npm_w + npm_b >= 2 * QueenValueMg + 4 * RookValueMg + 2 * KnightValueMg)
   {
-      int minorPieceCount =  pos.piece_count(WHITE, KNIGHT) + pos.piece_count(WHITE, BISHOP)
-                           + pos.piece_count(BLACK, KNIGHT) + pos.piece_count(BLACK, BISHOP);
+      int minorPieceCount =  pos.count<KNIGHT>(WHITE) + pos.count<BISHOP>(WHITE)
+                           + pos.count<KNIGHT>(BLACK) + pos.count<BISHOP>(BLACK);
 
       e->spaceWeight = minorPieceCount * minorPieceCount;
   }
@@ -266,10 +266,10 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
   // for the bishop pair "extended piece", this allow us to be more flexible
   // in defining bishop pair bonuses.
   const int pieceCount[COLOR_NB][PIECE_TYPE_NB] = {
-  { pos.piece_count(WHITE, BISHOP) > 1, pos.piece_count(WHITE, PAWN), pos.piece_count(WHITE, KNIGHT),
-    pos.piece_count(WHITE, BISHOP)    , pos.piece_count(WHITE, ROOK), pos.piece_count(WHITE, QUEEN) },
-  { pos.piece_count(BLACK, BISHOP) > 1, pos.piece_count(BLACK, PAWN), pos.piece_count(BLACK, KNIGHT),
-    pos.piece_count(BLACK, BISHOP)    , pos.piece_count(BLACK, ROOK), pos.piece_count(BLACK, QUEEN) } };
+  { pos.count<BISHOP>(WHITE) > 1, pos.count<PAWN>(WHITE), pos.count<KNIGHT>(WHITE),
+    pos.count<BISHOP>(WHITE)    , pos.count<ROOK>(WHITE), pos.count<QUEEN >(WHITE) },
+  { pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK),
+    pos.count<BISHOP>(BLACK)    , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } };
 
   e->value = (int16_t)((imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16);
   return e;
index 84acfc0..783fed7 100644 (file)
@@ -211,7 +211,7 @@ namespace {
 
     assert(Pt != KING && Pt != PAWN);
 
-    const Square* pl = pos.piece_list(us, Pt);
+    const Square* pl = pos.list<Pt>(us);
 
     for (Square from = *pl; from != SQ_NONE; from = *++pl)
     {
index d05e8af..e1952b6 100644 (file)
@@ -93,7 +93,7 @@ namespace {
     Rank r;
     bool passed, isolated, doubled, opposed, chain, backward, candidate;
     Score value = SCORE_ZERO;
-    const Square* pl = pos.piece_list(Us, PAWN);
+    const Square* pl = pos.list<PAWN>(Us);
 
     Bitboard ourPawns = pos.pieces(Us, PAWN);
     Bitboard theirPawns = pos.pieces(Them, PAWN);
@@ -103,7 +103,7 @@ namespace {
     e->semiopenFiles[Us] = 0xFF;
     e->pawnAttacks[Us] = shift_bb<Right>(ourPawns) | shift_bb<Left>(ourPawns);
     e->pawnsOnSquares[Us][BLACK] = popcount<Max15>(ourPawns & BlackSquares);
-    e->pawnsOnSquares[Us][WHITE] = pos.piece_count(Us, PAWN) - e->pawnsOnSquares[Us][BLACK];
+    e->pawnsOnSquares[Us][WHITE] = pos.count<PAWN>(Us) - e->pawnsOnSquares[Us][BLACK];
 
     // Loop through all pawns of the current color and score each pawn
     while ((s = *pl++) != SQ_NONE)
index c5e0294..76c2733 100644 (file)
@@ -1332,7 +1332,7 @@ Key Position::compute_material_key() const {
 
   for (Color c = WHITE; c <= BLACK; c++)
       for (PieceType pt = PAWN; pt <= QUEEN; pt++)
-          for (int cnt = 0; cnt < piece_count(c, pt); cnt++)
+          for (int cnt = 0; cnt < pieceCount[c][pt]; cnt++)
               k ^= Zobrist::psq[c][pt][cnt];
 
   return k;
@@ -1368,7 +1368,7 @@ Value Position::compute_non_pawn_material(Color c) const {
   Value value = VALUE_ZERO;
 
   for (PieceType pt = KNIGHT; pt <= QUEEN; pt++)
-      value += piece_count(c, pt) * PieceValue[MG][pt];
+      value += pieceCount[c][pt] * PieceValue[MG][pt];
 
   return value;
 }
@@ -1558,10 +1558,10 @@ bool Position::pos_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 (board[pieceList[c][pt][i]] != make_piece(c, pt))
                       return false;
 
-                  if (index[piece_list(c, pt)[i]] != i)
+                  if (index[pieceList[c][pt][i]] != i)
                       return false;
               }
 
index bebf617..d2343d1 100644 (file)
@@ -113,8 +113,8 @@ public:
   Square king_square(Color c) const;
   Square ep_square() const;
   bool is_empty(Square s) const;
-  const Square* piece_list(Color c, PieceType pt) const;
-  int piece_count(Color c, PieceType pt) const;
+  template<PieceType Pt> int count(Color c) const;
+  template<PieceType Pt> const Square* list(Color c) const;
 
   // Castling
   int can_castle(CastleRight f) const;
@@ -273,12 +273,12 @@ inline Bitboard Position::pieces(Color c, PieceType pt1, PieceType pt2) const {
   return byColorBB[c] & (byTypeBB[pt1] | byTypeBB[pt2]);
 }
 
-inline int Position::piece_count(Color c, PieceType pt) const {
-  return pieceCount[c][pt];
+template<PieceType Pt> inline int Position::count(Color c) const {
+  return pieceCount[c][Pt];
 }
 
-inline const Square* Position::piece_list(Color c, PieceType pt) const {
-  return pieceList[c][pt];
+template<PieceType Pt> inline const Square* Position::list(Color c) const {
+  return pieceList[c][Pt];
 }
 
 inline Square Position::ep_square() const {