]> git.sesse.net Git - stockfish/commitdiff
Rename occupied_squares() to pieces()
authorMarco Costalba <mcostalba@gmail.com>
Sun, 18 Mar 2012 10:10:12 +0000 (11:10 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 18 Mar 2012 10:18:38 +0000 (11:18 +0100)
Also some microoptimizations, were there from ages
but hidden: the renaming suddendly made them visible!

This is a good example of how better naming lets you write
better code. Naming is really a kind of black art!

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/book.cpp
src/evaluate.cpp
src/movegen.cpp
src/position.cpp
src/position.h
src/search.cpp

index 1baafbbaabb618f87c2b425a09f3a844fcf3f182..cc557e4800aac7126ed74ccdb1cf33c29ba9436c 100644 (file)
@@ -315,7 +315,7 @@ namespace {
   uint64_t book_key(const Position& pos) {
 
     uint64_t key = 0;
   uint64_t book_key(const Position& pos) {
 
     uint64_t key = 0;
-    Bitboard b = pos.occupied_squares();
+    Bitboard b = pos.pieces();
 
     while (b)
     {
 
     while (b)
     {
index 5e3a3ff24daf28de218928466d85de70c87d8243..ef52f7479d678b2c95ce4249fdd394a27f3f0971 100644 (file)
@@ -547,9 +547,9 @@ Value do_evaluate(const Position& pos, Value& margin) {
         if (Piece == KNIGHT || Piece == QUEEN)
             b = pos.attacks_from<Piece>(s);
         else if (Piece == BISHOP)
         if (Piece == KNIGHT || Piece == QUEEN)
             b = pos.attacks_from<Piece>(s);
         else if (Piece == BISHOP)
-            b = attacks_bb<BISHOP>(s, pos.occupied_squares() & ~pos.pieces(QUEEN, Us));
+            b = attacks_bb<BISHOP>(s, pos.pieces() ^ pos.pieces(QUEEN, Us));
         else if (Piece == ROOK)
         else if (Piece == ROOK)
-            b = attacks_bb<ROOK>(s, pos.occupied_squares() & ~pos.pieces(ROOK, QUEEN, Us));
+            b = attacks_bb<ROOK>(s, pos.pieces() ^ pos.pieces(ROOK, QUEEN, Us));
         else
             assert(false);
 
         else
             assert(false);
 
@@ -573,7 +573,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
         if (   (Piece == BISHOP || Piece == ROOK || Piece == QUEEN)
             && (PseudoAttacks[Piece][pos.king_square(Them)] & s))
         {
         if (   (Piece == BISHOP || Piece == ROOK || Piece == QUEEN)
             && (PseudoAttacks[Piece][pos.king_square(Them)] & s))
         {
-            b = BetweenBB[s][pos.king_square(Them)] & pos.occupied_squares();
+            b = BetweenBB[s][pos.king_square(Them)] & pos.pieces();
 
             assert(b);
 
 
             assert(b);
 
@@ -977,7 +977,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());
             // 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((queeningPath & pos.occupied_squares()) == (queeningPath & pos.pieces(c)));
+            assert((queeningPath & pos.pieces()) == (queeningPath & pos.pieces(c)));
 
             // Add moves needed to free the path from friendly pieces and retest condition
             movesToGo += popcount<Max15>(queeningPath & pos.pieces(c));
 
             // Add moves needed to free the path from friendly pieces and retest condition
             movesToGo += popcount<Max15>(queeningPath & pos.pieces(c));
index 0301e90648c8314ab6db53b3e9a47bfbfefa2215..86ab7ac4d1e007067ae21865b50dd4ba4c461264 100644 (file)
@@ -63,7 +63,7 @@ namespace {
     // when moving the castling rook we do not discover some hidden checker.
     // For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
     if (    pos.is_chess960()
     // when moving the castling rook we do not discover some hidden checker.
     // For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
     if (    pos.is_chess960()
-        && (pos.attackers_to(kto, pos.occupied_squares() ^ rfrom) & enemies))
+        && (pos.attackers_to(kto, pos.pieces() ^ rfrom) & enemies))
             return mlist;
 
     (*mlist++).move = make_castle(kfrom, rfrom);
             return mlist;
 
     (*mlist++).move = make_castle(kfrom, rfrom);
@@ -142,7 +142,7 @@ namespace {
     // Single and double pawn pushes, no promotions
     if (Type != MV_CAPTURE)
     {
     // Single and double pawn pushes, no promotions
     if (Type != MV_CAPTURE)
     {
-        emptySquares = (Type == MV_QUIET ? target : ~pos.occupied_squares());
+        emptySquares = (Type == MV_QUIET ? target : ~pos.pieces());
 
         b1 = move_pawns<UP>(pawnsNotOn7)   & emptySquares;
         b2 = move_pawns<UP>(b1 & TRank3BB) & emptySquares;
 
         b1 = move_pawns<UP>(pawnsNotOn7)   & emptySquares;
         b2 = move_pawns<UP>(b1 & TRank3BB) & emptySquares;
@@ -180,7 +180,7 @@ namespace {
     if (pawnsOn7 && (Type != MV_EVASION || (target & TRank8BB)))
     {
         if (Type == MV_CAPTURE)
     if (pawnsOn7 && (Type != MV_EVASION || (target & TRank8BB)))
     {
         if (Type == MV_CAPTURE)
-            emptySquares = ~pos.occupied_squares();
+            emptySquares = ~pos.pieces();
 
         if (Type == MV_EVASION)
             emptySquares &= target;
 
         if (Type == MV_EVASION)
             emptySquares &= target;
@@ -233,7 +233,7 @@ namespace {
 
     if (*pl != SQ_NONE)
     {
 
     if (*pl != SQ_NONE)
     {
-        target = ci.checkSq[Pt] & ~pos.occupied_squares(); // Non capture checks only
+        target = ci.checkSq[Pt] & ~pos.pieces(); // Non capture checks only
 
         do {
             from = *pl;
 
         do {
             from = *pl;
@@ -308,10 +308,10 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) {
       target = pos.pieces(~us);
 
   else if (Type == MV_QUIET)
       target = pos.pieces(~us);
 
   else if (Type == MV_QUIET)
-      target = ~pos.occupied_squares();
+      target = ~pos.pieces();
 
   else if (Type == MV_NON_EVASION)
 
   else if (Type == MV_NON_EVASION)
-      target = pos.pieces(~us) | ~pos.occupied_squares();
+      target = ~pos.pieces(us);
 
   mlist = (us == WHITE ? generate_pawn_moves<WHITE, Type>(pos, mlist, target)
                        : generate_pawn_moves<BLACK, Type>(pos, mlist, target));
 
   mlist = (us == WHITE ? generate_pawn_moves<WHITE, Type>(pos, mlist, target)
                        : generate_pawn_moves<BLACK, Type>(pos, mlist, target));
@@ -356,7 +356,7 @@ MoveStack* generate<MV_QUIET_CHECK>(const Position& pos, MoveStack* mlist) {
      if (pt == PAWN)
          continue; // Will be generated togheter with direct checks
 
      if (pt == PAWN)
          continue; // Will be generated togheter with direct checks
 
-     Bitboard b = pos.attacks_from(Piece(pt), from) & ~pos.occupied_squares();
+     Bitboard b = pos.attacks_from(Piece(pt), from) & ~pos.pieces();
 
      if (pt == KING)
          b &= ~PseudoAttacks[QUEEN][ci.ksq];
 
      if (pt == KING)
          b &= ~PseudoAttacks[QUEEN][ci.ksq];
index b10ea9ea49c787bab1b08670917505cb3cb5023e..d18cf2f88fcf9421cbecb42eb7601c6e67623594 100644 (file)
@@ -377,7 +377,7 @@ Bitboard Position::hidden_checkers() const {
 
   while (pinners)
   {
 
   while (pinners)
   {
-      b = squares_between(ksq, pop_1st_bit(&pinners)) & occupied_squares();
+      b = squares_between(ksq, pop_1st_bit(&pinners)) & pieces();
 
       if (b && single_bit(b) && (b & pieces(sideToMove)))
           result |= b;
 
       if (b && single_bit(b) && (b & pieces(sideToMove)))
           result |= b;
@@ -437,7 +437,7 @@ bool Position::move_attacks_square(Move m, Square s) const {
   assert(!square_is_empty(from));
 
   // Update occupancy as if the piece is moving
   assert(!square_is_empty(from));
 
   // Update occupancy as if the piece is moving
-  occ = occupied_squares() ^ from ^ to;
+  occ = pieces() ^ from ^ to;
 
   // The piece moved in 'to' attacks the square 's' ?
   if (attacks_from(piece, to, occ) & s)
 
   // The piece moved in 'to' attacks the square 's' ?
   if (attacks_from(piece, to, occ) & s)
@@ -474,7 +474,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
       Square to = to_sq(m);
       Square capsq = to + pawn_push(them);
       Square ksq = king_square(us);
       Square to = to_sq(m);
       Square capsq = to + pawn_push(them);
       Square ksq = king_square(us);
-      Bitboard b = (occupied_squares() ^ from ^ capsq) | to;
+      Bitboard b = (pieces() ^ from ^ capsq) | to;
 
       assert(to == ep_square());
       assert(piece_moved(m) == make_piece(us, PAWN));
 
       assert(to == ep_square());
       assert(piece_moved(m) == make_piece(us, PAWN));
@@ -626,7 +626,7 @@ bool Position::is_pseudo_legal(const Move m) const {
       }
       // In case of king moves under check we have to remove king so to catch
       // as invalid moves like b1a1 when opposite queen is on c1.
       }
       // In case of king moves under check we have to remove king so to catch
       // as invalid moves like b1a1 when opposite queen is on c1.
-      else if (attackers_to(to, occupied_squares() ^ from) & pieces(~us))
+      else if (attackers_to(to, pieces() ^ from) & pieces(~us))
           return false;
   }
 
           return false;
   }
 
@@ -668,7 +668,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
 
   // Promotion with check ?
   if (is_promotion(m))
 
   // Promotion with check ?
   if (is_promotion(m))
-      return attacks_from(Piece(promotion_type(m)), to, occupied_squares() ^ from) & ksq;
+      return attacks_from(Piece(promotion_type(m)), to, pieces() ^ from) & ksq;
 
   // En passant capture with check ? We have already handled the case
   // of direct checks and ordinary discovered check, the only case we
 
   // En passant capture with check ? We have already handled the case
   // of direct checks and ordinary discovered check, the only case we
@@ -677,7 +677,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
   if (is_enpassant(m))
   {
       Square capsq = make_square(file_of(to), rank_of(from));
   if (is_enpassant(m))
   {
       Square capsq = make_square(file_of(to), rank_of(from));
-      Bitboard b = (occupied_squares() ^ from ^ capsq) | to;
+      Bitboard b = (pieces() ^ from ^ capsq) | to;
 
       return  (attacks_bb<  ROOK>(ksq, b) & pieces(  ROOK, QUEEN, us))
             | (attacks_bb<BISHOP>(ksq, b) & pieces(BISHOP, QUEEN, us));
 
       return  (attacks_bb<  ROOK>(ksq, b) & pieces(  ROOK, QUEEN, us))
             | (attacks_bb<BISHOP>(ksq, b) & pieces(BISHOP, QUEEN, us));
@@ -690,7 +690,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
       Square rfrom = to; // 'King captures the rook' notation
       Square kto = relative_square(us, rfrom > kfrom ? SQ_G1 : SQ_C1);
       Square rto = relative_square(us, rfrom > kfrom ? SQ_F1 : SQ_D1);
       Square rfrom = to; // 'King captures the rook' notation
       Square kto = relative_square(us, rfrom > kfrom ? SQ_G1 : SQ_C1);
       Square rto = relative_square(us, rfrom > kfrom ? SQ_F1 : SQ_D1);
-      Bitboard b = (occupied_squares() ^ kfrom ^ rfrom) | rto | kto;
+      Bitboard b = (pieces() ^ kfrom ^ rfrom) | rto | kto;
 
       return attacks_bb<ROOK>(rto, b) & ksq;
   }
 
       return attacks_bb<ROOK>(rto, b) & ksq;
   }
@@ -1235,7 +1235,7 @@ int Position::see(Move m) const {
   from = from_sq(m);
   to = to_sq(m);
   capturedType = type_of(piece_on(to));
   from = from_sq(m);
   to = to_sq(m);
   capturedType = type_of(piece_on(to));
-  occ = occupied_squares();
+  occ = pieces();
 
   // Handle en passant moves
   if (is_enpassant(m))
 
   // Handle en passant moves
   if (is_enpassant(m))
@@ -1667,7 +1667,7 @@ bool Position::pos_is_ok(int* failedStep) const {
 
       // The union of the white and black pieces must be equal to all
       // occupied squares
 
       // The union of the white and black pieces must be equal to all
       // occupied squares
-      if ((pieces(WHITE) | pieces(BLACK)) != occupied_squares())
+      if ((pieces(WHITE) | pieces(BLACK)) != pieces())
           return false;
 
       // Separate piece type bitboards must have empty intersections
           return false;
 
       // Separate piece type bitboards must have empty intersections
index 30c25652f5b2455f966cd6767d9ae5011c43b814..d2ad99557427dedae4dcd3cbebcd23d1e070b8db 100644 (file)
@@ -108,7 +108,7 @@ public:
   Color side_to_move() const;
 
   // Bitboard representation of the position
   Color side_to_move() const;
 
   // Bitboard representation of the position
-  Bitboard occupied_squares() const;
+  Bitboard pieces() const;
   Bitboard pieces(Color c) const;
   Bitboard pieces(PieceType pt) const;
   Bitboard pieces(PieceType pt, Color c) const;
   Bitboard pieces(Color c) const;
   Bitboard pieces(PieceType pt) const;
   Bitboard pieces(PieceType pt, Color c) const;
@@ -285,7 +285,7 @@ inline Color Position::side_to_move() const {
   return sideToMove;
 }
 
   return sideToMove;
 }
 
-inline Bitboard Position::occupied_squares() const {
+inline Bitboard Position::pieces() const {
   return occupied;
 }
 
   return occupied;
 }
 
@@ -343,7 +343,7 @@ inline Square Position::castle_rook_square(CastleRight f) const {
 
 template<PieceType Pt>
 inline Bitboard Position::attacks_from(Square s) const {
 
 template<PieceType Pt>
 inline Bitboard Position::attacks_from(Square s) const {
-  return  Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, occupied_squares())
+  return  Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, pieces())
         : Pt == QUEEN  ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
         : StepAttacksBB[Pt][s];
 }
         : Pt == QUEEN  ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
         : StepAttacksBB[Pt][s];
 }
index 9386e453ca8e9d5ffaf7ef44bfd3f25bd3a7cd7d..b6fc06979599704a6bc67acbc367bb3ef0815b9f 100644 (file)
@@ -1335,7 +1335,7 @@ split_point_start: // At split points actual search starts from here
     kingAtt = pos.attacks_from<KING>(ksq);
     pc = pos.piece_moved(move);
 
     kingAtt = pos.attacks_from<KING>(ksq);
     pc = pos.piece_moved(move);
 
-    occ = pos.occupied_squares() & ~(1ULL << from) & ~(1ULL << ksq);
+    occ = pos.pieces() ^ from ^ ksq;
     oldAtt = pos.attacks_from(pc, from, occ);
     newAtt = pos.attacks_from(pc,   to, occ);
 
     oldAtt = pos.attacks_from(pc, from, occ);
     newAtt = pos.attacks_from(pc,   to, occ);
 
@@ -1403,7 +1403,7 @@ split_point_start: // At split points actual search starts from here
     ksq = pos.king_square(pos.side_to_move());
     if (    piece_is_slider(p1)
         && (squares_between(t1, ksq) & f2)
     ksq = pos.king_square(pos.side_to_move());
     if (    piece_is_slider(p1)
         && (squares_between(t1, ksq) & f2)
-        && (pos.attacks_from(p1, t1, pos.occupied_squares() ^ f2) & ksq))
+        && (pos.attacks_from(p1, t1, pos.pieces() ^ f2) & ksq))
         return true;
 
     return false;
         return true;
 
     return false;