]> git.sesse.net Git - stockfish/commitdiff
Replace make_square() with operator|(File, Rank)
authorMarco Costalba <mcostalba@gmail.com>
Sat, 23 Jun 2012 07:49:33 +0000 (08:49 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 23 Jun 2012 08:17:54 +0000 (09:17 +0100)
Be fancy :-)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/bitbase.cpp
src/bitboard.cpp
src/endgame.cpp
src/evaluate.cpp
src/move.cpp
src/position.cpp
src/types.h

index ceb94a0f9ef002f7c5bcc6218c8bf5a09df47b7a..9322e537f2837cd2bf2ba6588bda42baa0e3b524 100644 (file)
@@ -117,7 +117,7 @@ namespace {
     stm  = Color(idx & 1);
     bksq = Square((idx >> 1) & 63);
     wksq = Square((idx >> 7) & 63);
     stm  = Color(idx & 1);
     bksq = Square((idx >> 1) & 63);
     wksq = Square((idx >> 7) & 63);
-    psq  = make_square(File((idx >> 13) & 3), Rank((idx >> 15) + 1));
+    psq  = File((idx >> 13) & 3) | Rank((idx >> 15) + 1);
   }
 
   Result KPKPosition::classify_leaf(int idx) {
   }
 
   Result KPKPosition::classify_leaf(int idx) {
index 03080d15657500ffec995248646bb4816d7fcc83..08b43ad8a5b111406af4a0cf3b8ea21e14f630b0 100644 (file)
@@ -143,7 +143,7 @@ void Bitboards::print(Bitboard b) {
       std::cout << "+---+---+---+---+---+---+---+---+" << '\n';
 
       for (File file = FILE_A; file <= FILE_H; file++)
       std::cout << "+---+---+---+---+---+---+---+---+" << '\n';
 
       for (File file = FILE_A; file <= FILE_H; file++)
-          std::cout << "| " << (b & make_square(file, rank) ? "X " : "  ");
+          std::cout << "| " << (b & (file | rank) ? "X " : "  ");
 
       std::cout << "|\n";
   }
 
       std::cout << "|\n";
   }
index feaf59aafc20c04d2babdaae0e0e0a32e3e2664b..f5f2074cff44469d34e86c724d812abb07a2c083 100644 (file)
@@ -262,7 +262,7 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
       bpsq = ~bpsq;
   }
 
       bpsq = ~bpsq;
   }
 
-  Square queeningSq = make_square(file_of(bpsq), RANK_1);
+  Square queeningSq = file_of(bpsq) | RANK_1;
   Value result;
 
   // If the stronger side's king is in front of the pawn, it's a win
   Value result;
 
   // If the stronger side's king is in front of the pawn, it's a win
