X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=1c9663000e011af6df038d459a1bdb96337a25fa;hp=f0bbff449427eaa09509645876532ebfe5b45f8d;hb=9b43fd79372946128924ab3d42c64559e95d29d6;hpb=a695ed65a8b98c94a928862be76500485b38c414 diff --git a/src/position.cpp b/src/position.cpp index f0bbff44..1c966300 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1,7 +1,7 @@ /* Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) - Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad + Copyright (C) 2008-2012 Marco Costalba, Joona Kiiski, Tord Romstad Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -79,7 +79,7 @@ namespace { CheckInfo::CheckInfo(const Position& pos) { Color them = flip(pos.side_to_move()); - Square ksq = pos.king_square(them); + ksq = pos.king_square(them); pinned = pos.pinned_pieces(); dcCandidates = pos.discovered_check_candidates(); @@ -338,7 +338,7 @@ void Position::print(Move move) const { Piece piece = piece_on(sq); char c = (color_of(piece) == BLACK ? '=' : ' '); - if (piece == NO_PIECE && color_of(sq) == DARK) + if (piece == NO_PIECE && !opposite_colors(sq, SQ_A1)) piece++; // Index the dot cout << c << PieceToChar[piece] << c << '|'; @@ -420,8 +420,8 @@ bool Position::move_attacks_square(Move m, Square s) const { assert(square_is_ok(s)); Bitboard occ, xray; - Square from = move_from(m); - Square to = move_to(m); + Square from = from_sq(m); + Square to = to_sq(m); Piece piece = piece_on(from); assert(!square_is_empty(from)); @@ -451,7 +451,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { assert(pinned == pinned_pieces()); Color us = side_to_move(); - Square from = move_from(m); + Square from = from_sq(m); assert(color_of(piece_on(from)) == us); assert(piece_on(king_square(us)) == make_piece(us, KING)); @@ -462,7 +462,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { if (is_enpassant(m)) { Color them = flip(us); - Square to = move_to(m); + Square to = to_sq(m); Square capsq = to + pawn_push(them); Square ksq = king_square(us); Bitboard b = occupied_squares(); @@ -484,13 +484,13 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { // square is attacked by the opponent. Castling moves are checked // for legality during move generation. if (type_of(piece_on(from)) == KING) - return is_castle(m) || !(attackers_to(move_to(m)) & pieces(flip(us))); + return is_castle(m) || !(attackers_to(to_sq(m)) & pieces(flip(us))); // A non-king move is legal if and only if it is not pinned or it // is moving along the ray towards or away from the king. return !pinned || !bit_is_set(pinned, from) - || squares_aligned(from, move_to(m), king_square(us)); + || squares_aligned(from, to_sq(m), king_square(us)); } @@ -516,8 +516,8 @@ bool Position::is_pseudo_legal(const Move m) const { Color us = sideToMove; Color them = flip(sideToMove); - Square from = move_from(m); - Square to = move_to(m); + Square from = from_sq(m); + Square to = to_sq(m); Piece pc = piece_on(from); // Use a slower but simpler function for uncommon cases @@ -613,7 +613,7 @@ bool Position::is_pseudo_legal(const Move m) const { { Bitboard b = occupied_squares(); clear_bit(&b, from); - if (attackers_to(move_to(m), b) & pieces(flip(us))) + if (attackers_to(to_sq(m), b) & pieces(flip(us))) return false; } else @@ -626,7 +626,7 @@ bool Position::is_pseudo_legal(const Move m) const { // Our move must be a blocking evasion or a capture of the checking piece target = squares_between(checksq, king_square(us)) | checkers(); - if (!bit_is_set(target, move_to(m))) + if (!bit_is_set(target, to_sq(m))) return false; } } @@ -641,10 +641,10 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const { assert(is_ok(m)); assert(ci.dcCandidates == discovered_check_candidates()); - assert(color_of(piece_on(move_from(m))) == side_to_move()); + assert(color_of(piece_on(from_sq(m))) == side_to_move()); - Square from = move_from(m); - Square to = move_to(m); + Square from = from_sq(m); + Square to = to_sq(m); PieceType pt = type_of(piece_on(from)); // Direct check ? @@ -766,8 +766,8 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI Color us = side_to_move(); Color them = flip(us); - Square from = move_from(m); - Square to = move_to(m); + Square from = from_sq(m); + Square to = to_sq(m); Piece piece = piece_on(from); PieceType pt = type_of(piece); PieceType capture = is_enpassant(m) ? PAWN : type_of(piece_on(to)); @@ -982,8 +982,8 @@ void Position::undo_move(Move m) { Color us = side_to_move(); Color them = flip(us); - Square from = move_from(m); - Square to = move_to(m); + Square from = from_sq(m); + Square to = to_sq(m); Piece piece = piece_on(to); PieceType pt = type_of(piece); PieceType capture = st->capturedType; @@ -1077,8 +1077,8 @@ void Position::do_castle_move(Move m) { Square kto, kfrom, rfrom, rto, kAfter, rAfter; Color us = side_to_move(); - Square kBefore = move_from(m); - Square rBefore = move_to(m); + Square kBefore = from_sq(m); + Square rBefore = to_sq(m); // Find after-castle squares for king and rook if (rBefore > kBefore) // O-O @@ -1228,8 +1228,8 @@ int Position::see_sign(Move m) const { assert(is_ok(m)); - Square from = move_from(m); - Square to = move_to(m); + Square from = from_sq(m); + Square to = to_sq(m); // Early return if SEE cannot be negative because captured piece value // is not less then capturing one. Note that king moves always return @@ -1256,8 +1256,8 @@ int Position::see(Move m) const { if (is_castle(m)) return 0; - from = move_from(m); - to = move_to(m); + from = from_sq(m); + to = to_sq(m); capturedType = type_of(piece_on(to)); occ = occupied_squares(); @@ -1691,7 +1691,7 @@ bool Position::pos_is_ok(int* failedStep) const { // Is there more than 2 checkers? if (failedStep) (*failedStep)++; - if (debugCheckerCount && count_1s(st->checkersBB) > 2) + if (debugCheckerCount && popcount(st->checkersBB) > 2) return false; // Bitboards OK? @@ -1760,7 +1760,7 @@ bool Position::pos_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] != popcount(pieces(pt, c))) return false; if (failedStep) (*failedStep)++;