]> git.sesse.net Git - stockfish/commitdiff
Small touches in position.h
authorMarco Costalba <mcostalba@gmail.com>
Mon, 3 Oct 2011 08:23:04 +0000 (09:23 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 3 Oct 2011 13:18:56 +0000 (14:18 +0100)
No functional change.

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

index c2e892eef0b9d8e712151b2d148786cbfae4bb09..a4526ff612939307f5ce9f25c6878713af247010 100644 (file)
@@ -187,7 +187,7 @@ Value Endgame<KBNK>::apply(const Position& pos) const {
   // kbnk_mate_table() tries to drive toward corners A1 or H8,
   // if we have a bishop that cannot reach the above squares we
   // mirror the kings so to drive enemy toward corners A8 or H1.
-  if (opposite_color_squares(bishopSquare, SQ_A1))
+  if (opposite_colors(bishopSquare, SQ_A1))
   {
       winnerKSq = mirror(winnerKSq);
       loserKSq = mirror(loserKSq);
@@ -433,7 +433,7 @@ ScaleFactor Endgame<KBPsK>::apply(const Position& pos) const {
       Square queeningSq = relative_square(strongerSide, make_square(pawnFile, RANK_8));
       Square kingSq = pos.king_square(weakerSide);
 
-      if (   opposite_color_squares(queeningSq, bishopSq)
+      if (   opposite_colors(queeningSq, bishopSq)
           && abs(file_of(kingSq) - pawnFile) <= 1)
       {
           // The bishop has the wrong color, and the defending king is on the
@@ -710,12 +710,12 @@ ScaleFactor Endgame<KBPKB>::apply(const Position& pos) const {
   // Case 1: Defending king blocks the pawn, and cannot be driven away
   if (   file_of(weakerKingSq) == file_of(pawnSq)
       && relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
-      && (   opposite_color_squares(weakerKingSq, strongerBishopSq)
+      && (   opposite_colors(weakerKingSq, strongerBishopSq)
           || relative_rank(strongerSide, weakerKingSq) <= RANK_6))
       return SCALE_FACTOR_ZERO;
 
   // Case 2: Opposite colored bishops
-  if (opposite_color_squares(strongerBishopSq, weakerBishopSq))
+  if (opposite_colors(strongerBishopSq, weakerBishopSq))
   {
       // We assume that the position is drawn in the following three situations:
       //
@@ -760,7 +760,7 @@ ScaleFactor Endgame<KBPPKB>::apply(const Position& pos) const {
   Square wbsq = pos.piece_list(strongerSide, BISHOP)[0];
   Square bbsq = pos.piece_list(weakerSide, BISHOP)[0];
 
-  if (!opposite_color_squares(wbsq, bbsq))
+  if (!opposite_colors(wbsq, bbsq))
       return SCALE_FACTOR_NONE;
 
   Square ksq = pos.king_square(weakerSide);
@@ -788,7 +788,7 @@ ScaleFactor Endgame<KBPPKB>::apply(const Position& pos) const {
     // some square in the frontmost pawn's path.
     if (   file_of(ksq) == file_of(blockSq1)
         && relative_rank(strongerSide, ksq) >= relative_rank(strongerSide, blockSq1)
-        && opposite_color_squares(ksq, wbsq))
+        && opposite_colors(ksq, wbsq))
         return SCALE_FACTOR_ZERO;
     else
         return SCALE_FACTOR_NONE;
@@ -798,14 +798,14 @@ ScaleFactor Endgame<KBPPKB>::apply(const Position& pos) const {
     // in front of the frontmost pawn's path, and the square diagonally behind
     // this square on the file of the other pawn.
     if (   ksq == blockSq1
-        && opposite_color_squares(ksq, wbsq)
+        && opposite_colors(ksq, wbsq)
         && (   bbsq == blockSq2
             || (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(BISHOP, weakerSide))
             || abs(r1 - r2) >= 2))
         return SCALE_FACTOR_ZERO;
 
     else if (   ksq == blockSq2
-             && opposite_color_squares(ksq, wbsq)
+             && opposite_colors(ksq, wbsq)
              && (   bbsq == blockSq1
                  || (pos.attacks_from<BISHOP>(blockSq1) & pos.pieces(BISHOP, weakerSide))))
         return SCALE_FACTOR_ZERO;
@@ -839,7 +839,7 @@ ScaleFactor Endgame<KBPKN>::apply(const Position& pos) const {
 
   if (   file_of(weakerKingSq) == file_of(pawnSq)
       && relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
-      && (   opposite_color_squares(weakerKingSq, strongerBishopSq)
+      && (   opposite_colors(weakerKingSq, strongerBishopSq)
           || relative_rank(strongerSide, weakerKingSq) <= RANK_6))
       return SCALE_FACTOR_ZERO;
 
index 41f55ab9dbc8cbe02afbb01e09492bfa92910f14..cb77fe3efcbb46f9994d35c0cb7075e479acf8df 100644 (file)
@@ -462,7 +462,7 @@ namespace {
     if (bonus && bit_is_set(ei.attackedBy[Us][PAWN], s))
     {
         if (    pos.pieces(KNIGHT, Them) == EmptyBoardBB
-            && (SquaresByColorBB[square_color(s)] & pos.pieces(BISHOP, Them)) == EmptyBoardBB)
+            && (SquaresByColorBB[color_of(s)] & pos.pieces(BISHOP, Them)) == EmptyBoardBB)
             bonus += bonus + bonus / 2;
         else
             bonus += bonus / 2;
index 6075117426972adf189674af9d0ce7ac4f5b8816..80fa16dd3a5b8c0cd6eb7cb6f18034076c9a9d52 100644 (file)
@@ -342,7 +342,7 @@ void Position::print(Move move) const {
           Square sq = make_square(file, rank);
           Piece piece = piece_on(sq);
 
-          if (piece == PIECE_NONE && square_color(sq) == DARK)
+          if (piece == PIECE_NONE && color_of(sq) == DARK)
               piece = PIECE_NONE_DARK_SQ;
 
           char c = (color_of(piece_on(sq)) == BLACK ? '=' : ' ');
index 2930b8c853fdb7927c911fbc16d5a467dbc87d6e..8f2539013cbd00dd848b3313f5295a4317f092d2 100644 (file)
@@ -283,7 +283,7 @@ inline Piece Position::piece_on(Square s) const {
 }
 
 inline bool Position::square_is_empty(Square s) const {
-  return piece_on(s) == PIECE_NONE;
+  return board[s] == PIECE_NONE;
 }
 
 inline Color Position::side_to_move() const {
@@ -295,7 +295,7 @@ inline Bitboard Position::occupied_squares() const {
 }
 
 inline Bitboard Position::empty_squares() const {
-  return ~occupied_squares();
+  return ~byTypeBB[0];
 }
 
 inline Bitboard Position::pieces(Color c) const {
@@ -376,7 +376,7 @@ inline Bitboard Position::checkers() const {
 }
 
 inline bool Position::in_check() const {
-  return st->checkersBB != EmptyBoardBB;
+  return st->checkersBB != 0;
 }
 
 inline bool Position::pawn_is_passed(Color c, Square s) const {
@@ -417,9 +417,8 @@ inline Value Position::non_pawn_material(Color c) const {
 
 inline bool Position::move_is_passed_pawn_push(Move m) const {
 
-  Color c = side_to_move();
-  return   piece_on(move_from(m)) == make_piece(c, PAWN)
-        && pawn_is_passed(c, move_to(m));
+  return   board[move_from(m)] == make_piece(sideToMove, PAWN)
+        && pawn_is_passed(sideToMove, move_to(m));
 }
 
 inline int Position::startpos_ply_counter() const {
@@ -428,9 +427,9 @@ inline int Position::startpos_ply_counter() const {
 
 inline bool Position::opposite_colored_bishops() const {
 
-  return   piece_count(WHITE, BISHOP) == 1
-        && piece_count(BLACK, BISHOP) == 1
-        && opposite_color_squares(piece_list(WHITE, BISHOP)[0], piece_list(BLACK, BISHOP)[0]);
+  return   pieceCount[WHITE][BISHOP] == 1
+        && pieceCount[BLACK][BISHOP] == 1
+        && opposite_colors(pieceList[WHITE][BISHOP][0], pieceList[BLACK][BISHOP][0]);
 }
 
 inline bool Position::has_pawn_on_7th(Color c) const {
index f8eab0c2711cad795a215b972df306221601aa7d..8facaafa7489b0a0b4e1a0e1fe42dbab3c13b5bb 100644 (file)
@@ -382,11 +382,6 @@ inline Color flip(Color c) {
   return Color(c ^ 1);
 }
 
-inline char piece_type_to_char(PieceType pt) {
-  static const char ch[] = " PNBRQK";
-  return ch[pt];
-}
-
 inline Square make_square(File f, Rank r) {
   return Square((r << 3) | f);
 }
@@ -423,11 +418,11 @@ inline Rank relative_rank(Color c, Square s) {
   return relative_rank(c, rank_of(s));
 }
 
-inline SquareColor square_color(Square s) {
+inline SquareColor color_of(Square s) {
   return SquareColor(int(rank_of(s) + s) & 1);
 }
 
-inline bool opposite_color_squares(Square s1, Square s2) {
+inline bool opposite_colors(Square s1, Square s2) {
   int s = s1 ^ s2;
   return ((s >> 3) ^ s) & 1;
 }
@@ -444,6 +439,10 @@ inline int square_distance(Square s1, Square s2) {
   return SquareDistance[s1][s2];
 }
 
+inline char piece_type_to_char(PieceType pt) {
+  return " PNBRQK"[pt];
+}
+
 inline char file_to_char(File f) {
   return char(f - FILE_A + int('a'));
 }
@@ -454,7 +453,7 @@ inline char rank_to_char(Rank r) {
 
 inline const std::string square_to_string(Square s) {
   char ch[] = { file_to_char(file_of(s)), rank_to_char(rank_of(s)), 0 };
-  return std::string(ch);
+  return ch;
 }
 
 inline Square pawn_push(Color c) {