]> git.sesse.net Git - stockfish/commitdiff
Retire operator|(File f, Rank r)
authorMarco Costalba <mcostalba@gmail.com>
Sat, 22 Mar 2014 22:35:30 +0000 (23:35 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 22 Mar 2014 22:54:18 +0000 (23:54 +0100)
Use make_square() instead. Less fancy but
more clear.

No functional change.

src/bitbase.cpp
src/endgame.cpp
src/notation.cpp
src/pawns.cpp
src/position.cpp
src/types.h

index cd6a7329724e4260bc1529ca9756e82b8265adb9..b73b72c4c17506f2e2dc7da58ada30a7caa93ccb 100644 (file)
@@ -110,7 +110,7 @@ namespace {
     wksq = Square((idx >>  0) & 0x3F);
     bksq = Square((idx >>  6) & 0x3F);
     us   = Color ((idx >> 12) & 0x01);
     wksq = Square((idx >>  0) & 0x3F);
     bksq = Square((idx >>  6) & 0x3F);
     us   = Color ((idx >> 12) & 0x01);
-    psq  = File  ((idx >> 13) & 0x03) | Rank(RANK_7 - (idx >> 15));
+    psq  = make_square(File((idx >> 13) & 0x03), Rank(RANK_7 - (idx >> 15)));
     result  = UNKNOWN;
 
     // Check if two pieces are on the same square or if a king can be captured
     result  = UNKNOWN;
 
     // Check if two pieces are on the same square or if a king can be captured
index 572c160d42ba60c018a64bfbe13ed4c4403f42a1..94967c25eac588043e0730eabc2c0da5a4a16745 100644 (file)
@@ -240,7 +240,7 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
   Square rsq  = relative_square(strongSide, pos.list<ROOK>(strongSide)[0]);
   Square psq  = relative_square(strongSide, pos.list<PAWN>(weakSide)[0]);
 
   Square rsq  = relative_square(strongSide, pos.list<ROOK>(strongSide)[0]);
   Square psq  = relative_square(strongSide, pos.list<PAWN>(weakSide)[0]);
 
-  Square queeningSq = file_of(psq) | RANK_1;
+  Square queeningSq = make_square(file_of(psq), 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
@@ -371,7 +371,7 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
       && !(pawns & ~file_bb(pawnFile)))
   {
       Square bishopSq = pos.list<BISHOP>(strongSide)[0];
       && !(pawns & ~file_bb(pawnFile)))
   {
       Square bishopSq = pos.list<BISHOP>(strongSide)[0];
-      Square queeningSq = relative_square(strongSide, pawnFile | RANK_8);
+      Square queeningSq = relative_square(strongSide, make_square(pawnFile, RANK_8));
       Square kingSq = pos.king_square(weakSide);
 
       if (   opposite_colors(queeningSq, bishopSq)
       Square kingSq = pos.king_square(weakSide);
 
       if (   opposite_colors(queeningSq, bishopSq)
@@ -463,7 +463,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 = f | RANK_8;
+  Square queeningSq = make_square(f, RANK_8);
   int tempo = (pos.side_to_move() == strongSide);
 
   // If the pawn is not too far advanced and the defending king defends the
   int tempo = (pos.side_to_move() == strongSide);
 
   // If the pawn is not too far advanced and the defending king defends the
@@ -721,12 +721,12 @@ ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
   if (relative_rank(strongSide, psq1) > relative_rank(strongSide, psq2))
   {
       blockSq1 = psq1 + pawn_push(strongSide);
   if (relative_rank(strongSide, psq1) > relative_rank(strongSide, psq2))
   {
       blockSq1 = psq1 + pawn_push(strongSide);
-      blockSq2 = file_of(psq2) | rank_of(psq1);
+      blockSq2 = make_square(file_of(psq2), rank_of(psq1));
   }
   else
   {
       blockSq1 = psq2 + pawn_push(strongSide);
   }
   else
   {
       blockSq1 = psq2 + pawn_push(strongSide);
-      blockSq2 = file_of(psq1) | rank_of(psq2);
+      blockSq2 = make_square(file_of(psq1), rank_of(psq2));
   }
 
   switch (file_distance(psq1, psq2))
   }
 
   switch (file_distance(psq1, psq2))
index 3ca43deb402515b61a893389bdccc96204ffe684..c74346c02930b762f48c46f91a710c9b6daf78e6 100644 (file)
@@ -70,7 +70,7 @@ const string move_to_uci(Move m, bool chess960) {
       return "0000";
 
   if (type_of(m) == CASTLING && !chess960)
       return "0000";
 
   if (type_of(m) == CASTLING && !chess960)
-      to = (to > from ? FILE_G : FILE_C) | rank_of(from);
+      to = make_square(to > from ? FILE_G : FILE_C, rank_of(from));
 
   string move = to_string(from) + to_string(to);
 
 
   string move = to_string(from) + to_string(to);
 
index 88c63ce3a3d4ad518720d887cdb7fab974f92b16..89911e50b69bd848d59bf9ae01c2549112f72f60 100644 (file)
@@ -257,7 +257,7 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) {
       b  = theirPawns & file_bb(f);
       rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
 
       b  = theirPawns & file_bb(f);
       rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
 
-      if (   (MiddleEdges & (f | rkThem))
+      if (   (MiddleEdges & make_square(f, rkThem))
           && file_of(ksq) == f
           && relative_rank(Us, ksq) == rkThem - 1)
           safety += Value(200);
           && file_of(ksq) == f
           && relative_rank(Us, ksq) == rkThem - 1)
           safety += Value(200);
index b89c645f9768b77e5974e7a40aef0517f871d0ad..788a220769c23cde1e1a15ce1298d8c32651e44f 100644 (file)
@@ -274,7 +274,7 @@ void Position::set(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 = File(token - 'A') | relative_rank(c, RANK_1);
+          rsq = make_square(File(token - 'A'), relative_rank(c, RANK_1));
 
       else
           continue;
 
       else
           continue;
@@ -286,7 +286,7 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) {
   if (   ((ss >> col) && (col >= 'a' && col <= 'h'))
       && ((ss >> row) && (row == '3' || row == '6')))
   {
   if (   ((ss >> col) && (col >= 'a' && col <= 'h'))
       && ((ss >> row) && (row == '3' || row == '6')))
   {
-      st->epSquare = File(col - 'a') | Rank(row - '1');
+      st->epSquare = make_square(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;
@@ -392,14 +392,14 @@ const string Position::fen() const {
   {
       for (File file = FILE_A; file <= FILE_H; ++file)
       {
   {
       for (File file = FILE_A; file <= FILE_H; ++file)
       {
-          for (emptyCnt = 0; file <= FILE_H && empty(file | rank); ++file)
+          for (emptyCnt = 0; file <= FILE_H && empty(make_square(file, rank)); ++file)
               ++emptyCnt;
 
           if (emptyCnt)
               ss << emptyCnt;
 
           if (file <= FILE_H)
               ++emptyCnt;
 
           if (emptyCnt)
               ss << emptyCnt;
 
           if (file <= FILE_H)
-              ss << PieceToChar[piece_on(file | rank)];
+              ss << PieceToChar[piece_on(make_square(file, rank))];
       }
 
       if (rank > RANK_1)
       }
 
       if (rank > RANK_1)
@@ -664,7 +664,7 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
   // the captured pawn.
   case ENPASSANT:
   {
   // the captured pawn.
   case ENPASSANT:
   {
-      Square capsq = file_of(to) | rank_of(from);
+      Square capsq = make_square(file_of(to), rank_of(from));
       Bitboard b = (pieces() ^ from ^ capsq) | to;
 
       return  (attacks_bb<  ROOK>(ci.ksq, b) & pieces(sideToMove, QUEEN, ROOK))
       Bitboard b = (pieces() ^ from ^ capsq) | to;
 
       return  (attacks_bb<  ROOK>(ci.ksq, b) & pieces(sideToMove, QUEEN, ROOK))
index 5002ece8c8dd202bd0fcf7a12bbd1c35d6f38368..812a370059801cb73f88bf83986c704333551941 100644 (file)
@@ -337,10 +337,6 @@ inline Square operator~(Square s) {
   return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
 }
 
   return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
 }
 
-inline Square operator|(File f, Rank r) {
-  return Square((r << 3) | f);
-}
-
 inline CastlingRight operator|(Color c, CastlingSide s) {
   return CastlingRight(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c));
 }
 inline CastlingRight operator|(Color c, CastlingSide s) {
   return CastlingRight(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c));
 }
@@ -353,6 +349,10 @@ inline Value mated_in(int ply) {
   return -VALUE_MATE + ply;
 }
 
   return -VALUE_MATE + ply;
 }
 
+inline Square make_square(File f, Rank r) {
+  return Square((r << 3) | f);
+}
+
 inline Piece make_piece(Color c, PieceType pt) {
   return Piece((c << 3) | pt);
 }
 inline Piece make_piece(Color c, PieceType pt) {
   return Piece((c << 3) | pt);
 }