]> git.sesse.net Git - stockfish/blobdiff - src/position.h
Use update_checkers<>() also for PAWN
[stockfish] / src / position.h
index 27ec25a7e60d0ac270fd6bee175e8b61b07949e7..3822e3bc5f225ee276724c9e3347b4e5fb772f19 100644 (file)
@@ -86,8 +86,8 @@ struct UndoInfo {
   Key key, pawnKey, materialKey;
   int rule50;
   Move lastMove;
-  PieceType capture;
   Value mgValue, egValue;
+  PieceType capture;
 };
 
 
@@ -122,13 +122,13 @@ class Position {
 public:
   // Constructors
   Position() {};
-  Position(const Position &pos);
-  Position(const std::string &fen);
+  Position(const Positionpos);
+  Position(const std::stringfen);
 
   // Text input/output
-  void from_fen(const std::string &fen);
+  void from_fen(const std::stringfen);
   const std::string to_fen() const;
-  void print() const;
+  void print(Move m = MOVE_NONE) const;
 
   // Copying
   void copy(const Position &pos);
@@ -174,13 +174,13 @@ public:
   // Number of pieces of each color and type
   int piece_count(Color c, PieceType pt) const;
 
-  // The en passant square:
+  // The en passant square
   Square ep_square() const;
 
   // Current king position for each color
   Square king_square(Color c) const;
 
-  // Castling rights.
+  // Castling rights
   bool can_castle_kingside(Color c) const;
   bool can_castle_queenside(Color c) const;
   bool can_castle(Color c) const;
@@ -253,6 +253,7 @@ public:
   // Static exchange evaluation
   int see(Square from, Square to) const;
   int see(Move m) const;
+  int see(Square to) const;
 
   // Accessing hash keys
   Key get_key() const;
@@ -267,7 +268,7 @@ public:
   Value mg_pst_delta(Move m) const;
 
   // Game termination checks
-  bool is_mate();
+  bool is_mate() const;
   bool is_draw() const;
 
   // Check if one side threatens a mate in one
@@ -307,6 +308,9 @@ private:
   void undo_ep_move(Move m);
   void find_checkers();
 
+  template<PieceType Piece>
+  void update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates);
+
   template<PieceType Piece, bool FindPinned>
   Bitboard hidden_checks(Color c, Square ksq) const;
 
@@ -528,6 +532,11 @@ inline Bitboard Position::pawn_attacks(Color c, Square s) const {
   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];
@@ -570,6 +579,16 @@ Bitboard Position::piece_attacks_square(Square f, Square t) const {
   return bit_is_set(piece_attacks<Piece>(f), t);
 }
 
+inline Bitboard Position::attacks_to(Square s, Color c) const {
+
+  return attacks_to(s) & pieces_of_color(c);
+}
+
+inline bool Position::square_is_attacked(Square s, Color c) const {
+
+  return attacks_to(s, c) != EmptyBoardBB;
+}
+
 inline bool Position::pawn_is_passed(Color c, Square s) const {
   return !(pawns(opposite_color(c)) & passed_pawn_mask(c, s));
 }