X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=98e79df2a82d2d661c9af66aa8d8004466da1bab;hp=8390facc5b501a040333c820285bd28e15573a29;hb=dc2302b701083dade07d59b1ffbfd180d47c4383;hpb=3c05bd70ebf57cebb88d29a88e6c492976a97761 diff --git a/src/position.cpp b/src/position.cpp index 8390facc..98e79df2 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -39,6 +39,8 @@ //// Variables //// +extern SearchStack EmptySearchStack; + int Position::castleRightsMask[64]; Key Position::zobrist[2][8][64]; @@ -50,6 +52,7 @@ Key Position::zobSideToMove; Value Position::MgPieceSquareTable[16][64]; Value Position::EgPieceSquareTable[16][64]; +static bool RequestPending = false; //// //// Functions @@ -243,7 +246,7 @@ const std::string Position::to_fen() const { fen += (rank > RANK_1 ? '/' : ' '); } - fen += (sideToMove == WHITE ? 'w' : 'b') + ' '; + fen += (sideToMove == WHITE ? "w " : "b "); if (castleRights != NO_CASTLES) { if (can_castle_kingside(WHITE)) fen += 'K'; @@ -270,11 +273,18 @@ void Position::print(Move m) const { static const std::string pieceLetters = " PNBRQK PNBRQK ."; + // Check for reentrancy, as example when called from inside + // MovePicker that is used also here in move_to_san() + if (RequestPending) + return; + + RequestPending = true; + std::cout << std::endl; if (m != MOVE_NONE) { - Position p(*this); - std::cout << "Move is: " << move_to_san(p, m) << std::endl; + std::string col = (color_of_piece_on(move_from(m)) == BLACK ? ".." : ""); + std::cout << "Move is: " << col << move_to_san(*this, m) << std::endl; } for (Rank rank = RANK_8; rank >= RANK_1; rank--) { @@ -291,9 +301,11 @@ void Position::print(Move m) const { } std::cout << '|' << std::endl; } - std::cout << "+---+---+---+---+---+---+---+---+" << std::endl; - std::cout << "Fen is: " << to_fen() << std::endl; - std::cout << key << std::endl; + std::cout << "+---+---+---+---+---+---+---+---+" << std::endl + << "Fen is: " << to_fen() << std::endl + << "Key is: " << key << std::endl; + + RequestPending = false; } @@ -663,10 +675,12 @@ 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. +/// 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)) == opposite_color(side_to_move())) ) @@ -1913,8 +1927,7 @@ bool Position::is_mate() { if (is_check()) { - MovePicker mp = MovePicker(*this, false, MOVE_NONE, MOVE_NONE, - MOVE_NONE, MOVE_NONE, Depth(0)); + MovePicker mp = MovePicker(*this, false, MOVE_NONE, EmptySearchStack, Depth(0)); return mp.get_next_move() == MOVE_NONE; } return false;