Introduce CheckInfo struct
authorMarco Costalba <mcostalba@gmail.com>
Mon, 9 Nov 2009 19:49:01 +0000 (20:49 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 9 Nov 2009 19:50:02 +0000 (20:50 +0100)
Keeps info used to speed-up move_is_check()

No functional change.

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

index 77a6d604523f40a841a5f73ba6a2e67e41a760f3..8ab712b46d1f81a0fe6cd25865f39a1ea57e3c93 100644 (file)
@@ -56,12 +56,25 @@ Score Position::PieceSquareTable[16][64];
 
 static bool RequestPending = false;
 
-////
-//// Functions
-////
 
 /// Constructors
 
+CheckInfo::CheckInfo(const Position& pos) {
+
+  Color us = pos.side_to_move();
+  Color them = opposite_color(us);
+
+  ksq = pos.king_square(them);
+  dc = pos.discovered_check_candidates(us);
+
+  checkSq[PAWN] = pos.attacks_from<PAWN>(ksq, them);
+  checkSq[KNIGHT] = pos.attacks_from<KNIGHT>(ksq);
+  checkSq[BISHOP] = pos.attacks_from<BISHOP>(ksq);
+  checkSq[ROOK] = pos.attacks_from<ROOK>(ksq);
+  checkSq[QUEEN] = checkSq[BISHOP] | checkSq[ROOK];
+  checkSq[KING] = EmptyBoardBB;
+}
+
 Position::Position(const Position& pos) {
   copy(pos);
 }
index 09c630062dd3984ea5a2fcc0ffaa647c7ff4fe2a..9e476722955a3f012bbf9c6f67a867db41d3078e 100644 (file)
@@ -63,6 +63,18 @@ const int MaxGameLength = 220;
 //// Types
 ////
 
+/// struct checkInfo is initialized at c'tor time and keeps
+/// info used to detect if a move gives check.
+
+struct CheckInfo {
+
+    CheckInfo(const Position&);
+
+    Square ksq;
+    Bitboard dc;
+    Bitboard checkSq[8];
+};
+
 /// Castle rights, encoded as bit fields
 
 enum CastleRights {