X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=23ffbaa46593c8dad832a7ee6ebd0973a1820228;hp=8cc5fccd0bcc5e8cf51c405637a020929f5f20d3;hb=141caf1d5b642bab826e2e8a7ab043b8c4928250;hpb=23fd3796947a3a8863d4a336c7a30aba65752742 diff --git a/src/position.cpp b/src/position.cpp index 8cc5fccd..23ffbaa4 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -382,7 +382,7 @@ const string Position::to_fen() const { /// Position::print() prints an ASCII representation of the position to -/// the standard output. If a move is given then also the san is print. +/// the standard output. If a move is given then also the san is printed. void Position::print(Move move) const { @@ -523,6 +523,7 @@ bool Position::move_attacks_square(Move m, Square s) const { assert(move_is_ok(m)); assert(square_is_ok(s)); + Bitboard occ, xray; Square f = move_from(m), t = move_to(m); assert(square_is_occupied(f)); @@ -531,12 +532,11 @@ bool Position::move_attacks_square(Move m, Square s) const { return true; // Move the piece and scan for X-ray attacks behind it - Bitboard occ = occupied_squares(); - Color us = color_of_piece_on(f); - clear_bit(&occ, f); - set_bit(&occ, t); - Bitboard xray = ( (rook_attacks_bb(s, occ) & pieces(ROOK, QUEEN)) - |(bishop_attacks_bb(s, occ) & pieces(BISHOP, QUEEN))) & pieces_of_color(us); + occ = occupied_squares(); + do_move_bb(&occ, make_move_bb(f, t)); + xray = ( (rook_attacks_bb(s, occ) & pieces(ROOK, QUEEN)) + |(bishop_attacks_bb(s, occ) & pieces(BISHOP, QUEEN))) + & pieces_of_color(color_of_piece_on(f)); // If we have attacks we need to verify that are caused by our move // and are not already existent ones. @@ -1561,7 +1561,7 @@ void Position::allow_ooo(Color c) { Key Position::compute_key() const { - Key result = Key(0ULL); + Key result = 0; for (Square s = SQ_A1; s <= SQ_H8; s++) if (square_is_occupied(s)) @@ -1586,7 +1586,7 @@ Key Position::compute_key() const { Key Position::compute_pawn_key() const { - Key result = Key(0ULL); + Key result = 0; Bitboard b; Square s; @@ -1611,7 +1611,7 @@ Key Position::compute_pawn_key() const { Key Position::compute_material_key() const { - Key result = Key(0ULL); + Key result = 0; for (Color c = WHITE; c <= BLACK; c++) for (PieceType pt = PAWN; pt <= QUEEN; pt++) { @@ -1677,7 +1677,6 @@ 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. -// FIXME: Currently we are not handling 50 move rule correctly when in check bool Position::is_draw() const { @@ -1687,7 +1686,7 @@ bool Position::is_draw() const { return true; // Draw by the 50 moves rule? - if (st->rule50 > 100 || (st->rule50 == 100 && !is_check())) + if (st->rule50 > 99 && (st->rule50 > 100 || !is_mate())) return true; // Draw by repetition? @@ -1704,7 +1703,7 @@ bool Position::is_draw() const { bool Position::is_mate() const { - MoveStack moves[256]; + MoveStack moves[MOVES_MAX]; return is_check() && (generate_moves(*this, moves) == moves); } @@ -1714,7 +1713,7 @@ bool Position::is_mate() const { bool Position::has_mate_threat() { - MoveStack mlist[256], *last, *cur; + MoveStack mlist[MOVES_MAX], *last, *cur; StateInfo st1, st2; bool mateFound = false; @@ -1918,7 +1917,7 @@ bool Position::is_ok(int* failedStep) const { // Is there more than 2 checkers? if (failedStep) (*failedStep)++; - if (debugCheckerCount && count_1s(st->checkersBB) > 2) + if (debugCheckerCount && count_1s(st->checkersBB) > 2) return false; // Bitboards OK? @@ -1987,7 +1986,7 @@ bool Position::is_ok(int* failedStep) const { if (debugPieceCounts) for (Color c = WHITE; c <= BLACK; c++) for (PieceType pt = PAWN; pt <= KING; pt++) - if (pieceCount[c][pt] != count_1s(pieces(pt, c))) + if (pieceCount[c][pt] != count_1s(pieces(pt, c))) return false; if (failedStep) (*failedStep)++;