]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Generate pseudo-legal moves in generate_evasions()
[stockfish] / src / position.cpp
index 4e9a6dc7b02388ddae1c8224a9bfd8eeedea2368..be4e234d99d9b937036ee9d6fabb9cec170a0e40 100644 (file)
@@ -470,7 +470,6 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
   assert(is_ok());
   assert(move_is_ok(m));
   assert(pinned == pinned_pieces(side_to_move()));
-  assert(!is_check());
 
   // Castling moves are checked for legality during move generation.
   if (move_is_castle(m))
@@ -482,7 +481,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
   assert(color_of_piece_on(from) == us);
   assert(piece_on(king_square(us)) == piece_of_color_and_type(us, KING));
 
-  // En passant captures are a tricky special case.  Because they are
+  // En passant captures are a tricky special case. Because they are
   // rather uncommon, we do it simply by testing whether the king is attacked
   // after the move is made
   if (move_is_ep(m))
@@ -1338,6 +1337,7 @@ int Position::see(Square from, Square to) const {
 
   Bitboard attackers, stmAttackers, b;
 
+  assert(!shortcut || from != SQ_NONE);
   assert(square_is_ok(from) || from == SQ_NONE);
   assert(square_is_ok(to));
 
@@ -1350,6 +1350,10 @@ int Position::see(Square from, Square to) const {
   Piece capture = piece_on(to);
   Bitboard occ = occupied_squares();
 
+  // King cannot be recaptured
+  if (type_of_piece(piece) == KING)
+      return seeValues[capture];
+
   // Handle en passant moves
   if (st->epSquare == to && type_of_piece_on(from) == PAWN)
   {
@@ -1488,8 +1492,8 @@ void Position::clear() {
   for (int i = 0; i < 64; i++)
       board[i] = EMPTY;
 
-  for (int i = 0; i < 7; i++)
-      for (int j = 0; j < 8; j++)
+  for (int i = 0; i < 8; i++)
+      for (int j = 0; j < 16; j++)
           pieceList[0][i][j] = pieceList[1][i][j] = SQ_NONE;
 
   sideToMove = WHITE;
@@ -1701,8 +1705,7 @@ bool Position::is_draw() const {
 bool Position::is_mate() const {
 
   MoveStack moves[256];
-
-  return is_check() && (generate_evasions(*this, moves, pinned_pieces(sideToMove)) == moves);
+  return is_check() && (generate_moves(*this, moves, false) == moves);
 }