@@ -414,7 +414,7 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
       && !(pawns & ~file_bb(pawnFile)))
   {
       Square bishopSq = pos.piece_list(strongerSide, BISHOP)[0];
       && !(pawns & ~file_bb(pawnFile)))
   {
       Square bishopSq = pos.piece_list(strongerSide, BISHOP)[0];
-      Square queeningSq = relative_square(strongerSide, make_square(pawnFile, RANK_8));
+      Square queeningSq = relative_square(strongerSide, pawnFile | RANK_8);
       Square kingSq = pos.king_square(weakerSide);
 
       if (   opposite_colors(queeningSq, bishopSq)
       Square kingSq = pos.king_square(weakerSide);
 
       if (   opposite_colors(queeningSq, bishopSq)
@@ -513,7 +513,7 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
 
   File f = file_of(wpsq);
   Rank r = rank_of(wpsq);
 
   File f = file_of(wpsq);
   Rank r = rank_of(wpsq);
-  Square queeningSq = make_square(f, RANK_8);
+  Square queeningSq = f | RANK_8;
   int tempo = (pos.side_to_move() == strongerSide);
 
   // If the pawn is not too far advanced and the defending king defends the
   int tempo = (pos.side_to_move() == strongerSide);
 
   // If the pawn is not too far advanced and the defending king defends the
@@ -752,12 +752,12 @@ ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
   if (relative_rank(strongerSide, psq1) > relative_rank(strongerSide, psq2))
   {
       blockSq1 = psq1 + pawn_push(strongerSide);
   if (relative_rank(strongerSide, psq1) > relative_rank(strongerSide, psq2))
   {
       blockSq1 = psq1 + pawn_push(strongerSide);
-      blockSq2 = make_square(file_of(psq2), rank_of(psq1));
+      blockSq2 = file_of(psq2) | rank_of(psq1);
   }
   else
   {
       blockSq1 = psq2 + pawn_push(strongerSide);
   }
   else
   {
       blockSq1 = psq2 + pawn_push(strongerSide);
-      blockSq2 = make_square(file_of(psq1), rank_of(psq2));
+      blockSq2 = file_of(psq1) | rank_of(psq2);
   }
 
   switch (file_distance(psq1, psq2))
   }
 
   switch (file_distance(psq1, psq2))
index 8a5b6618851a8b33745e324d305a822ac2bb4d9e..02ca6d350402d280770970e40fded39022ad5f1e 100644 (file)
@@ -977,7 +977,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
         while (b)
         {
             s = pop_1st_bit(&b);
         while (b)
         {
             s = pop_1st_bit(&b);
-            queeningSquare = relative_square(c, make_square(file_of(s), RANK_8));
+            queeningSquare = relative_square(c, file_of(s) | RANK_8);
             queeningPath = forward_bb(c, s);
 
             // Compute plies to queening and check direct advancement
             queeningPath = forward_bb(c, s);
 
             // Compute plies to queening and check direct advancement
@@ -1020,7 +1020,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
         s = pop_1st_bit(&b);
 
         // Compute plies from queening
         s = pop_1st_bit(&b);
 
         // Compute plies from queening
-        queeningSquare = relative_square(loserSide, make_square(file_of(s), RANK_8));
+        queeningSquare = relative_square(loserSide, file_of(s) | RANK_8);
         movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(loserSide, s) == RANK_2);
         pliesToGo = 2 * movesToGo - int(loserSide == pos.side_to_move());
 
         movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(loserSide, s) == RANK_2);
         pliesToGo = 2 * movesToGo - int(loserSide == pos.side_to_move());
 
@@ -1044,7 +1044,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
         minKingDist = kingptg = 256;
 
         // Compute plies from queening
         minKingDist = kingptg = 256;
 
         // Compute plies from queening
-        queeningSquare = relative_square(loserSide, make_square(file_of(s), RANK_8));
+        queeningSquare = relative_square(loserSide, file_of(s) | RANK_8);
         movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(loserSide, s) == RANK_2);
         pliesToGo = 2 * movesToGo - int(loserSide == pos.side_to_move());
 
         movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(loserSide, s) == RANK_2);
         pliesToGo = 2 * movesToGo - int(loserSide == pos.side_to_move());
 
index 41d1603771a7b4d7d29daa019c23667deff99272..8ea6ad52aea0694ee5cf87808f444221e33837f1 100644 (file)
@@ -43,7 +43,7 @@ const string move_to_uci(Move m, bool chess960) {
       return "0000";
 
   if (is_castle(m) && !chess960)
       return "0000";
 
   if (is_castle(m) && !chess960)
-      to = make_square(to > from ? FILE_G : FILE_C, rank_of(from));
+      to = (to > from ? FILE_G : FILE_C) | rank_of(from);
 
   if (is_promotion(m))
       promotion = char(tolower(piece_type_to_char(promotion_type(m))));
 
   if (is_promotion(m))
       promotion = char(tolower(piece_type_to_char(promotion_type(m))));
@@ -89,7 +89,7 @@ const string move_to_san(Position& pos, Move m) {
   PieceType pt = type_of(pos.piece_on(from));
 
   if (is_castle(m))
   PieceType pt = type_of(pos.piece_on(from));
 
   if (is_castle(m))
-      san = to_sq(m) < from_sq(m) ? "O-O-O" : "O-O";
+      san = to > from ? "O-O" : "O-O-O";
   else
   {
       if (pt != PAWN)
   else
   {
       if (pt != PAWN)
index c26ab1b6884abe0c17066dac51ada332f900033c..1e416ef6bf776fa67d61480e1e227491926bd05f 100644 (file)
@@ -187,7 +187,7 @@ void Position::from_fen(const string& fenStr, bool isChess960, Thread* th) {
           for (rsq = relative_square(c, SQ_A1); type_of(piece_on(rsq)) != ROOK; rsq++) {}
 
       else if (token >= 'A' && token <= 'H')
           for (rsq = relative_square(c, SQ_A1); type_of(piece_on(rsq)) != ROOK; rsq++) {}
 
       else if (token >= 'A' && token <= 'H')
-          rsq = make_square(File(token - 'A'), relative_rank(c, RANK_1));
+          rsq = File(token - 'A') | relative_rank(c, RANK_1);
 
       else
           continue;
 
       else
           continue;
@@ -199,7 +199,7 @@ void Position::from_fen(const string& fenStr, bool isChess960, Thread* th) {
   if (   ((fen >> col) && (col >= 'a' && col <= 'h'))
       && ((fen >> row) && (row == '3' || row == '6')))
   {
   if (   ((fen >> col) && (col >= 'a' && col <= 'h'))
       && ((fen >> row) && (row == '3' || row == '6')))
   {
-      st->epSquare = make_square(File(col - 'a'), Rank(row - '1'));
+      st->epSquare = File(col - 'a') | Rank(row - '1');
 
       if (!(attackers_to(st->epSquare) & pieces(sideToMove, PAWN)))
           st->epSquare = SQ_NONE;
 
       if (!(attackers_to(st->epSquare) & pieces(sideToMove, PAWN)))
           st->epSquare = SQ_NONE;
@@ -268,7 +268,7 @@ const string Position::to_fen() const {
 
       for (File file = FILE_A; file <= FILE_H; file++)
       {
 
       for (File file = FILE_A; file <= FILE_H; file++)
       {
-          sq = make_square(file, rank);
+          sq = file | rank;
 
           if (is_empty(sq))
               emptyCnt++;
 
           if (is_empty(sq))
               emptyCnt++;
@@ -656,7 +656,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
   // the captured pawn.
   if (is_enpassant(m))
   {
   // the captured pawn.
   if (is_enpassant(m))
   {
-      Square capsq = make_square(file_of(to), rank_of(from));
+      Square capsq = file_of(to) | rank_of(from);
       Bitboard b = (pieces() ^ from ^ capsq) | to;
 
       return  (attacks_bb<  ROOK>(ksq, b) & pieces(us, QUEEN, ROOK))
       Bitboard b = (pieces() ^ from ^ capsq) | to;
 
       return  (attacks_bb<  ROOK>(ksq, b) & pieces(us, QUEEN, ROOK))
index 40a2baa0099e2da6ac006cc6bc6b86c225169374..4a78cc81d03040080923e4b6c4ea1f1fe44b2e30 100644 (file)
@@ -335,6 +335,10 @@ inline Square operator~(Square s) {
   return Square(s ^ 56); // Vertical flip SQ_A1 -> SQ_A8
 }
 
   return Square(s ^ 56); // Vertical flip SQ_A1 -> SQ_A8
 }
 
+inline Square operator|(File f, Rank r) {
+  return Square((r << 3) | f);
+}
+
 inline Value mate_in(int ply) {
   return VALUE_MATE - ply;
 }
 inline Value mate_in(int ply) {
   return VALUE_MATE - ply;
 }
@@ -359,10 +363,6 @@ inline Color color_of(Piece p) {
   return Color(p >> 3);
 }
 
   return Color(p >> 3);
 }
 
-inline Square make_square(File f, Rank r) {
-  return Square((r << 3) | f);
-}
-
 inline bool is_ok(Square s) {
   return s >= SQ_A1 && s <= SQ_H8;
 }
 inline bool is_ok(Square s) {
   return s >= SQ_A1 && s <= SQ_H8;
 }