X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fposition.cpp;h=4613ec4d63eb87594c5c4127ddd6a1006710a72e;hb=bc4f3155ae3937d32a3ebaae77ee4f7be355aa60;hp=52aa93ebddc918493fd720a58dace0b1ab1d8d17;hpb=13fe7ee4df30f5bc15189870ebf5d166e26d9906;p=stockfish diff --git a/src/position.cpp b/src/position.cpp index 52aa93eb..4613ec4d 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -591,9 +591,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { // after the move is made if (move_is_ep(m)) { - Color us = side_to_move(); Color them = opposite_color(us); - Square from = move_from(m); Square to = move_to(m); Square capsq = make_square(square_file(to), square_rank(from)); Square ksq = king_square(us); @@ -626,30 +624,32 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { } -/// Position::move_is_legal() takes a position and a (not necessarily pseudo-legal) -/// move and tests whether the move is legal. This version is not very fast and -/// should be used only in non time-critical paths. +/// Position::move_is_pl_slow() takes a position and a move and tests whether +/// the move is pseudo legal. This version is not very fast and should be used +/// only in non time-critical paths. -bool Position::move_is_legal(const Move m) const { +bool Position::move_is_pl_slow(const Move m) const { MoveStack mlist[MAX_MOVES]; - MoveStack *cur, *last = generate(*this, mlist); + MoveStack *cur, *last; + + last = in_check() ? generate(*this, mlist) + : generate(*this, mlist); - for (cur = mlist; cur != last; cur++) + for (cur = mlist; cur != last; cur++) if (cur->move == m) - return pl_move_is_legal(m, pinned_pieces(sideToMove)); + return true; return false; } -/// Fast version of Position::move_is_legal() that takes a position a move and -/// a bitboard of pinned pieces as input, and tests whether the move is legal. +/// Fast version of Position::move_is_pl() that takes a position a move and a +/// bitboard of pinned pieces as input, and tests whether the move is pseudo legal. -bool Position::move_is_legal(const Move m, Bitboard pinned) const { +bool Position::move_is_pl(const Move m) const { assert(is_ok()); - assert(pinned == pinned_pieces(sideToMove)); Color us = sideToMove; Color them = opposite_color(sideToMove); @@ -659,7 +659,7 @@ bool Position::move_is_legal(const Move m, Bitboard pinned) const { // Use a slower but simpler function for uncommon cases if (move_is_special(m)) - return move_is_legal(m); + return move_is_pl_slow(m); // Is not a promotion, so promotion piece must be empty if (move_promotion_piece(m) - 2 != PIECE_TYPE_NONE) @@ -765,8 +765,7 @@ bool Position::move_is_legal(const Move m, Bitboard pinned) const { } } - // The move is pseudo-legal, check if it is also legal - return pl_move_is_legal(m, pinned); + return true; } @@ -1779,7 +1778,7 @@ Value Position::compute_non_pawn_material(Color c) const { /// Position::is_draw() tests whether the position is drawn by material, /// repetition, or the 50 moves rule. It does not detect stalemates, this /// must be done by the search. - +template bool Position::is_draw() const { // Draw by material? @@ -1792,13 +1791,18 @@ bool Position::is_draw() const { return true; // Draw by repetition? - for (int i = 4, e = Min(Min(st->gamePly, st->rule50), st->pliesFromNull); i <= e; i += 2) - if (history[st->gamePly - i] == st->key) - return true; + if (!SkipRepetition) + for (int i = 4, e = Min(Min(st->gamePly, st->rule50), st->pliesFromNull); i <= e; i += 2) + if (history[st->gamePly - i] == st->key) + return true; return false; } +// Explicit template instantiations +template bool Position::is_draw() const; +template bool Position::is_draw() const; + /// Position::is_mate() returns true or false depending on whether the /// side to move is checkmated.