]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Stockfish 1.5
[stockfish] / src / position.cpp
index 96b455f1249801cf9b6435ec72b0ea2b2f30b5ba..00503429242342be2d9f0587fa73b06b2a0ceab7 100644 (file)
@@ -704,7 +704,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
   struct ReducedStateInfo {
     Key key, pawnKey, materialKey;
     int castleRights, rule50;
-    Square kingSquare[2], epSquare;
+    Square epSquare;
     Value mgValue, egValue;
     Value npMaterial[2];
   };
@@ -784,10 +784,6 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
   board[to] = board[from];
   board[from] = EMPTY;
 
-  // If the moving piece was a king, update the king square
-  if (pt == KING)
-      st->kingSquare[us] = to;
-
   // Update piece lists, note that index[from] is not updated and
   // becomes stale. This works as long as index[] is accessed just
   // by known occupied squares.
@@ -842,6 +838,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
       Square lastPawnSquare = pieceList[us][PAWN][pieceCount[us][PAWN]];
       index[lastPawnSquare] = index[to];
       pieceList[us][PAWN][index[lastPawnSquare]] = lastPawnSquare;
+      pieceList[us][PAWN][pieceCount[us][PAWN]] = SQ_NONE;
       index[to] = pieceCount[us][promotion] - 1;
       pieceList[us][promotion][index[to]] = to;
 
@@ -947,6 +944,7 @@ void Position::do_capture_move(Bitboard& key, PieceType capture, Color them, Squ
     Square lastPieceSquare = pieceList[them][capture][pieceCount[them][capture]];
     index[lastPieceSquare] = index[capsq];
     pieceList[them][capture][index[lastPieceSquare]] = lastPieceSquare;
+    pieceList[them][capture][pieceCount[them][capture]] = SQ_NONE;
 
     // Reset rule 50 counter
     st->rule50 = 0;
@@ -1005,9 +1003,6 @@ void Position::do_castle_move(Move m) {
   board[kto] = king;
   board[rto] = rook;
 
-  // Update king square
-  st->kingSquare[us] = kto;
-
   // Update piece lists
   pieceList[us][KING][index[kfrom]] = kto;
   pieceList[us][ROOK][index[rfrom]] = rto;
@@ -1106,6 +1101,7 @@ void Position::undo_move(Move m) {
       Square lastPromotionSquare = pieceList[us][promotion][pieceCount[us][promotion]];
       index[lastPromotionSquare] = index[to];
       pieceList[us][promotion][index[lastPromotionSquare]] = lastPromotionSquare;
+      pieceList[us][promotion][pieceCount[us][promotion]] = SQ_NONE;
       index[to] = pieceCount[us][PAWN] - 1;
       pieceList[us][PAWN][index[to]] = to;
   }
@@ -1325,7 +1321,7 @@ int Position::see(Square from, Square to) const {
     0, 0
   };
 
-  Bitboard attackers, stmAttackers, occ, b;
+  Bitboard attackers, stmAttackers, b;
 
   assert(square_is_ok(from) || from == SQ_NONE);
   assert(square_is_ok(to));
@@ -1337,10 +1333,7 @@ int Position::see(Square from, Square to) const {
   // Initialize pieces
   Piece piece = piece_on(from);
   Piece capture = piece_on(to);
-
-  // Find all attackers to the destination square, with the moving piece
-  // removed, but possibly an X-ray attacker added behind it.
-  occ = occupied_squares();
+  Bitboard occ = occupied_squares();
 
   // Handle en passant moves
   if (st->epSquare == to && type_of_piece_on(from) == PAWN)
@@ -1357,6 +1350,8 @@ int Position::see(Square from, Square to) const {
 
   while (true)
   {
+      // Find all attackers to the destination square, with the moving piece
+      // removed, but possibly an X-ray attacker added behind it.
       clear_bit(&occ, from);
       attackers =  (rook_attacks_bb(to, occ)      & pieces(ROOK, QUEEN))
                  | (bishop_attacks_bb(to, occ)    & pieces(BISHOP, QUEEN))
@@ -1519,9 +1514,6 @@ void Position::put_piece(Piece p, Square s) {
   set_bit(&byTypeBB[0], s); // HACK: byTypeBB[0] contains all occupied squares.
 
   pieceCount[c][pt]++;
-
-  if (pt == KING)
-      st->kingSquare[c] = s;
 }
 
 
@@ -2014,7 +2006,7 @@ bool Position::is_ok(int* failedStep) const {
           for(PieceType pt = PAWN; pt <= KING; pt++)
               for(int i = 0; i < pieceCount[c][pt]; i++)
               {
-                  if (piece_on(piece_list(c, pt, i)) != (pieces(pt, c)))
+                  if (piece_on(piece_list(c, pt, i)) != piece_of_color_and_type(c, pt))
                       return false;
 
                   if (index[piece_list(c, pt, i)] != i)