/*
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
- Copyright (C) 2008-2014 Marco Costalba, Joona Kiiski, Tord Romstad
+ Copyright (C) 2008-2015 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
#include <algorithm>
#include <cassert>
-#include <cstring>
+#include <cstring> // For std::memset
#include <iomanip>
#include <sstream>
Key exclusion;
}
-Key Position::exclusion_key() const { return st->key ^ Zobrist::exclusion;}
+Key Position::exclusion_key() const { return st->key ^ Zobrist::exclusion; }
namespace {
<< std::setfill('0') << std::setw(16) << pos.st->key << std::dec << "\nCheckers: ";
for (Bitboard b = pos.checkers(); b; )
- os << UCI::format_square(pop_lsb(&b)) << " ";
+ os << UCI::square(pop_lsb(&b)) << " ";
return os;
}
}
-/// Position::operator=() creates a copy of 'pos'. We want the new born Position
-/// object to not depend on any external data so we detach state pointer from
-/// the source one.
+/// Position::operator=() creates a copy of 'pos' but detaching the state pointer
+/// from the source to be self-consistent and not depending on any external data.
Position& Position::operator=(const Position& pos) {
if (!can_castle(WHITE) && !can_castle(BLACK))
ss << '-';
- ss << (ep_square() == SQ_NONE ? " - " : " " + UCI::format_square(ep_square()) + " ")
+ ss << (ep_square() == SQ_NONE ? " - " : " " + UCI::square(ep_square()) + " ")
<< st->rule50 << " " << 1 + (gamePly - (sideToMove == BLACK)) / 2;
return ss.str();
return true;
// Is there a discovered check?
- if ( unlikely(ci.dcCandidates)
+ if ( ci.dcCandidates
&& (ci.dcCandidates & from)
&& !aligned(from, to, ci.ksq))
return true;
void Position::do_move(Move m, StateInfo& newSt) {
CheckInfo ci(*this);
- do_move(m, newSt, ci, gives_check(m, ci));
+ do_move(m, newSt, gives_check(m, ci));
}
-void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck) {
+void Position::do_move(Move m, StateInfo& newSt, bool moveIsCheck) {
assert(is_ok(m));
assert(&newSt != st);
// Update the key with the final value
st->key = k;
- // Update checkers bitboard: piece must be already moved due to attacks_from()
- st->checkersBB = 0;
-
- if (moveIsCheck)
- {
- if (type_of(m) != NORMAL)
- st->checkersBB = attackers_to(king_square(them)) & pieces(us);
- else
- {
- // Direct checks
- if (ci.checkSq[pt] & to)
- st->checkersBB |= to;
-
- // Discovered checks
- if (unlikely(ci.dcCandidates) && (ci.dcCandidates & from))
- {
- if (pt != ROOK)
- st->checkersBB |= attacks_from<ROOK>(king_square(them)) & pieces(us, QUEEN, ROOK);
-
- if (pt != BISHOP)
- st->checkersBB |= attacks_from<BISHOP>(king_square(them)) & pieces(us, QUEEN, BISHOP);
- }
- }
- }
+ // Calculate checkers bitboard (if move is check)
+ st->checkersBB = moveIsCheck ? attackers_to(king_square(them)) & pieces(us) : 0;
sideToMove = ~sideToMove;
stm = color_of(piece_on(from));
occupied = pieces() ^ from;
- // Castling moves are implemented as king capturing the rook so cannot be
- // handled correctly. Simply return 0 that is always the correct value
+ // Castling moves are implemented as king capturing the rook so cannot
+ // be handled correctly. Simply return VALUE_ZERO that is always correct
// unless in the rare case the rook ends up under attack.
if (type_of(m) == CASTLING)
return VALUE_ZERO;