]> git.sesse.net Git - stockfish/commitdiff
Use update_checkers<>() also for PAWN
authorMarco Costalba <mcostalba@gmail.com>
Thu, 12 Feb 2009 11:26:23 +0000 (12:26 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 13 Feb 2009 19:54:37 +0000 (20:54 +0100)
No functional change.

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

index 83a83c1887eddbfa7731c1f1b537a5d995822fba..ed7510101de89fbbd38270113019d82b710d8b7a 100644 (file)
@@ -317,6 +317,25 @@ void Position::copy(const Position &pos) {
 }
 
 
 }
 
 
+/// Position::update_checkers() updates checkers info, used in do_move()
+template<PieceType Piece>
+inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square from,
+                                      Square to, Bitboard dcCandidates) {
+
+  if (Piece != KING && bit_is_set(piece_attacks<Piece>(ksq), to))
+      set_bit(pCheckersBB, to);
+
+  if (Piece != QUEEN && bit_is_set(dcCandidates, from))
+  {
+      if (Piece != ROOK)
+          (*pCheckersBB) |= (piece_attacks<ROOK>(ksq) & rooks_and_queens(side_to_move()));
+
+      if (Piece != BISHOP)
+          (*pCheckersBB) |= (piece_attacks<BISHOP>(ksq) & bishops_and_queens(side_to_move()));
+  }
+}
+
+
 /// Position:pinned_pieces() returns a bitboard of all pinned (against the
 /// king) pieces for the given color.
 Bitboard Position::pinned_pieces(Color c) const {
 /// Position:pinned_pieces() returns a bitboard of all pinned (against the
 /// king) pieces for the given color.
 Bitboard Position::pinned_pieces(Color c) const {
@@ -710,22 +729,6 @@ void Position::restore(const UndoInfo& u) {
   // u.capture is restored in undo_move()
 }
 
   // u.capture is restored in undo_move()
 }
 
-template<PieceType Piece>
-inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates) {
-
-  if (Piece != KING && bit_is_set(piece_attacks<Piece>(ksq), to))
-      set_bit(pCheckersBB, to);
-
-  if (Piece != QUEEN && bit_is_set(dcCandidates, from))
-  {
-      if (Piece != ROOK)
-          (*pCheckersBB) |= (piece_attacks<ROOK>(ksq) & rooks_and_queens(side_to_move()));
-
-      if (Piece != BISHOP)
-          (*pCheckersBB) |= (piece_attacks<BISHOP>(ksq) & bishops_and_queens(side_to_move()));
-  }
-}
-
 /// Position::do_move() makes a move, and backs up all information necessary
 /// to undo the move to an UndoInfo object. The move is assumed to be legal.
 /// Pseudo-legal moves should be filtered out before this function is called.
 /// Position::do_move() makes a move, and backs up all information necessary
 /// to undo the move to an UndoInfo object. The move is assumed to be legal.
 /// Pseudo-legal moves should be filtered out before this function is called.
@@ -849,12 +852,7 @@ void Position::do_move(Move m, UndoInfo& u, Bitboard dcCandidates) {
     switch (piece)
     {
     case PAWN:
     switch (piece)
     {
     case PAWN:
-        if (bit_is_set(pawn_attacks(them, ksq), to))
-            set_bit(&checkersBB, to);
-
-        if (bit_is_set(dcCandidates, from))
-            checkersBB |= ( (piece_attacks<ROOK>(ksq) & rooks_and_queens(us))
-                           |(piece_attacks<BISHOP>(ksq) & bishops_and_queens(us)));
+        update_checkers<PAWN>(&checkersBB, ksq, from, to, dcCandidates);
         break;
 
     case KNIGHT:
         break;
 
     case KNIGHT:
index d05546f75ff7d6cae1157d92be10ae79b86eb37c..3822e3bc5f225ee276724c9e3347b4e5fb772f19 100644 (file)
@@ -532,6 +532,11 @@ inline Bitboard Position::pawn_attacks(Color c, Square s) const {
   return StepAttackBB[pawn_of_color(c)][s];
 }
 
   return StepAttackBB[pawn_of_color(c)][s];
 }
 
+template<>
+inline Bitboard Position::piece_attacks<PAWN>(Square s) const {
+  return StepAttackBB[pawn_of_color(opposite_color(sideToMove))][s];
+}
+
 template<>
 inline Bitboard Position::piece_attacks<KNIGHT>(Square s) const {
   return StepAttackBB[KNIGHT][s];
 template<>
 inline Bitboard Position::piece_attacks<KNIGHT>(Square s) const {
   return StepAttackBB[KNIGHT][s];