]> git.sesse.net Git - stockfish/commitdiff
Better naming borrowed from Critter
authorMarco Costalba <mcostalba@gmail.com>
Sun, 2 Oct 2011 07:33:40 +0000 (08:33 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 2 Oct 2011 09:16:59 +0000 (10:16 +0100)
In line with http://chessprogramming.wikispaces.com conventions.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
16 files changed:
src/bitbase.cpp
src/bitboard.cpp
src/bitboard.h
src/book.cpp
src/endgame.cpp
src/endgame.h
src/evaluate.cpp
src/move.cpp
src/movegen.cpp
src/movepick.cpp
src/pawns.cpp
src/position.cpp
src/position.h
src/search.cpp
src/types.h
src/uci.cpp

index fda5030d247e8dd82925151635886d57520dd93f..96ada8dd59d2ac95e6dd6ab2d7d8826db0022354 100644 (file)
@@ -104,9 +104,9 @@ namespace {
 
   int compute_index(Square wksq, Square bksq, Square wpsq, Color stm) {
 
 
   int compute_index(Square wksq, Square bksq, Square wpsq, Color stm) {
 
-    assert(square_file(wpsq) <= FILE_D);
+    assert(file_of(wpsq) <= FILE_D);
 
 
-    int p = square_file(wpsq) + 4 * (square_rank(wpsq) - 1);
+    int p = file_of(wpsq) + 4 * (rank_of(wpsq) - 1);
     int r = stm + 2 * bksq + 128 * wksq + 8192 * p;
 
     assert(r >= 0 && r < IndexMax);
     int r = stm + 2 * bksq + 128 * wksq + 8192 * p;
 
     assert(r >= 0 && r < IndexMax);
@@ -140,7 +140,7 @@ namespace {
 
     // The position is an immediate win if it is white to move and the
     // white pawn can be promoted without getting captured.
 
     // The position is an immediate win if it is white to move and the
     // white pawn can be promoted without getting captured.
-    if (   square_rank(pawnSquare) == RANK_7
+    if (   rank_of(pawnSquare) == RANK_7
         && sideToMove == WHITE
         && whiteKingSquare != pawnSquare + DELTA_N
         && (   square_distance(blackKingSquare, pawnSquare + DELTA_N) > 1
         && sideToMove == WHITE
         && whiteKingSquare != pawnSquare + DELTA_N
         && (   square_distance(blackKingSquare, pawnSquare + DELTA_N) > 1
@@ -161,19 +161,19 @@ namespace {
 
     // Case 3: Black king in front of white pawn
     if (   blackKingSquare == pawnSquare + DELTA_N
 
     // Case 3: Black king in front of white pawn
     if (   blackKingSquare == pawnSquare + DELTA_N
-        && square_rank(pawnSquare) < RANK_7)
+        && rank_of(pawnSquare) < RANK_7)
         return RESULT_DRAW;
 
     //  Case 4: White king in front of pawn and black has opposition
     if (   whiteKingSquare == pawnSquare + DELTA_N
         && blackKingSquare == pawnSquare + DELTA_N + DELTA_N + DELTA_N
         return RESULT_DRAW;
 
     //  Case 4: White king in front of pawn and black has opposition
     if (   whiteKingSquare == pawnSquare + DELTA_N
         && blackKingSquare == pawnSquare + DELTA_N + DELTA_N + DELTA_N
-        && square_rank(pawnSquare) < RANK_5
+        && rank_of(pawnSquare) < RANK_5
         && sideToMove == WHITE)
         return RESULT_DRAW;
 
     // Case 5: Stalemate with rook pawn
     if (   blackKingSquare == SQ_A8
         && sideToMove == WHITE)
         return RESULT_DRAW;
 
     // Case 5: Stalemate with rook pawn
     if (   blackKingSquare == SQ_A8
-        && square_file(pawnSquare) == FILE_A)
+        && file_of(pawnSquare) == FILE_A)
         return RESULT_DRAW;
 
     return RESULT_UNKNOWN;
         return RESULT_DRAW;
 
     return RESULT_UNKNOWN;
@@ -213,7 +213,7 @@ namespace {
     }
 
     // Pawn moves
     }
 
     // Pawn moves
-    if (square_rank(pawnSquare) < RANK_7)
+    if (rank_of(pawnSquare) < RANK_7)
     {
         s = pawnSquare + DELTA_N;
         r = db[compute_index(whiteKingSquare, blackKingSquare, s, BLACK)];
     {
         s = pawnSquare + DELTA_N;
         r = db[compute_index(whiteKingSquare, blackKingSquare, s, BLACK)];
@@ -225,7 +225,7 @@ namespace {
             unknownFound = true;
 
         // Double pawn push
             unknownFound = true;
 
         // Double pawn push
-        if (square_rank(s) == RANK_3 && r != RESULT_INVALID)
+        if (rank_of(s) == RANK_3 && r != RESULT_INVALID)
         {
             s += DELTA_N;
             r = db[compute_index(whiteKingSquare, blackKingSquare, s, BLACK)];
         {
             s += DELTA_N;
             r = db[compute_index(whiteKingSquare, blackKingSquare, s, BLACK)];
index 073487e99cf252a02f9ed6656a31578048264279..3bed69bead7665dc9a51e53f29008d67ab8fda9e 100644 (file)
@@ -325,7 +325,7 @@ namespace {
         } while (b);
 
         offset += maxKey;
         } while (b);
 
         offset += maxKey;
-        booster = MagicBoosters[CpuIs64Bit][square_rank(s)];
+        booster = MagicBoosters[CpuIs64Bit][rank_of(s)];
 
         // Then find a possible magic and the corresponding attacks
         do {
 
         // Then find a possible magic and the corresponding attacks
         do {
index 55f40eee2e8e2414c2af55c4e1c5c949670fd982..59de12886e513f55b6ba2ffae18cfe4ce96986bd 100644 (file)
@@ -113,7 +113,7 @@ inline Bitboard rank_bb(Rank r) {
 }
 
 inline Bitboard rank_bb(Square s) {
 }
 
 inline Bitboard rank_bb(Square s) {
-  return RankBB[square_rank(s)];
+  return RankBB[rank_of(s)];
 }
 
 inline Bitboard file_bb(File f) {
 }
 
 inline Bitboard file_bb(File f) {
@@ -121,7 +121,7 @@ inline Bitboard file_bb(File f) {
 }
 
 inline Bitboard file_bb(Square s) {
 }
 
 inline Bitboard file_bb(Square s) {
-  return FileBB[square_file(s)];
+  return FileBB[file_of(s)];
 }
 
 
 }
 
 
@@ -133,7 +133,7 @@ inline Bitboard neighboring_files_bb(File f) {
 }
 
 inline Bitboard neighboring_files_bb(Square s) {
 }
 
 inline Bitboard neighboring_files_bb(Square s) {
-  return NeighboringFilesBB[square_file(s)];
+  return NeighboringFilesBB[file_of(s)];
 }
 
 
 }
 
 
@@ -145,7 +145,7 @@ inline Bitboard this_and_neighboring_files_bb(File f) {
 }
 
 inline Bitboard this_and_neighboring_files_bb(Square s) {
 }
 
 inline Bitboard this_and_neighboring_files_bb(Square s) {
-  return ThisAndNeighboringFilesBB[square_file(s)];
+  return ThisAndNeighboringFilesBB[file_of(s)];
 }
 
 
 }
 
 
@@ -160,7 +160,7 @@ inline Bitboard in_front_bb(Color c, Rank r) {
 }
 
 inline Bitboard in_front_bb(Color c, Square s) {
 }
 
 inline Bitboard in_front_bb(Color c, Square s) {
-  return InFrontBB[c][square_rank(s)];
+  return InFrontBB[c][rank_of(s)];
 }
 
 
 }
 
 
index fcaccf6f7560fe92c24cccc22428166f77ca5e03..7dac7e7233ac3d2f052011470ed163ea7f679881 100644 (file)
@@ -335,7 +335,7 @@ namespace {
         result ^= ZobCastle[3];
 
     if (pos.ep_square() != SQ_NONE)
         result ^= ZobCastle[3];
 
     if (pos.ep_square() != SQ_NONE)
-        result ^= ZobEnPassant[square_file(pos.ep_square())];
+        result ^= ZobEnPassant[file_of(pos.ep_square())];
 
     if (pos.side_to_move() == WHITE)
         result ^= ZobTurn[0];
 
     if (pos.side_to_move() == WHITE)
         result ^= ZobTurn[0];
index 3f8094b6d0c321c5105b7008b7eb9ea69df689f6..c2e892eef0b9d8e712151b2d148786cbfae4bb09 100644 (file)
@@ -189,8 +189,8 @@ Value Endgame<KBNK>::apply(const Position& pos) const {
   // mirror the kings so to drive enemy toward corners A8 or H1.
   if (opposite_color_squares(bishopSquare, SQ_A1))
   {
   // mirror the kings so to drive enemy toward corners A8 or H1.
   if (opposite_color_squares(bishopSquare, SQ_A1))
   {
-      winnerKSq = flop_square(winnerKSq);
-      loserKSq = flop_square(loserKSq);
+      winnerKSq = mirror(winnerKSq);
+      loserKSq = mirror(loserKSq);
   }
 
   Value result =  VALUE_KNOWN_WIN
   }
 
   Value result =  VALUE_KNOWN_WIN
@@ -222,17 +222,17 @@ Value Endgame<KPK>::apply(const Position& pos) const {
   }
   else
   {
   }
   else
   {
-      wksq = flip_square(pos.king_square(BLACK));
-      bksq = flip_square(pos.king_square(WHITE));
-      wpsq = flip_square(pos.piece_list(BLACK, PAWN)[0]);
-      stm = opposite_color(pos.side_to_move());
+      wksq = flip(pos.king_square(BLACK));
+      bksq = flip(pos.king_square(WHITE));
+      wpsq = flip(pos.piece_list(BLACK, PAWN)[0]);
+      stm = flip(pos.side_to_move());
   }
 
   }
 
-  if (square_file(wpsq) >= FILE_E)
+  if (file_of(wpsq) >= FILE_E)
   {
   {
-      wksq = flop_square(wksq);
-      bksq = flop_square(bksq);
-      wpsq = flop_square(wpsq);
+      wksq = mirror(wksq);
+      bksq = mirror(bksq);
+      wpsq = mirror(wpsq);
   }
 
   if (!probe_kpk_bitbase(wksq, wpsq, bksq, stm))
   }
 
   if (!probe_kpk_bitbase(wksq, wpsq, bksq, stm))
@@ -240,7 +240,7 @@ Value Endgame<KPK>::apply(const Position& pos) const {
 
   Value result =  VALUE_KNOWN_WIN
                 + PawnValueEndgame
 
   Value result =  VALUE_KNOWN_WIN
                 + PawnValueEndgame
-                + Value(square_rank(wpsq));
+                + Value(rank_of(wpsq));
 
   return strongerSide == pos.side_to_move() ? result : -result;
 }
 
   return strongerSide == pos.side_to_move() ? result : -result;
 }
@@ -268,17 +268,17 @@ Value Endgame<KRKP>::apply(const Position& pos) const {
 
   if (strongerSide == BLACK)
   {
 
   if (strongerSide == BLACK)
   {
-      wksq = flip_square(wksq);
-      wrsq = flip_square(wrsq);
-      bksq = flip_square(bksq);
-      bpsq = flip_square(bpsq);
+      wksq = flip(wksq);
+      wrsq = flip(wrsq);
+      bksq = flip(bksq);
+      bpsq = flip(bpsq);
   }
 
   }
 
-  Square queeningSq = make_square(square_file(bpsq), RANK_1);
+  Square queeningSq = make_square(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
-  if (wksq < bpsq && square_file(wksq) == square_file(bpsq))
+  if (wksq < bpsq && file_of(wksq) == file_of(bpsq))
       result = RookValueEndgame - Value(square_distance(wksq, bpsq));
 
   // If the weaker side's king is too far from the pawn and the rook,
       result = RookValueEndgame - Value(square_distance(wksq, bpsq));
 
   // If the weaker side's king is too far from the pawn and the rook,
@@ -289,9 +289,9 @@ Value Endgame<KRKP>::apply(const Position& pos) const {
 
   // If the pawn is far advanced and supported by the defending king,
   // the position is drawish
 
   // If the pawn is far advanced and supported by the defending king,
   // the position is drawish
-  else if (   square_rank(bksq) <= RANK_3
+  else if (   rank_of(bksq) <= RANK_3
            && square_distance(bksq, bpsq) == 1
            && square_distance(bksq, bpsq) == 1
-           && square_rank(wksq) >= RANK_4
+           && rank_of(wksq) >= RANK_4
            && square_distance(wksq, bpsq) - tempo > 2)
       result = Value(80 - square_distance(wksq, bpsq) * 8);
 
            && square_distance(wksq, bpsq) - tempo > 2)
       result = Value(80 - square_distance(wksq, bpsq) * 8);
 
@@ -423,7 +423,7 @@ ScaleFactor Endgame<KBPsK>::apply(const Position& pos) const {
   // be detected even when the weaker side has some pawns.
 
   Bitboard pawns = pos.pieces(PAWN, strongerSide);
   // 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 = file_of(pos.piece_list(strongerSide, PAWN)[0]);
 
   // All pawns are on a single rook file ?
   if (   (pawnFile == FILE_A || pawnFile == FILE_H)
 
   // All pawns are on a single rook file ?
   if (   (pawnFile == FILE_A || pawnFile == FILE_H)
@@ -434,7 +434,7 @@ ScaleFactor Endgame<KBPsK>::apply(const Position& pos) const {
       Square kingSq = pos.king_square(weakerSide);
 
       if (   opposite_color_squares(queeningSq, bishopSq)
       Square kingSq = pos.king_square(weakerSide);
 
       if (   opposite_color_squares(queeningSq, bishopSq)
-          && abs(square_file(kingSq) - pawnFile) <= 1)
+          && abs(file_of(kingSq) - pawnFile) <= 1)
       {
           // The bishop has the wrong color, and the defending king is on the
           // file of the pawn(s) or the neighboring file. Find the rank of the
       {
           // The bishop has the wrong color, and the defending king is on the
           // file of the pawn(s) or the neighboring file. Find the rank of the
@@ -515,23 +515,23 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
   // pawn is on the left half of the board.
   if (strongerSide == BLACK)
   {
   // pawn is on the left half of the board.
   if (strongerSide == BLACK)
   {
-      wksq = flip_square(wksq);
-      wrsq = flip_square(wrsq);
-      wpsq = flip_square(wpsq);
-      bksq = flip_square(bksq);
-      brsq = flip_square(brsq);
+      wksq = flip(wksq);
+      wrsq = flip(wrsq);
+      wpsq = flip(wpsq);
+      bksq = flip(bksq);
+      brsq = flip(brsq);
   }
   }
-  if (square_file(wpsq) > FILE_D)
+  if (file_of(wpsq) > FILE_D)
   {
   {
-      wksq = flop_square(wksq);
-      wrsq = flop_square(wrsq);
-      wpsq = flop_square(wpsq);
-      bksq = flop_square(bksq);
-      brsq = flop_square(brsq);
+      wksq = mirror(wksq);
+      wrsq = mirror(wrsq);
+      wpsq = mirror(wpsq);
+      bksq = mirror(bksq);
+      brsq = mirror(brsq);
   }
 
   }
 
-  File f = square_file(wpsq);
-  Rank r = square_rank(wpsq);
+  File f = file_of(wpsq);
+  Rank r = rank_of(wpsq);
   Square queeningSq = make_square(f, RANK_8);
   int tempo = (pos.side_to_move() == strongerSide);
 
   Square queeningSq = make_square(f, RANK_8);
   int tempo = (pos.side_to_move() == strongerSide);
 
@@ -540,20 +540,20 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
   if (   r <= RANK_5
       && square_distance(bksq, queeningSq) <= 1
       && wksq <= SQ_H5
   if (   r <= RANK_5
       && square_distance(bksq, queeningSq) <= 1
       && wksq <= SQ_H5
-      && (square_rank(brsq) == RANK_6 || (r <= RANK_3 && square_rank(wrsq) != RANK_6)))
+      && (rank_of(brsq) == RANK_6 || (r <= RANK_3 && rank_of(wrsq) != RANK_6)))
       return SCALE_FACTOR_ZERO;
 
   // The defending side saves a draw by checking from behind in case the pawn
   // has advanced to the 6th rank with the king behind.
   if (   r == RANK_6
       && square_distance(bksq, queeningSq) <= 1
       return SCALE_FACTOR_ZERO;
 
   // The defending side saves a draw by checking from behind in case the pawn
   // has advanced to the 6th rank with the king behind.
   if (   r == RANK_6
       && square_distance(bksq, queeningSq) <= 1
-      && square_rank(wksq) + tempo <= RANK_6
-      && (square_rank(brsq) == RANK_1 || (!tempo && abs(square_file(brsq) - f) >= 3)))
+      && rank_of(wksq) + tempo <= RANK_6
+      && (rank_of(brsq) == RANK_1 || (!tempo && abs(file_of(brsq) - f) >= 3)))
       return SCALE_FACTOR_ZERO;
 
   if (   r >= RANK_6
       && bksq == queeningSq
       return SCALE_FACTOR_ZERO;
 
   if (   r >= RANK_6
       && bksq == queeningSq
-      && square_rank(brsq) == RANK_1
+      && rank_of(brsq) == RANK_1
       && (!tempo || square_distance(wksq, wpsq) >= 2))
       return SCALE_FACTOR_ZERO;
 
       && (!tempo || square_distance(wksq, wpsq) >= 2))
       return SCALE_FACTOR_ZERO;
 
@@ -562,8 +562,8 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
   if (   wpsq == SQ_A7
       && wrsq == SQ_A8
       && (bksq == SQ_H7 || bksq == SQ_G7)
   if (   wpsq == SQ_A7
       && wrsq == SQ_A8
       && (bksq == SQ_H7 || bksq == SQ_G7)
-      && square_file(brsq) == FILE_A
-      && (square_rank(brsq) <= RANK_3 || square_file(wksq) >= FILE_D || square_rank(wksq) <= RANK_5))
+      && file_of(brsq) == FILE_A
+      && (rank_of(brsq) <= RANK_3 || file_of(wksq) >= FILE_D || rank_of(wksq) <= RANK_5))
       return SCALE_FACTOR_ZERO;
 
   // If the defending king blocks the pawn and the attacking king is too far
       return SCALE_FACTOR_ZERO;
 
   // If the defending king blocks the pawn and the attacking king is too far
@@ -579,7 +579,7 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
   // and the defending king cannot gain tempi by threatening the attacking rook.
   if (   r == RANK_7
       && f != FILE_A
   // and the defending king cannot gain tempi by threatening the attacking rook.
   if (   r == RANK_7
       && f != FILE_A
-      && square_file(wrsq) == f
+      && file_of(wrsq) == f
       && wrsq != queeningSq
       && (square_distance(wksq, queeningSq) < square_distance(bksq, queeningSq) - 2 + tempo)
       && (square_distance(wksq, queeningSq) < square_distance(bksq, wrsq) + tempo))
       && wrsq != queeningSq
       && (square_distance(wksq, queeningSq) < square_distance(bksq, queeningSq) - 2 + tempo)
       && (square_distance(wksq, queeningSq) < square_distance(bksq, wrsq) + tempo))
@@ -587,7 +587,7 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
 
   // Similar to the above, but with the pawn further back
   if (   f != FILE_A
 
   // Similar to the above, but with the pawn further back
   if (   f != FILE_A
-      && square_file(wrsq) == f
+      && file_of(wrsq) == f
       && wrsq < wpsq
       && (square_distance(wksq, queeningSq) < square_distance(bksq, queeningSq) - 2 + tempo)
       && (square_distance(wksq, wpsq + DELTA_N) < square_distance(bksq, wpsq + DELTA_N) - 2 + tempo)
       && wrsq < wpsq
       && (square_distance(wksq, queeningSq) < square_distance(bksq, queeningSq) - 2 + tempo)
       && (square_distance(wksq, wpsq + DELTA_N) < square_distance(bksq, wpsq + DELTA_N) - 2 + tempo)
@@ -602,9 +602,9 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
   // the pawn's path, it's probably a draw.
   if (r <= RANK_4 && bksq > wpsq)
   {
   // the pawn's path, it's probably a draw.
   if (r <= RANK_4 && bksq > wpsq)
   {
-      if (square_file(bksq) == square_file(wpsq))
+      if (file_of(bksq) == file_of(wpsq))
           return ScaleFactor(10);
           return ScaleFactor(10);
-      if (   abs(square_file(bksq) - square_file(wpsq)) == 1
+      if (   abs(file_of(bksq) - file_of(wpsq)) == 1
           && square_distance(wksq, bksq) > 2)
           return ScaleFactor(24 - 2 * square_distance(wksq, bksq));
   }
           && square_distance(wksq, bksq) > 2)
           return ScaleFactor(24 - 2 * square_distance(wksq, bksq));
   }
@@ -670,7 +670,7 @@ ScaleFactor Endgame<KPsK>::apply(const Position& pos) const {
   {
       // Does the defending king block the pawns?
       if (   square_distance(ksq, relative_square(strongerSide, SQ_A8)) <= 1
   {
       // Does the defending king block the pawns?
       if (   square_distance(ksq, relative_square(strongerSide, SQ_A8)) <= 1
-          || (   square_file(ksq) == FILE_A
+          || (   file_of(ksq) == FILE_A
               && (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
           return SCALE_FACTOR_ZERO;
   }
               && (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
           return SCALE_FACTOR_ZERO;
   }
@@ -679,7 +679,7 @@ ScaleFactor Endgame<KPsK>::apply(const Position& pos) const {
   {
     // Does the defending king block the pawns?
     if (   square_distance(ksq, relative_square(strongerSide, SQ_H8)) <= 1
   {
     // Does the defending king block the pawns?
     if (   square_distance(ksq, relative_square(strongerSide, SQ_H8)) <= 1
-        || (   square_file(ksq) == FILE_H
+        || (   file_of(ksq) == FILE_H
             && (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
         return SCALE_FACTOR_ZERO;
   }
             && (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
         return SCALE_FACTOR_ZERO;
   }
@@ -708,7 +708,7 @@ ScaleFactor Endgame<KBPKB>::apply(const Position& pos) const {
   Square weakerKingSq = pos.king_square(weakerSide);
 
   // Case 1: Defending king blocks the pawn, and cannot be driven away
   Square weakerKingSq = pos.king_square(weakerSide);
 
   // Case 1: Defending king blocks the pawn, and cannot be driven away
-  if (   square_file(weakerKingSq) == square_file(pawnSq)
+  if (   file_of(weakerKingSq) == file_of(pawnSq)
       && relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
       && (   opposite_color_squares(weakerKingSq, strongerBishopSq)
           || relative_rank(strongerSide, weakerKingSq) <= RANK_6))
       && relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
       && (   opposite_color_squares(weakerKingSq, strongerBishopSq)
           || relative_rank(strongerSide, weakerKingSq) <= RANK_6))
@@ -766,19 +766,19 @@ ScaleFactor Endgame<KBPPKB>::apply(const Position& pos) const {
   Square ksq = pos.king_square(weakerSide);
   Square psq1 = pos.piece_list(strongerSide, PAWN)[0];
   Square psq2 = pos.piece_list(strongerSide, PAWN)[1];
   Square ksq = pos.king_square(weakerSide);
   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);
+  Rank r1 = rank_of(psq1);
+  Rank r2 = rank_of(psq2);
   Square blockSq1, blockSq2;
 
   if (relative_rank(strongerSide, psq1) > relative_rank(strongerSide, psq2))
   {
       blockSq1 = psq1 + pawn_push(strongerSide);
   Square blockSq1, blockSq2;
 
   if (relative_rank(strongerSide, psq1) > relative_rank(strongerSide, psq2))
   {
       blockSq1 = psq1 + pawn_push(strongerSide);
-      blockSq2 = make_square(square_file(psq2), square_rank(psq1));
+      blockSq2 = make_square(file_of(psq2), rank_of(psq1));
   }
   else
   {
       blockSq1 = psq2 + pawn_push(strongerSide);
   }
   else
   {
       blockSq1 = psq2 + pawn_push(strongerSide);
-      blockSq2 = make_square(square_file(psq1), square_rank(psq2));
+      blockSq2 = make_square(file_of(psq1), rank_of(psq2));
   }
 
   switch (file_distance(psq1, psq2))
   }
 
   switch (file_distance(psq1, psq2))
@@ -786,7 +786,7 @@ ScaleFactor Endgame<KBPPKB>::apply(const Position& pos) const {
   case 0:
     // Both pawns are on the same file. Easy draw if defender firmly controls
     // some square in the frontmost pawn's path.
   case 0:
     // Both pawns are on the same file. Easy draw if defender firmly controls
     // some square in the frontmost pawn's path.
-    if (   square_file(ksq) == square_file(blockSq1)
+    if (   file_of(ksq) == file_of(blockSq1)
         && relative_rank(strongerSide, ksq) >= relative_rank(strongerSide, blockSq1)
         && opposite_color_squares(ksq, wbsq))
         return SCALE_FACTOR_ZERO;
         && relative_rank(strongerSide, ksq) >= relative_rank(strongerSide, blockSq1)
         && opposite_color_squares(ksq, wbsq))
         return SCALE_FACTOR_ZERO;
@@ -837,7 +837,7 @@ ScaleFactor Endgame<KBPKN>::apply(const Position& pos) const {
   Square strongerBishopSq = pos.piece_list(strongerSide, BISHOP)[0];
   Square weakerKingSq = pos.king_square(weakerSide);
 
   Square strongerBishopSq = pos.piece_list(strongerSide, BISHOP)[0];
   Square weakerKingSq = pos.king_square(weakerSide);
 
-  if (   square_file(weakerKingSq) == square_file(pawnSq)
+  if (   file_of(weakerKingSq) == file_of(pawnSq)
       && relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
       && (   opposite_color_squares(weakerKingSq, strongerBishopSq)
           || relative_rank(strongerSide, weakerKingSq) <= RANK_6))
       && relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
       && (   opposite_color_squares(weakerKingSq, strongerBishopSq)
           || relative_rank(strongerSide, weakerKingSq) <= RANK_6))
@@ -900,23 +900,23 @@ ScaleFactor Endgame<KPKP>::apply(const Position& pos) const {
   }
   else
   {
   }
   else
   {
-      wksq = flip_square(pos.king_square(BLACK));
-      bksq = flip_square(pos.king_square(WHITE));
-      wpsq = flip_square(pos.piece_list(BLACK, PAWN)[0]);
-      stm = opposite_color(pos.side_to_move());
+      wksq = flip(pos.king_square(BLACK));
+      bksq = flip(pos.king_square(WHITE));
+      wpsq = flip(pos.piece_list(BLACK, PAWN)[0]);
+      stm = flip(pos.side_to_move());
   }
 
   }
 
-  if (square_file(wpsq) >= FILE_E)
+  if (file_of(wpsq) >= FILE_E)
   {
   {
-      wksq = flop_square(wksq);
-      bksq = flop_square(bksq);
-      wpsq = flop_square(wpsq);
+      wksq = mirror(wksq);
+      bksq = mirror(bksq);
+      wpsq = mirror(wpsq);
   }
 
   // If the pawn has advanced to the fifth rank or further, and is not a
   // rook pawn, it's too dangerous to assume that it's at least a draw.
   }
 
   // If the pawn has advanced to the fifth rank or further, and is not a
   // rook pawn, it's too dangerous to assume that it's at least a draw.
-  if (   square_rank(wpsq) >= RANK_5
-      && square_file(wpsq) != FILE_A)
+  if (   rank_of(wpsq) >= RANK_5
+      && file_of(wpsq) != FILE_A)
       return SCALE_FACTOR_NONE;
 
   // Probe the KPK bitbase with the weakest side's pawn removed. If it's a
       return SCALE_FACTOR_NONE;
 
   // Probe the KPK bitbase with the weakest side's pawn removed. If it's a
index efc527a7f98f30980fd8677e3ab35568a4a78a36..e26418c05a7f1a2d6ea7fedb6667d09f01bf4d0f 100644 (file)
@@ -82,7 +82,7 @@ struct EndgameBase {
 template<EndgameType E, typename T = typename eg_family<E>::type>
 struct Endgame : public EndgameBase<T> {
 
 template<EndgameType E, typename T = typename eg_family<E>::type>
 struct Endgame : public EndgameBase<T> {
 
-  explicit Endgame(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
+  explicit Endgame(Color c) : strongerSide(c), weakerSide(flip(c)) {}
   Color color() const { return strongerSide; }
   T apply(const Position&) const;
 
   Color color() const { return strongerSide; }
   T apply(const Position&) const;
 
index 13475ad4c343e23f40bc546c72bbfd991eef8545..41f55ab9dbc8cbe02afbb01e09492bfa92910f14 100644 (file)
@@ -546,7 +546,7 @@ namespace {
             // problem, especially when that pawn is also blocked.
             if (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1))
             {
             // problem, especially when that pawn is also blocked.
             if (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1))
             {
-                Square d = pawn_push(Us) + (square_file(s) == FILE_A ? DELTA_E : DELTA_W);
+                Square d = pawn_push(Us) + (file_of(s) == FILE_A ? DELTA_E : DELTA_W);
                 if (pos.piece_on(s + d) == make_piece(Us, PAWN))
                 {
                     if (!pos.square_is_empty(s + d + pawn_push(Us)))
                 if (pos.piece_on(s + d) == make_piece(Us, PAWN))
                 {
                     if (!pos.square_is_empty(s + d + pawn_push(Us)))
@@ -563,7 +563,7 @@ namespace {
         if (Piece == ROOK)
         {
             // Open and half-open files
         if (Piece == ROOK)
         {
             // Open and half-open files
-            f = square_file(s);
+            f = file_of(s);
             if (ei.pi->file_is_half_open(Us, f))
             {
                 if (ei.pi->file_is_half_open(Them, f))
             if (ei.pi->file_is_half_open(Us, f))
             {
                 if (ei.pi->file_is_half_open(Them, f))
@@ -579,21 +579,21 @@ namespace {
 
             ksq = pos.king_square(Us);
 
 
             ksq = pos.king_square(Us);
 
-            if (    square_file(ksq) >= FILE_E
-                &&  square_file(s) > square_file(ksq)
-                && (relative_rank(Us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
+            if (    file_of(ksq) >= FILE_E
+                &&  file_of(s) > file_of(ksq)
+                && (relative_rank(Us, ksq) == RANK_1 || rank_of(ksq) == rank_of(s)))
             {
                 // Is there a half-open file between the king and the edge of the board?
             {
                 // Is there a half-open file between the king and the edge of the board?
-                if (!ei.pi->has_open_file_to_right(Us, square_file(ksq)))
+                if (!ei.pi->has_open_file_to_right(Us, file_of(ksq)))
                     score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2
                                                            : (TrappedRookPenalty - mob * 16), 0);
             }
                     score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2
                                                            : (TrappedRookPenalty - mob * 16), 0);
             }
-            else if (    square_file(ksq) <= FILE_D
-                     &&  square_file(s) < square_file(ksq)
-                     && (relative_rank(Us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
+            else if (    file_of(ksq) <= FILE_D
+                     &&  file_of(s) < file_of(ksq)
+                     && (relative_rank(Us, ksq) == RANK_1 || rank_of(ksq) == rank_of(s)))
             {
                 // Is there a half-open file between the king and the edge of the board?
             {
                 // Is there a half-open file between the king and the edge of the board?
-                if (!ei.pi->has_open_file_to_left(Us, square_file(ksq)))
+                if (!ei.pi->has_open_file_to_left(Us, file_of(ksq)))
                     score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2
                                                            : (TrappedRookPenalty - mob * 16), 0);
             }
                     score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2
                                                            : (TrappedRookPenalty - mob * 16), 0);
             }
@@ -816,7 +816,7 @@ namespace {
             ebonus -= Value(square_distance(pos.king_square(Us), blockSq) * 3 * rr);
 
             // If blockSq is not the queening square then consider also a second push
             ebonus -= Value(square_distance(pos.king_square(Us), blockSq) * 3 * rr);
 
             // If blockSq is not the queening square then consider also a second push
-            if (square_rank(blockSq) != (Us == WHITE ? RANK_8 : RANK_1))
+            if (rank_of(blockSq) != (Us == WHITE ? RANK_8 : RANK_1))
                 ebonus -= Value(square_distance(pos.king_square(Us), blockSq + pawn_push(Us)) * rr);
 
             // If the pawn is free to advance, increase bonus
                 ebonus -= Value(square_distance(pos.king_square(Us), blockSq + pawn_push(Us)) * rr);
 
             // If the pawn is free to advance, increase bonus
@@ -866,7 +866,7 @@ namespace {
         // we try the following: Increase the value for rook pawns if the
         // other side has no pieces apart from a knight, and decrease the
         // value if the other side has a rook or queen.
         // we try the following: Increase the value for rook pawns if the
         // other side has no pieces apart from a knight, and decrease the
         // value if the other side has a rook or queen.
-        if (square_file(s) == FILE_A || square_file(s) == FILE_H)
+        if (file_of(s) == FILE_A || file_of(s) == FILE_H)
         {
             if (pos.non_pawn_material(Them) <= KnightValueMidgame)
                 ebonus += ebonus / 4;
         {
             if (pos.non_pawn_material(Them) <= KnightValueMidgame)
                 ebonus += ebonus / 4;
@@ -902,7 +902,7 @@ namespace {
     for (c = WHITE; c <= BLACK; c++)
     {
         // Skip if other side has non-pawn pieces
     for (c = WHITE; c <= BLACK; c++)
     {
         // Skip if other side has non-pawn pieces
-        if (pos.non_pawn_material(opposite_color(c)))
+        if (pos.non_pawn_material(flip(c)))
             continue;
 
         b = ei.pi->passed_pawns(c);
             continue;
 
         b = ei.pi->passed_pawns(c);
@@ -910,12 +910,12 @@ namespace {
         while (b)
         {
             s = pop_1st_bit(&b);
         while (b)
         {
             s = pop_1st_bit(&b);
-            queeningSquare = relative_square(c, make_square(square_file(s), RANK_8));
+            queeningSquare = relative_square(c, make_square(file_of(s), RANK_8));
             queeningPath = squares_in_front_of(c, s);
 
             // Compute plies to queening and check direct advancement
             movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(c, s) == RANK_2);
             queeningPath = squares_in_front_of(c, s);
 
             // Compute plies to queening and check direct advancement
             movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(c, s) == RANK_2);
-            oppMovesToGo = square_distance(pos.king_square(opposite_color(c)), queeningSquare) - int(c != pos.side_to_move());
+            oppMovesToGo = square_distance(pos.king_square(flip(c)), queeningSquare) - int(c != pos.side_to_move());
             pathDefended = ((ei.attackedBy[c][0] & queeningPath) == queeningPath);
 
             if (movesToGo >= oppMovesToGo && !pathDefended)
             pathDefended = ((ei.attackedBy[c][0] & queeningPath) == queeningPath);
 
             if (movesToGo >= oppMovesToGo && !pathDefended)
@@ -943,7 +943,7 @@ namespace {
         return SCORE_ZERO;
 
     winnerSide = (pliesToQueen[WHITE] < pliesToQueen[BLACK] ? WHITE : BLACK);
         return SCORE_ZERO;
 
     winnerSide = (pliesToQueen[WHITE] < pliesToQueen[BLACK] ? WHITE : BLACK);
-    loserSide = opposite_color(winnerSide);
+    loserSide = flip(winnerSide);
 
     // Step 3. Can the losing side possibly create a new passed pawn and thus prevent the loss?
     b = candidates = pos.pieces(PAWN, loserSide);
 
     // Step 3. Can the losing side possibly create a new passed pawn and thus prevent the loss?
     b = candidates = pos.pieces(PAWN, loserSide);
@@ -953,7 +953,7 @@ namespace {
         s = pop_1st_bit(&b);
 
         // Compute plies from queening
         s = pop_1st_bit(&b);
 
         // Compute plies from queening
-        queeningSquare = relative_square(loserSide, make_square(square_file(s), RANK_8));
+        queeningSquare = relative_square(loserSide, make_square(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());
 
@@ -977,7 +977,7 @@ namespace {
         minKingDist = kingptg = 256;
 
         // Compute plies from queening
         minKingDist = kingptg = 256;
 
         // Compute plies from queening
-        queeningSquare = relative_square(loserSide, make_square(square_file(s), RANK_8));
+        queeningSquare = relative_square(loserSide, make_square(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 4a9705446454d78298db32fec024985bb234f11b..2a74aef1ad2378bad5ab1889de2f8c441f7abef2 100644 (file)
@@ -45,7 +45,7 @@ const string move_to_uci(Move m, bool chess960) {
       return "0000";
 
   if (move_is_castle(m) && !chess960)
       return "0000";
 
   if (move_is_castle(m) && !chess960)
-      to = from + (square_file(to) == FILE_H ? Square(2) : -Square(2));
+      to = from + (file_of(to) == FILE_H ? Square(2) : -Square(2));
 
   if (move_is_promotion(m))
       promotion = char(tolower(piece_type_to_char(promotion_piece_type(m))));
 
   if (move_is_promotion(m))
       promotion = char(tolower(piece_type_to_char(promotion_piece_type(m))));
@@ -86,7 +86,7 @@ const string move_to_san(Position& pos, Move m) {
   bool ambiguousMove, ambiguousFile, ambiguousRank;
   Square sq, from = move_from(m);
   Square to = move_to(m);
   bool ambiguousMove, ambiguousFile, ambiguousRank;
   Square sq, from = move_from(m);
   Square to = move_to(m);
-  PieceType pt = piece_type(pos.piece_on(from));
+  PieceType pt = type_of(pos.piece_on(from));
   string san;
 
   if (move_is_castle(m))
   string san;
 
   if (move_is_castle(m))
@@ -107,10 +107,10 @@ const string move_to_san(Position& pos, Move m) {
           {
               sq = pop_1st_bit(&attackers);
 
           {
               sq = pop_1st_bit(&attackers);
 
-              if (square_file(sq) == square_file(from))
+              if (file_of(sq) == file_of(from))
                   ambiguousFile = true;
 
                   ambiguousFile = true;
 
-              if (square_rank(sq) == square_rank(from))
+              if (rank_of(sq) == rank_of(from))
                   ambiguousRank = true;
 
               ambiguousMove = true;
                   ambiguousRank = true;
 
               ambiguousMove = true;
@@ -119,9 +119,9 @@ const string move_to_san(Position& pos, Move m) {
           if (ambiguousMove)
           {
               if (!ambiguousFile)
           if (ambiguousMove)
           {
               if (!ambiguousFile)
-                  san += file_to_char(square_file(from));
+                  san += file_to_char(file_of(from));
               else if (!ambiguousRank)
               else if (!ambiguousRank)
-                  san += rank_to_char(square_rank(from));
+                  san += rank_to_char(rank_of(from));
               else
                   san += square_to_string(from);
           }
               else
                   san += square_to_string(from);
           }
@@ -130,7 +130,7 @@ const string move_to_san(Position& pos, Move m) {
       if (pos.move_is_capture(m))
       {
           if (pt == PAWN)
       if (pos.move_is_capture(m))
       {
           if (pt == PAWN)
-              san += file_to_char(square_file(from));
+              san += file_to_char(file_of(from));
 
           san += 'x';
       }
 
           san += 'x';
       }
index 90d0135a4d0dbe246aa38daa54b94d28820d5ad4..501704ba3f53ffd1566f8be4ff9593750fae9782 100644 (file)
@@ -52,7 +52,7 @@ namespace {
     Bitboard b = pos.attacks_from<Pt>(from) & pos.empty_squares();
 
     if (Pt == KING)
     Bitboard b = pos.attacks_from<Pt>(from) & pos.empty_squares();
 
     if (Pt == KING)
-        b &= ~QueenPseudoAttacks[pos.king_square(opposite_color(pos.side_to_move()))];
+        b &= ~QueenPseudoAttacks[pos.king_square(flip(pos.side_to_move()))];
 
     SERIALIZE_MOVES(b);
     return mlist;
 
     SERIALIZE_MOVES(b);
     return mlist;
@@ -158,7 +158,7 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) {
   Bitboard target;
 
   if (Type == MV_CAPTURE || Type == MV_NON_EVASION)
   Bitboard target;
 
   if (Type == MV_CAPTURE || Type == MV_NON_EVASION)
-      target = pos.pieces(opposite_color(us));
+      target = pos.pieces(flip(us));
   else if (Type == MV_NON_CAPTURE)
       target = pos.empty_squares();
   else
   else if (Type == MV_NON_CAPTURE)
       target = pos.empty_squares();
   else
@@ -207,9 +207,9 @@ MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist)
   Bitboard b, dc;
   Square from;
   Color us = pos.side_to_move();
   Bitboard b, dc;
   Square from;
   Color us = pos.side_to_move();
-  Square ksq = pos.king_square(opposite_color(us));
+  Square ksq = pos.king_square(flip(us));
 
 
-  assert(pos.piece_on(ksq) == make_piece(opposite_color(us), KING));
+  assert(pos.piece_on(ksq) == make_piece(flip(us), KING));
 
   // Discovered non-capture checks
   b = dc = pos.discovered_check_candidates();
 
   // Discovered non-capture checks
   b = dc = pos.discovered_check_candidates();
@@ -217,7 +217,7 @@ MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist)
   while (b)
   {
      from = pop_1st_bit(&b);
   while (b)
   {
      from = pop_1st_bit(&b);
-     switch (piece_type(pos.piece_on(from)))
+     switch (type_of(pos.piece_on(from)))
      {
       case PAWN:   /* Will be generated togheter with pawns direct checks */     break;
       case KNIGHT: mlist = generate_discovered_checks<KNIGHT>(pos, mlist, from); break;
      {
       case PAWN:   /* Will be generated togheter with pawns direct checks */     break;
       case KNIGHT: mlist = generate_discovered_checks<KNIGHT>(pos, mlist, from); break;
@@ -264,9 +264,9 @@ MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
       checkersCnt++;
       checksq = pop_1st_bit(&b);
 
       checkersCnt++;
       checksq = pop_1st_bit(&b);
 
-      assert(piece_color(pos.piece_on(checksq)) == opposite_color(us));
+      assert(color_of(pos.piece_on(checksq)) == flip(us));
 
 
-      switch (piece_type(pos.piece_on(checksq)))
+      switch (type_of(pos.piece_on(checksq)))
       {
       case BISHOP: sliderAttacks |= BishopPseudoAttacks[checksq]; break;
       case ROOK:   sliderAttacks |= RookPseudoAttacks[checksq];   break;
       {
       case BISHOP: sliderAttacks |= BishopPseudoAttacks[checksq]; break;
       case ROOK:   sliderAttacks |= RookPseudoAttacks[checksq];   break;
@@ -473,8 +473,8 @@ namespace {
     // En passant captures
     if ((Type == MV_CAPTURE || Type == MV_EVASION) && pos.ep_square() != SQ_NONE)
     {
     // En passant captures
     if ((Type == MV_CAPTURE || Type == MV_EVASION) && pos.ep_square() != SQ_NONE)
     {
-        assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6);
-        assert(Us != BLACK || square_rank(pos.ep_square()) == RANK_3);
+        assert(Us != WHITE || rank_of(pos.ep_square()) == RANK_6);
+        assert(Us != BLACK || rank_of(pos.ep_square()) == RANK_3);
 
         // An en passant capture can be an evasion only if the checking piece
         // is the double pushed pawn and so is in the target. Otherwise this
 
         // An en passant capture can be an evasion only if the checking piece
         // is the double pushed pawn and so is in the target. Otherwise this
@@ -499,7 +499,7 @@ namespace {
   MoveStack* generate_castle_moves(const Position& pos, MoveStack* mlist, Color us) {
 
     CastleRight f = CastleRight((Side == KING_SIDE ? WHITE_OO : WHITE_OOO) << us);
   MoveStack* generate_castle_moves(const Position& pos, MoveStack* mlist, Color us) {
 
     CastleRight f = CastleRight((Side == KING_SIDE ? WHITE_OO : WHITE_OOO) << us);
-    Color them = opposite_color(us);
+    Color them = flip(us);
 
     // After castling, the rook and king's final positions are exactly the same
     // in Chess960 as they would be in standard chess.
 
     // After castling, the rook and king's final positions are exactly the same
     // in Chess960 as they would be in standard chess.
index c898127f3ecef51dd8b96b2bbf41737ed45082c7..6bfe14571809658b5ace78fa8fce3dc41c18c794 100644 (file)
@@ -252,7 +252,7 @@ void MovePicker::score_captures() {
   {
       m = cur->move;
       cur->score =  piece_value_midgame(pos.piece_on(move_to(m)))
   {
       m = cur->move;
       cur->score =  piece_value_midgame(pos.piece_on(move_to(m)))
-                  - piece_type(pos.piece_on(move_from(m)));
+                  - type_of(pos.piece_on(move_from(m)));
 
       if (move_is_promotion(m))
           cur->score += piece_value_midgame(Piece(promotion_piece_type(m)));
 
       if (move_is_promotion(m))
           cur->score += piece_value_midgame(Piece(promotion_piece_type(m)));
@@ -291,7 +291,7 @@ void MovePicker::score_evasions() {
           cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom
       else if (pos.move_is_capture(m))
           cur->score =  piece_value_midgame(pos.piece_on(move_to(m)))
           cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom
       else if (pos.move_is_capture(m))
           cur->score =  piece_value_midgame(pos.piece_on(move_to(m)))
-                      - piece_type(pos.piece_on(move_from(m))) + History::MaxValue;
+                      - type_of(pos.piece_on(move_from(m))) + History::MaxValue;
       else
           cur->score = H.value(pos.piece_on(move_from(m)), move_to(m));
   }
       else
           cur->score = H.value(pos.piece_on(move_from(m)), move_to(m));
   }
index b3c65a0f166268200fb918d4a751f2563f7de378..52bc9f88eea5eb031931cfe1aa17dce81fde575e 100644 (file)
@@ -132,8 +132,8 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
   {
       assert(pos.piece_on(s) == make_piece(Us, PAWN));
 
   {
       assert(pos.piece_on(s) == make_piece(Us, PAWN));
 
-      f = square_file(s);
-      r = square_rank(s);
+      f = file_of(s);
+      r = rank_of(s);
 
       // This file cannot be half open
       pi->halfOpenFiles[Us] &= ~(1 << f);
 
       // This file cannot be half open
       pi->halfOpenFiles[Us] &= ~(1 << f);
index 922a96fd8bdee8e23c4df7e1382ca486985a961c..6075117426972adf189674af9d0ce7ac4f5b8816 100644 (file)
@@ -77,7 +77,7 @@ namespace {
 
 CheckInfo::CheckInfo(const Position& pos) {
 
 
 CheckInfo::CheckInfo(const Position& pos) {
 
-  Color them = opposite_color(pos.side_to_move());
+  Color them = flip(pos.side_to_move());
   Square ksq = pos.king_square(them);
 
   pinned = pos.pinned_pieces();
   Square ksq = pos.king_square(them);
 
   pinned = pos.pinned_pieces();
@@ -183,7 +183,7 @@ void Position::from_fen(const string& fenStr, bool isChess960) {
       && ((fen >> row) && (row == '3' || row == '6')))
   {
       st->epSquare = make_square(File(col - 'a'), Rank(row - '1'));
       && ((fen >> row) && (row == '3' || row == '6')))
   {
       st->epSquare = make_square(File(col - 'a'), Rank(row - '1'));
-      Color them = opposite_color(sideToMove);
+      Color them = flip(sideToMove);
 
       if (!(attacks_from<PAWN>(st->epSquare, them) & pieces(PAWN, sideToMove)))
           st->epSquare = SQ_NONE;
 
       if (!(attacks_from<PAWN>(st->epSquare, them) & pieces(PAWN, sideToMove)))
           st->epSquare = SQ_NONE;
@@ -198,7 +198,7 @@ void Position::from_fen(const string& fenStr, bool isChess960) {
 
   // Various initialisations
   chess960 = isChess960;
 
   // Various initialisations
   chess960 = isChess960;
-  st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(opposite_color(sideToMove));
+  st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(flip(sideToMove));
 
   st->key = compute_key();
   st->pawnKey = compute_pawn_key();
 
   st->key = compute_key();
   st->pawnKey = compute_pawn_key();
@@ -251,7 +251,7 @@ void Position::set_castling_rights(char token) {
 
     else return;
 
 
     else return;
 
-    if (square_file(rsq) < square_file(ksq))
+    if (file_of(rsq) < file_of(ksq))
         set_castle(WHITE_OOO << c, ksq, rsq);
     else
         set_castle(WHITE_OO << c, ksq, rsq);
         set_castle(WHITE_OOO << c, ksq, rsq);
     else
         set_castle(WHITE_OO << c, ksq, rsq);
@@ -300,16 +300,16 @@ const string Position::to_fen() const {
   if (st->castleRights != CASTLES_NONE)
   {
       if (can_castle(WHITE_OO))
   if (st->castleRights != CASTLES_NONE)
   {
       if (can_castle(WHITE_OO))
-          fen << (chess960 ? char(toupper(file_to_char(square_file(castle_rook_square(WHITE_OO))))) : 'K');
+          fen << (chess960 ? char(toupper(file_to_char(file_of(castle_rook_square(WHITE_OO))))) : 'K');
 
       if (can_castle(WHITE_OOO))
 
       if (can_castle(WHITE_OOO))
-          fen << (chess960 ? char(toupper(file_to_char(square_file(castle_rook_square(WHITE_OOO))))) : 'Q');
+          fen << (chess960 ? char(toupper(file_to_char(file_of(castle_rook_square(WHITE_OOO))))) : 'Q');
 
       if (can_castle(BLACK_OO))
 
       if (can_castle(BLACK_OO))
-          fen << (chess960 ? file_to_char(square_file(castle_rook_square(BLACK_OO))) : 'k');
+          fen << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK_OO))) : 'k');
 
       if (can_castle(BLACK_OOO))
 
       if (can_castle(BLACK_OOO))
-          fen << (chess960 ? file_to_char(square_file(castle_rook_square(BLACK_OOO))) : 'q');
+          fen << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK_OOO))) : 'q');
   } else
       fen << '-';
 
   } else
       fen << '-';
 
@@ -345,7 +345,7 @@ void Position::print(Move move) const {
           if (piece == PIECE_NONE && square_color(sq) == DARK)
               piece = PIECE_NONE_DARK_SQ;
 
           if (piece == PIECE_NONE && square_color(sq) == DARK)
               piece = PIECE_NONE_DARK_SQ;
 
-          char c = (piece_color(piece_on(sq)) == BLACK ? '=' : ' ');
+          char c = (color_of(piece_on(sq)) == BLACK ? '=' : ' ');
           cout << c << PieceToChar[piece] << c << '|';
       }
   }
           cout << c << PieceToChar[piece] << c << '|';
       }
   }
@@ -363,8 +363,8 @@ Bitboard Position::hidden_checkers() const {
 
   // Pinned pieces protect our king, dicovery checks attack the enemy king
   Bitboard b, result = EmptyBoardBB;
 
   // Pinned pieces protect our king, dicovery checks attack the enemy king
   Bitboard b, result = EmptyBoardBB;
-  Bitboard pinners = pieces(FindPinned ? opposite_color(sideToMove) : sideToMove);
-  Square ksq = king_square(FindPinned ? sideToMove : opposite_color(sideToMove));
+  Bitboard pinners = pieces(FindPinned ? flip(sideToMove) : sideToMove);
+  Square ksq = king_square(FindPinned ? sideToMove : flip(sideToMove));
 
   // Pinners are sliders, that give check when candidate pinned is removed
   pinners &=  (pieces(ROOK, QUEEN) & RookPseudoAttacks[ksq])
 
   // Pinners are sliders, that give check when candidate pinned is removed
   pinners &=  (pieces(ROOK, QUEEN) & RookPseudoAttacks[ksq])
@@ -474,7 +474,7 @@ bool Position::move_attacks_square(Move m, Square s) const {
   do_move_bb(&occ, make_move_bb(f, t));
   xray = ( (rook_attacks_bb(s, occ)   & pieces(ROOK, QUEEN))
           |(bishop_attacks_bb(s, occ) & pieces(BISHOP, QUEEN)))
   do_move_bb(&occ, make_move_bb(f, t));
   xray = ( (rook_attacks_bb(s, occ)   & pieces(ROOK, QUEEN))
           |(bishop_attacks_bb(s, occ) & pieces(BISHOP, QUEEN)))
-         & pieces(piece_color(piece_on(f)));
+         & pieces(color_of(piece_on(f)));
 
   // If we have attacks we need to verify that are caused by our move
   // and are not already existent ones.
 
   // If we have attacks we need to verify that are caused by our move
   // and are not already existent ones.
@@ -492,7 +492,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
   Color us = side_to_move();
   Square from = move_from(m);
 
   Color us = side_to_move();
   Square from = move_from(m);
 
-  assert(piece_color(piece_on(from)) == us);
+  assert(color_of(piece_on(from)) == us);
   assert(piece_on(king_square(us)) == make_piece(us, KING));
 
   // En passant captures are a tricky special case. Because they are rather
   assert(piece_on(king_square(us)) == make_piece(us, KING));
 
   // En passant captures are a tricky special case. Because they are rather
@@ -500,7 +500,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
   // the move is made.
   if (move_is_ep(m))
   {
   // the move is made.
   if (move_is_ep(m))
   {
-      Color them = opposite_color(us);
+      Color them = flip(us);
       Square to = move_to(m);
       Square capsq = to + pawn_push(them);
       Square ksq = king_square(us);
       Square to = move_to(m);
       Square capsq = to + pawn_push(them);
       Square ksq = king_square(us);
@@ -522,8 +522,8 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
   // If the moving piece is a king, check whether the destination
   // square is attacked by the opponent. Castling moves are checked
   // for legality during move generation.
   // If the moving piece is a king, check whether the destination
   // square is attacked by the opponent. Castling moves are checked
   // for legality during move generation.
-  if (piece_type(piece_on(from)) == KING)
-      return move_is_castle(m) || !(attackers_to(move_to(m)) & pieces(opposite_color(us)));
+  if (type_of(piece_on(from)) == KING)
+      return move_is_castle(m) || !(attackers_to(move_to(m)) & pieces(flip(us)));
 
   // A non-king move is legal if and only if it is not pinned or it
   // is moving along the ray towards or away from the king.
 
   // A non-king move is legal if and only if it is not pinned or it
   // is moving along the ray towards or away from the king.
@@ -553,7 +553,7 @@ bool Position::move_is_legal(const Move m) const {
 bool Position::move_is_pl(const Move m) const {
 
   Color us = sideToMove;
 bool Position::move_is_pl(const Move m) const {
 
   Color us = sideToMove;
-  Color them = opposite_color(sideToMove);
+  Color them = flip(sideToMove);
   Square from = move_from(m);
   Square to = move_to(m);
   Piece pc = piece_on(from);
   Square from = move_from(m);
   Square to = move_to(m);
   Piece pc = piece_on(from);
@@ -568,15 +568,15 @@ bool Position::move_is_pl(const Move m) const {
 
   // If the from square is not occupied by a piece belonging to the side to
   // move, the move is obviously not legal.
 
   // If the from square is not occupied by a piece belonging to the side to
   // move, the move is obviously not legal.
-  if (pc == PIECE_NONE || piece_color(pc) != us)
+  if (pc == PIECE_NONE || color_of(pc) != us)
       return false;
 
   // The destination square cannot be occupied by a friendly piece
       return false;
 
   // The destination square cannot be occupied by a friendly piece
-  if (piece_color(piece_on(to)) == us)
+  if (color_of(piece_on(to)) == us)
       return false;
 
   // Handle the special case of a pawn move
       return false;
 
   // Handle the special case of a pawn move
-  if (piece_type(pc) == PAWN)
+  if (type_of(pc) == PAWN)
   {
       // Move direction must be compatible with pawn color
       int direction = to - from;
   {
       // Move direction must be compatible with pawn color
       int direction = to - from;
@@ -585,7 +585,7 @@ bool Position::move_is_pl(const Move m) const {
 
       // We have already handled promotion moves, so destination
       // cannot be on the 8/1th rank.
 
       // We have already handled promotion moves, so destination
       // cannot be on the 8/1th rank.
-      if (square_rank(to) == RANK_8 || square_rank(to) == RANK_1)
+      if (rank_of(to) == RANK_8 || rank_of(to) == RANK_1)
           return false;
 
       // Proceed according to the square delta between the origin and
           return false;
 
       // Proceed according to the square delta between the origin and
@@ -598,11 +598,11 @@ bool Position::move_is_pl(const Move m) const {
       case DELTA_SE:
       // Capture. The destination square must be occupied by an enemy
       // piece (en passant captures was handled earlier).
       case DELTA_SE:
       // Capture. The destination square must be occupied by an enemy
       // piece (en passant captures was handled earlier).
-      if (piece_color(piece_on(to)) != them)
+      if (color_of(piece_on(to)) != them)
           return false;
 
       // From and to files must be one file apart, avoids a7h5
           return false;
 
       // From and to files must be one file apart, avoids a7h5
-      if (abs(square_file(from) - square_file(to)) != 1)
+      if (abs(file_of(from) - file_of(to)) != 1)
           return false;
       break;
 
           return false;
       break;
 
@@ -617,7 +617,7 @@ bool Position::move_is_pl(const Move m) const {
       // Double white pawn push. The destination square must be on the fourth
       // rank, and both the destination square and the square between the
       // source and destination squares must be empty.
       // Double white pawn push. The destination square must be on the fourth
       // rank, and both the destination square and the square between the
       // source and destination squares must be empty.
-      if (   square_rank(to) != RANK_4
+      if (   rank_of(to) != RANK_4
           || !square_is_empty(to)
           || !square_is_empty(from + DELTA_N))
           return false;
           || !square_is_empty(to)
           || !square_is_empty(from + DELTA_N))
           return false;
@@ -627,7 +627,7 @@ bool Position::move_is_pl(const Move m) const {
       // Double black pawn push. The destination square must be on the fifth
       // rank, and both the destination square and the square between the
       // source and destination squares must be empty.
       // Double black pawn push. The destination square must be on the fifth
       // rank, and both the destination square and the square between the
       // source and destination squares must be empty.
-      if (   square_rank(to) != RANK_5
+      if (   rank_of(to) != RANK_5
           || !square_is_empty(to)
           || !square_is_empty(from + DELTA_S))
           return false;
           || !square_is_empty(to)
           || !square_is_empty(from + DELTA_S))
           return false;
@@ -644,11 +644,11 @@ bool Position::move_is_pl(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.
-      if (piece_type(piece_on(from)) == KING)
+      if (type_of(piece_on(from)) == KING)
       {
           Bitboard b = occupied_squares();
           clear_bit(&b, from);
       {
           Bitboard b = occupied_squares();
           clear_bit(&b, from);
-          if (attackers_to(move_to(m), b) & pieces(opposite_color(us)))
+          if (attackers_to(move_to(m), b) & pieces(flip(us)))
               return false;
       }
       else
               return false;
       }
       else
@@ -676,11 +676,11 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
 
   assert(move_is_ok(m));
   assert(ci.dcCandidates == discovered_check_candidates());
 
   assert(move_is_ok(m));
   assert(ci.dcCandidates == discovered_check_candidates());
-  assert(piece_color(piece_on(move_from(m))) == side_to_move());
+  assert(color_of(piece_on(move_from(m))) == side_to_move());
 
   Square from = move_from(m);
   Square to = move_to(m);
 
   Square from = move_from(m);
   Square to = move_to(m);
-  PieceType pt = piece_type(piece_on(from));
+  PieceType pt = type_of(piece_on(from));
 
   // Direct check ?
   if (bit_is_set(ci.checkSq[pt], to))
 
   // Direct check ?
   if (bit_is_set(ci.checkSq[pt], to))
@@ -691,7 +691,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
   {
       // For pawn and king moves we need to verify also direction
       if (  (pt != PAWN && pt != KING)
   {
       // For pawn and king moves we need to verify also direction
       if (  (pt != PAWN && pt != KING)
-          || !squares_aligned(from, to, king_square(opposite_color(side_to_move()))))
+          || !squares_aligned(from, to, king_square(flip(side_to_move()))))
           return true;
   }
 
           return true;
   }
 
@@ -701,7 +701,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
 
   Color us = side_to_move();
   Bitboard b = occupied_squares();
 
   Color us = side_to_move();
   Bitboard b = occupied_squares();
-  Square ksq = king_square(opposite_color(us));
+  Square ksq = king_square(flip(us));
 
   // Promotion with check ?
   if (move_is_promotion(m))
 
   // Promotion with check ?
   if (move_is_promotion(m))
@@ -729,7 +729,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
   // the captured pawn.
   if (move_is_ep(m))
   {
   // the captured pawn.
   if (move_is_ep(m))
   {
-      Square capsq = make_square(square_file(to), square_rank(from));
+      Square capsq = make_square(file_of(to), rank_of(from));
       clear_bit(&b, from);
       clear_bit(&b, capsq);
       set_bit(&b, to);
       clear_bit(&b, from);
       clear_bit(&b, capsq);
       set_bit(&b, to);
@@ -813,18 +813,18 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
   }
 
   Color us = side_to_move();
   }
 
   Color us = side_to_move();
-  Color them = opposite_color(us);
+  Color them = flip(us);
   Square from = move_from(m);
   Square to = move_to(m);
   bool ep = move_is_ep(m);
   bool pm = move_is_promotion(m);
 
   Piece piece = piece_on(from);
   Square from = move_from(m);
   Square to = move_to(m);
   bool ep = move_is_ep(m);
   bool pm = move_is_promotion(m);
 
   Piece piece = piece_on(from);
-  PieceType pt = piece_type(piece);
-  PieceType capture = ep ? PAWN : piece_type(piece_on(to));
+  PieceType pt = type_of(piece);
+  PieceType capture = ep ? PAWN : type_of(piece_on(to));
 
 
-  assert(piece_color(piece_on(from)) == us);
-  assert(piece_color(piece_on(to)) == them || square_is_empty(to));
+  assert(color_of(piece_on(from)) == us);
+  assert(color_of(piece_on(to)) == them || square_is_empty(to));
   assert(!(ep || pm) || piece == make_piece(us, PAWN));
   assert(!pm || relative_rank(us, to) == RANK_8);
 
   assert(!(ep || pm) || piece == make_piece(us, PAWN));
   assert(!pm || relative_rank(us, to) == RANK_8);
 
@@ -967,7 +967,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
   }
 
   // Finish
   }
 
   // Finish
-  sideToMove = opposite_color(sideToMove);
+  sideToMove = flip(sideToMove);
   st->value += (sideToMove == WHITE ?  TempoValue : -TempoValue);
 
   assert(is_ok());
   st->value += (sideToMove == WHITE ?  TempoValue : -TempoValue);
 
   assert(is_ok());
@@ -992,7 +992,7 @@ void Position::do_capture_move(Key& key, PieceType capture, Color them, Square t
             capsq = to + pawn_push(them);
 
             assert(to == st->epSquare);
             capsq = to + pawn_push(them);
 
             assert(to == st->epSquare);
-            assert(relative_rank(opposite_color(them), to) == RANK_6);
+            assert(relative_rank(flip(them), to) == RANK_6);
             assert(piece_on(to) == PIECE_NONE);
             assert(piece_on(capsq) == make_piece(them, PAWN));
 
             assert(piece_on(to) == PIECE_NONE);
             assert(piece_on(capsq) == make_piece(them, PAWN));
 
@@ -1048,7 +1048,7 @@ void Position::do_castle_move(Move m) {
   assert(move_is_castle(m));
 
   Color us = side_to_move();
   assert(move_is_castle(m));
 
   Color us = side_to_move();
-  Color them = opposite_color(us);
+  Color them = flip(us);
 
   // Find source squares for king and rook
   Square kfrom = move_from(m);
 
   // Find source squares for king and rook
   Square kfrom = move_from(m);
@@ -1130,7 +1130,7 @@ void Position::do_castle_move(Move m) {
   st->checkersBB = attackers_to(king_square(them)) & pieces(us);
 
   // Finish
   st->checkersBB = attackers_to(king_square(them)) & pieces(us);
 
   // Finish
-  sideToMove = opposite_color(sideToMove);
+  sideToMove = flip(sideToMove);
   st->value += (sideToMove == WHITE ?  TempoValue : -TempoValue);
 
   assert(is_ok());
   st->value += (sideToMove == WHITE ?  TempoValue : -TempoValue);
 
   assert(is_ok());
@@ -1144,7 +1144,7 @@ void Position::undo_move(Move m) {
 
   assert(move_is_ok(m));
 
 
   assert(move_is_ok(m));
 
-  sideToMove = opposite_color(sideToMove);
+  sideToMove = flip(sideToMove);
 
   if (move_is_castle(m))
   {
 
   if (move_is_castle(m))
   {
@@ -1153,16 +1153,16 @@ void Position::undo_move(Move m) {
   }
 
   Color us = side_to_move();
   }
 
   Color us = side_to_move();
-  Color them = opposite_color(us);
+  Color them = flip(us);
   Square from = move_from(m);
   Square to = move_to(m);
   bool ep = move_is_ep(m);
   bool pm = move_is_promotion(m);
 
   Square from = move_from(m);
   Square to = move_to(m);
   bool ep = move_is_ep(m);
   bool pm = move_is_promotion(m);
 
-  PieceType pt = piece_type(piece_on(to));
+  PieceType pt = type_of(piece_on(to));
 
   assert(square_is_empty(from));
 
   assert(square_is_empty(from));
-  assert(piece_color(piece_on(to)) == us);
+  assert(color_of(piece_on(to)) == us);
   assert(!pm || relative_rank(us, to) == RANK_8);
   assert(!ep || to == st->previous->epSquare);
   assert(!ep || relative_rank(us, to) == RANK_6);
   assert(!pm || relative_rank(us, to) == RANK_8);
   assert(!ep || to == st->previous->epSquare);
   assert(!ep || relative_rank(us, to) == RANK_6);
@@ -1335,7 +1335,7 @@ void Position::do_null_move(StateInfo& backupSt) {
   st->key ^= zobSideToMove;
   prefetch((char*)TT.first_entry(st->key));
 
   st->key ^= zobSideToMove;
   prefetch((char*)TT.first_entry(st->key));
 
-  sideToMove = opposite_color(sideToMove);
+  sideToMove = flip(sideToMove);
   st->epSquare = SQ_NONE;
   st->rule50++;
   st->pliesFromNull = 0;
   st->epSquare = SQ_NONE;
   st->rule50++;
   st->pliesFromNull = 0;
@@ -1360,7 +1360,7 @@ void Position::undo_null_move() {
   st->pliesFromNull = backupSt->pliesFromNull;
 
   // Update the necessary information
   st->pliesFromNull = backupSt->pliesFromNull;
 
   // Update the necessary information
-  sideToMove = opposite_color(sideToMove);
+  sideToMove = flip(sideToMove);
   st->rule50--;
 
   assert(is_ok());
   st->rule50--;
 
   assert(is_ok());
@@ -1407,16 +1407,16 @@ int Position::see(Move m) const {
 
   from = move_from(m);
   to = move_to(m);
 
   from = move_from(m);
   to = move_to(m);
-  capturedType = piece_type(piece_on(to));
+  capturedType = type_of(piece_on(to));
   occupied = occupied_squares();
 
   // Handle en passant moves
   occupied = occupied_squares();
 
   // Handle en passant moves
-  if (st->epSquare == to && piece_type(piece_on(from)) == PAWN)
+  if (st->epSquare == to && type_of(piece_on(from)) == PAWN)
   {
       Square capQq = to - pawn_push(side_to_move());
 
       assert(capturedType == PIECE_TYPE_NONE);
   {
       Square capQq = to - pawn_push(side_to_move());
 
       assert(capturedType == PIECE_TYPE_NONE);
-      assert(piece_type(piece_on(capQq)) == PAWN);
+      assert(type_of(piece_on(capQq)) == PAWN);
 
       // Remove the captured pawn
       clear_bit(&occupied, capQq);
 
       // Remove the captured pawn
       clear_bit(&occupied, capQq);
@@ -1429,7 +1429,7 @@ int Position::see(Move m) const {
   attackers = attackers_to(to, occupied);
 
   // If the opponent has no attackers we are finished
   attackers = attackers_to(to, occupied);
 
   // If the opponent has no attackers we are finished
-  stm = opposite_color(piece_color(piece_on(from)));
+  stm = flip(color_of(piece_on(from)));
   stmAttackers = attackers & pieces(stm);
   if (!stmAttackers)
       return PieceValueMidgame[capturedType];
   stmAttackers = attackers & pieces(stm);
   if (!stmAttackers)
       return PieceValueMidgame[capturedType];
@@ -1441,7 +1441,7 @@ int Position::see(Move m) const {
   // capture with the least valuable piece. After each capture, we look for
   // new X-ray attacks from behind the capturing piece.
   swapList[0] = PieceValueMidgame[capturedType];
   // capture with the least valuable piece. After each capture, we look for
   // new X-ray attacks from behind the capturing piece.
   swapList[0] = PieceValueMidgame[capturedType];
-  capturedType = piece_type(piece_on(from));
+  capturedType = type_of(piece_on(from));
 
   do {
       // Locate the least valuable attacker for the side to move. The loop
 
   do {
       // Locate the least valuable attacker for the side to move. The loop
@@ -1467,7 +1467,7 @@ int Position::see(Move m) const {
       // Remember the value of the capturing piece, and change the side to
       // move before beginning the next iteration.
       capturedType = pt;
       // Remember the value of the capturing piece, and change the side to
       // move before beginning the next iteration.
       capturedType = pt;
-      stm = opposite_color(stm);
+      stm = flip(stm);
       stmAttackers = attackers & pieces(stm);
 
       // Stop before processing a king capture
       stmAttackers = attackers & pieces(stm);
 
       // Stop before processing a king capture
@@ -1521,8 +1521,8 @@ void Position::clear() {
 
 void Position::put_piece(Piece p, Square s) {
 
 
 void Position::put_piece(Piece p, Square s) {
 
-  Color c = piece_color(p);
-  PieceType pt = piece_type(p);
+  Color c = color_of(p);
+  PieceType pt = type_of(p);
 
   board[s] = p;
   index[s] = pieceCount[c][pt]++;
 
   board[s] = p;
   index[s] = pieceCount[c][pt]++;
@@ -1545,7 +1545,7 @@ Key Position::compute_key() const {
 
   for (Square s = SQ_A1; s <= SQ_H8; s++)
       if (!square_is_empty(s))
 
   for (Square s = SQ_A1; s <= SQ_H8; s++)
       if (!square_is_empty(s))
-          result ^= zobrist[piece_color(piece_on(s))][piece_type(piece_on(s))][s];
+          result ^= zobrist[color_of(piece_on(s))][type_of(piece_on(s))][s];
 
   if (ep_square() != SQ_NONE)
       result ^= zobEp[ep_square()];
 
   if (ep_square() != SQ_NONE)
       result ^= zobEp[ep_square()];
@@ -1692,7 +1692,7 @@ bool Position::is_mate() const {
 /// startup the various arrays used to compute hash keys and the piece
 /// square tables. The latter is a two-step operation: First, the white
 /// halves of the tables are copied from the MgPST[][] and EgPST[][] arrays.
 /// startup the various arrays used to compute hash keys and the piece
 /// square tables. The latter is a two-step operation: First, the white
 /// halves of the tables are copied from the MgPST[][] and EgPST[][] arrays.
-/// Second, the black halves of the tables are initialized by mirroring
+/// Second, the black halves of the tables are initialized by flipping
 /// and changing the sign of the corresponding white scores.
 
 void Position::init() {
 /// and changing the sign of the corresponding white scores.
 
 void Position::init() {
@@ -1713,20 +1713,19 @@ void Position::init() {
   zobSideToMove = rk.rand<Key>();
   zobExclusion  = rk.rand<Key>();
 
   zobSideToMove = rk.rand<Key>();
   zobExclusion  = rk.rand<Key>();
 
-  for (Square s = SQ_A1; s <= SQ_H8; s++)
-      for (Piece p = WP; p <= WK; p++)
+  for (Piece p = WP; p <= WK; p++)
+      for (Square s = SQ_A1; s <= SQ_H8; s++)
+      {
           pieceSquareTable[p][s] = make_score(MgPST[p][s], EgPST[p][s]);
           pieceSquareTable[p][s] = make_score(MgPST[p][s], EgPST[p][s]);
-
-  for (Square s = SQ_A1; s <= SQ_H8; s++)
-      for (Piece p = BP; p <= BK; p++)
-          pieceSquareTable[p][s] = -pieceSquareTable[p-8][flip_square(s)];
+          pieceSquareTable[p+8][flip(s)] = -pieceSquareTable[p][s];
+      }
 }
 
 
 }
 
 
-/// Position::flip() flips position with the white and black sides reversed. This
+/// Position::flip_me() flips position with the white and black sides reversed. This
 /// is only useful for debugging especially for finding evaluation symmetry bugs.
 
 /// is only useful for debugging especially for finding evaluation symmetry bugs.
 
-void Position::flip() {
+void Position::flip_me() {
 
   // Make a copy of current position before to start changing
   const Position pos(*this, threadID);
 
   // Make a copy of current position before to start changing
   const Position pos(*this, threadID);
@@ -1737,27 +1736,27 @@ void Position::flip() {
   // Board
   for (Square s = SQ_A1; s <= SQ_H8; s++)
       if (!pos.square_is_empty(s))
   // Board
   for (Square s = SQ_A1; s <= SQ_H8; s++)
       if (!pos.square_is_empty(s))
-          put_piece(Piece(pos.piece_on(s) ^ 8), flip_square(s));
+          put_piece(Piece(pos.piece_on(s) ^ 8), flip(s));
 
   // Side to move
 
   // Side to move
-  sideToMove = opposite_color(pos.side_to_move());
+  sideToMove = flip(pos.side_to_move());
 
   // Castling rights
   if (pos.can_castle(WHITE_OO))
 
   // Castling rights
   if (pos.can_castle(WHITE_OO))
-      set_castle(BLACK_OO,  king_square(BLACK), flip_square(pos.castle_rook_square(WHITE_OO)));
+      set_castle(BLACK_OO,  king_square(BLACK), flip(pos.castle_rook_square(WHITE_OO)));
   if (pos.can_castle(WHITE_OOO))
   if (pos.can_castle(WHITE_OOO))
-      set_castle(BLACK_OOO, king_square(BLACK), flip_square(pos.castle_rook_square(WHITE_OOO)));
+      set_castle(BLACK_OOO, king_square(BLACK), flip(pos.castle_rook_square(WHITE_OOO)));
   if (pos.can_castle(BLACK_OO))
   if (pos.can_castle(BLACK_OO))
-      set_castle(WHITE_OO,  king_square(WHITE), flip_square(pos.castle_rook_square(BLACK_OO)));
+      set_castle(WHITE_OO,  king_square(WHITE), flip(pos.castle_rook_square(BLACK_OO)));
   if (pos.can_castle(BLACK_OOO))
   if (pos.can_castle(BLACK_OOO))
-      set_castle(WHITE_OOO, king_square(WHITE), flip_square(pos.castle_rook_square(BLACK_OOO)));
+      set_castle(WHITE_OOO, king_square(WHITE), flip(pos.castle_rook_square(BLACK_OOO)));
 
   // En passant square
   if (pos.st->epSquare != SQ_NONE)
 
   // En passant square
   if (pos.st->epSquare != SQ_NONE)
-      st->epSquare = flip_square(pos.st->epSquare);
+      st->epSquare = flip(pos.st->epSquare);
 
   // Checkers
 
   // Checkers
-  st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(opposite_color(sideToMove));
+  st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(flip(sideToMove));
 
   // Hash keys
   st->key = compute_key();
 
   // Hash keys
   st->key = compute_key();
@@ -1817,8 +1816,8 @@ bool Position::is_ok(int* failedStep) const {
   {
       int kingCount[2] = {0, 0};
       for (Square s = SQ_A1; s <= SQ_H8; s++)
   {
       int kingCount[2] = {0, 0};
       for (Square s = SQ_A1; s <= SQ_H8; s++)
-          if (piece_type(piece_on(s)) == KING)
-              kingCount[piece_color(piece_on(s))]++;
+          if (type_of(piece_on(s)) == KING)
+              kingCount[color_of(piece_on(s))]++;
 
       if (kingCount[0] != 1 || kingCount[1] != 1)
           return false;
 
       if (kingCount[0] != 1 || kingCount[1] != 1)
           return false;
@@ -1829,7 +1828,7 @@ bool Position::is_ok(int* failedStep) const {
   if (debugKingCapture)
   {
       Color us = side_to_move();
   if (debugKingCapture)
   {
       Color us = side_to_move();
-      Color them = opposite_color(us);
+      Color them = flip(us);
       Square ksq = king_square(them);
       if (attackers_to(ksq) & pieces(us))
           return false;
       Square ksq = king_square(them);
       if (attackers_to(ksq) & pieces(us))
           return false;
index 695ad98db8d9bf157effd8be06bc695effa4477a..2930b8c853fdb7927c911fbc16d5a467dbc87d6e 100644 (file)
@@ -204,7 +204,7 @@ public:
 
   // Position consistency check, for debugging
   bool is_ok(int* failedStep = NULL) const;
 
   // Position consistency check, for debugging
   bool is_ok(int* failedStep = NULL) const;
-  void flip();
+  void flip_me();
 
   // Global initialization
   static void init();
 
   // Global initialization
   static void init();
@@ -380,7 +380,7 @@ inline bool Position::in_check() const {
 }
 
 inline bool Position::pawn_is_passed(Color c, Square s) const {
 }
 
 inline bool Position::pawn_is_passed(Color c, Square s) const {
-  return !(pieces(PAWN, opposite_color(c)) & passed_pawn_mask(c, s));
+  return !(pieces(PAWN, flip(c)) & passed_pawn_mask(c, s));
 }
 
 inline Key Position::get_key() const {
 }
 
 inline Key Position::get_key() const {
index 36f57b424646caa60bae5be859d51bd04b441e65..61a394a1cf2b50b0a4a04e386ee1c199054cc628 100644 (file)
@@ -270,7 +270,7 @@ namespace {
     if (moveIsCheck && pos.see_sign(m) >= 0)
         result += CheckExtension[PvNode];
 
     if (moveIsCheck && pos.see_sign(m) >= 0)
         result += CheckExtension[PvNode];
 
-    if (piece_type(pos.piece_on(move_from(m))) == PAWN)
+    if (type_of(pos.piece_on(move_from(m))) == PAWN)
     {
         Color c = pos.side_to_move();
         if (relative_rank(c, move_to(m)) == RANK_7)
     {
         Color c = pos.side_to_move();
         if (relative_rank(c, move_to(m)) == RANK_7)
@@ -286,7 +286,7 @@ namespace {
     }
 
     if (   captureOrPromotion
     }
 
     if (   captureOrPromotion
-        && piece_type(pos.piece_on(move_to(m))) != PAWN
+        && type_of(pos.piece_on(move_to(m))) != PAWN
         && (  pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
             - piece_value_midgame(pos.piece_on(move_to(m))) == VALUE_ZERO)
         && !move_is_special(m))
         && (  pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
             - piece_value_midgame(pos.piece_on(move_to(m))) == VALUE_ZERO)
         && !move_is_special(m))
@@ -1493,7 +1493,7 @@ split_point_start: // At split points actual search starts from here
 
     from = move_from(move);
     to = move_to(move);
 
     from = move_from(move);
     to = move_to(move);
-    them = opposite_color(pos.side_to_move());
+    them = flip(pos.side_to_move());
     ksq = pos.king_square(them);
     kingAtt = pos.attacks_from<KING>(ksq);
     pc = pos.piece_on(from);
     ksq = pos.king_square(them);
     kingAtt = pos.attacks_from<KING>(ksq);
     pc = pos.piece_on(from);
@@ -1509,7 +1509,7 @@ split_point_start: // At split points actual search starts from here
         return true;
 
     // Rule 2. Queen contact check is very dangerous
         return true;
 
     // Rule 2. Queen contact check is very dangerous
-    if (   piece_type(pc) == QUEEN
+    if (   type_of(pc) == QUEEN
         && bit_is_set(kingAtt, to))
         return true;
 
         && bit_is_set(kingAtt, to))
         return true;
 
@@ -1644,7 +1644,7 @@ split_point_start: // At split points actual search starts from here
     // value of the threatening piece, don't prune moves which defend it.
     if (   pos.move_is_capture(threat)
         && (   piece_value_midgame(pos.piece_on(tfrom)) >= piece_value_midgame(pos.piece_on(tto))
     // value of the threatening piece, don't prune moves which defend it.
     if (   pos.move_is_capture(threat)
         && (   piece_value_midgame(pos.piece_on(tfrom)) >= piece_value_midgame(pos.piece_on(tto))
-            || piece_type(pos.piece_on(tfrom)) == KING)
+            || type_of(pos.piece_on(tfrom)) == KING)
         && pos.move_attacks_square(m, tto))
         return true;
 
         && pos.move_attacks_square(m, tto))
         return true;
 
index 863e0df2f771be35033dd9e22debaa7d524f4203..f8eab0c2711cad795a215b972df306221601aa7d 100644 (file)
@@ -370,15 +370,15 @@ inline Piece make_piece(Color c, PieceType pt) {
   return Piece((c << 3) | pt);
 }
 
   return Piece((c << 3) | pt);
 }
 
-inline PieceType piece_type(Piece p)  {
+inline PieceType type_of(Piece p)  {
   return PieceType(p & 7);
 }
 
   return PieceType(p & 7);
 }
 
-inline Color piece_color(Piece p) {
+inline Color color_of(Piece p) {
   return Color(p >> 3);
 }
 
   return Color(p >> 3);
 }
 
-inline Color opposite_color(Color c) {
+inline Color flip(Color c) {
   return Color(c ^ 1);
 }
 
   return Color(c ^ 1);
 }
 
@@ -395,19 +395,19 @@ inline bool square_is_ok(Square s) {
   return s >= SQ_A1 && s <= SQ_H8;
 }
 
   return s >= SQ_A1 && s <= SQ_H8;
 }
 
-inline File square_file(Square s) {
+inline File file_of(Square s) {
   return File(s & 7);
 }
 
   return File(s & 7);
 }
 
-inline Rank square_rank(Square s) {
+inline Rank rank_of(Square s) {
   return Rank(s >> 3);
 }
 
   return Rank(s >> 3);
 }
 
-inline Square flip_square(Square s) {
+inline Square flip(Square s) {
   return Square(s ^ 56);
 }
 
   return Square(s ^ 56);
 }
 
-inline Square flop_square(Square s) {
+inline Square mirror(Square s) {
   return Square(s ^ 7);
 }
 
   return Square(s ^ 7);
 }
 
@@ -420,11 +420,11 @@ inline Rank relative_rank(Color c, Rank r) {
 }
 
 inline Rank relative_rank(Color c, Square s) {
 }
 
 inline Rank relative_rank(Color c, Square s) {
-  return relative_rank(c, square_rank(s));
+  return relative_rank(c, rank_of(s));
 }
 
 inline SquareColor square_color(Square s) {
 }
 
 inline SquareColor square_color(Square s) {
-  return SquareColor(int(square_rank(s) + s) & 1);
+  return SquareColor(int(rank_of(s) + s) & 1);
 }
 
 inline bool opposite_color_squares(Square s1, Square s2) {
 }
 
 inline bool opposite_color_squares(Square s1, Square s2) {
@@ -433,11 +433,11 @@ inline bool opposite_color_squares(Square s1, Square s2) {
 }
 
 inline int file_distance(Square s1, Square s2) {
 }
 
 inline int file_distance(Square s1, Square s2) {
-  return abs(square_file(s1) - square_file(s2));
+  return abs(file_of(s1) - file_of(s2));
 }
 
 inline int rank_distance(Square s1, Square s2) {
 }
 
 inline int rank_distance(Square s1, Square s2) {
-  return abs(square_rank(s1) - square_rank(s2));
+  return abs(rank_of(s1) - rank_of(s2));
 }
 
 inline int square_distance(Square s1, Square s2) {
 }
 
 inline int square_distance(Square s1, Square s2) {
@@ -453,7 +453,7 @@ inline char rank_to_char(Rank r) {
 }
 
 inline const std::string square_to_string(Square s) {
 }
 
 inline const std::string square_to_string(Square s) {
-  char ch[] = { file_to_char(square_file(s)), rank_to_char(square_rank(s)), 0 };
+  char ch[] = { file_to_char(file_of(s)), rank_to_char(rank_of(s)), 0 };
   return std::string(ch);
 }
 
   return std::string(ch);
 }
 
index dbf735af15a018b487a9b0df4574e60534fa89ae..86fe629a84f69708fd6057c9897790fbdc816063 100644 (file)
@@ -91,7 +91,7 @@ void uci_loop() {
           pos.print();
 
       else if (token == "flip")
           pos.print();
 
       else if (token == "flip")
-          pos.flip();
+          pos.flip_me();
 
       else if (token == "eval")
       {
 
       else if (token == "eval")
       {