]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Stockfish 1.3.1
[stockfish] / src / position.cpp
index abe75807e2869044b05aad7b1cdfd696c31594bf..5f19403035313eddc8e7694c4f9ce52f9bdc60d6 100644 (file)
@@ -599,19 +599,17 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const {
 
   case BISHOP:
     return   (dcCandidates && bit_is_set(dcCandidates, from))
-          || (   direction_between_squares(ksq, to) != DIR_NONE
-              && bit_is_set(piece_attacks<BISHOP>(ksq), to));
+          || (direction_is_diagonal(ksq, to) && bit_is_set(piece_attacks<BISHOP>(ksq), to));
 
   case ROOK:
     return   (dcCandidates && bit_is_set(dcCandidates, from))
-          || (   direction_between_squares(ksq, to) != DIR_NONE
-              && bit_is_set(piece_attacks<ROOK>(ksq), to));
+          || (direction_is_straight(ksq, to) && bit_is_set(piece_attacks<ROOK>(ksq), to));
 
   case QUEEN:
       // Discovered checks are impossible!
       assert(!bit_is_set(dcCandidates, from));
-      return (   direction_between_squares(ksq, to) != DIR_NONE
-              && bit_is_set(piece_attacks<QUEEN>(ksq), to));
+      return (   (direction_is_straight(ksq, to) && bit_is_set(piece_attacks<ROOK>(ksq), to))
+              || (direction_is_diagonal(ksq, to) && bit_is_set(piece_attacks<BISHOP>(ksq), to)));
 
   case KING:
       // Discovered check?
@@ -651,20 +649,6 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const {
 }
 
 
-/// Position::move_is_capture() tests whether a move from the current
-/// position is a capture. Move must not be MOVE_NONE.
-
-bool Position::move_is_capture(Move m) const {
-
-  assert(m != MOVE_NONE);
-
-  return (   !square_is_empty(move_to(m))
-          && (color_of_piece_on(move_to(m)) != color_of_piece_on(move_from(m)))
-         )
-         || move_is_ep(m);
-}
-
-
 /// Position::update_checkers() udpates chekers info given the move. It is called
 /// in do_move() and is faster then find_checkers().
 
@@ -1955,26 +1939,26 @@ bool Position::has_mate_threat(Color c) {
 
 void Position::init_zobrist() {
 
-  for(Piece p = WP; p <= BK; p++)
-      for(Square s = SQ_A1; s <= SQ_H8; s++)
-          zobrist[color_of_piece(p)][type_of_piece(p)][s] = genrand_int64();
+  for (int i = 0; i < 2; i++)
+      for (int j = 0; j < 8; j++)
+          for (int k = 0; k < 64; k++)
+              zobrist[i][j][k] = Key(genrand_int64());
 
-  zobEp[0] = 0ULL;
-  for(int i = 1; i < 64; i++)
-      zobEp[i] = genrand_int64();
+  for (int i = 0; i < 64; i++)
+      zobEp[i] = Key(genrand_int64());
 
-  for(int i = 15; i >= 0; i--)
-      zobCastle[(i&8) | (i&1) | ((i&2) << 1) | ((i&4) >> 1)] = genrand_int64();
+  for (int i = 0; i < 16; i++)
+      zobCastle[i] = genrand_int64();
 
   zobSideToMove = genrand_int64();
 
   for (int i = 0; i < 2; i++)
       for (int j = 0; j < 8; j++)
           for (int k = 0; k < 16; k++)
-              zobMaterial[i][j][k] = (k > 0)? genrand_int64() : 0LL;
+              zobMaterial[i][j][k] = (k > 0)? Key(genrand_int64()) : Key(0LL);
 
   for (int i = 0; i < 16; i++)
-      zobMaterial[0][KING][i] = zobMaterial[1][KING][i] = 0ULL;
+      zobMaterial[0][KING][i] = zobMaterial[1][KING][i] = Key(0ULL);
 }