summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
69f4954)
It's only necessary to do the checking at the end of every non-const
member (including the constructors and from_fen()) of class Position.
Once the post-condition of every modifier guarantees the class invariant,
we don't need to verify sanity of the position as preconditions for outside
callers such as movegen, search etc. For non-class types such as Move and
Square we still need to assert of course.
Suggested by Rein Halbersma.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
Value margins[2];
Score score, mobilityWhite, mobilityBlack;
Value margins[2];
Score score, mobilityWhite, mobilityBlack;
assert(pos.thread() >= 0 && pos.thread() < MAX_THREADS);
assert(!pos.in_check());
assert(pos.thread() >= 0 && pos.thread() < MAX_THREADS);
assert(!pos.in_check());
if (m == MOVE_NULL)
return "(null)";
if (m == MOVE_NULL)
return "(null)";
assert(move_is_ok(m));
Bitboard attackers;
assert(move_is_ok(m));
Bitboard attackers;
template<MoveType Type>
MoveStack* generate(const Position& pos, MoveStack* mlist) {
template<MoveType Type>
MoveStack* generate(const Position& pos, MoveStack* mlist) {
assert(!pos.in_check());
Color us = pos.side_to_move();
assert(!pos.in_check());
Color us = pos.side_to_move();
template<>
MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist) {
template<>
MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist) {
assert(!pos.in_check());
Bitboard b, dc;
assert(!pos.in_check());
Bitboard b, dc;
template<>
MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
template<>
MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
assert(pos.in_check());
Bitboard b, target;
assert(pos.in_check());
Bitboard b, target;
template<>
MoveStack* generate<MV_LEGAL>(const Position& pos, MoveStack* mlist) {
template<>
MoveStack* generate<MV_LEGAL>(const Position& pos, MoveStack* mlist) {
MoveStack *last, *cur = mlist;
Bitboard pinned = pos.pinned_pieces();
MoveStack *last, *cur = mlist;
Bitboard pinned = pos.pinned_pieces();
PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) const {
PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) const {
Key key = pos.get_pawn_key();
PawnInfo* pi = probe(key);
Key key = pos.get_pawn_key();
PawnInfo* pi = probe(key);
detach(); // Always detach() in copy c'tor to avoid surprises
threadID = th;
nodes = 0;
detach(); // Always detach() in copy c'tor to avoid surprises
threadID = th;
nodes = 0;
}
Position::Position(const string& fen, bool isChess960, int th) {
}
Position::Position(const string& fen, bool isChess960, int th) {
st->value = compute_value();
st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
st->npMaterial[BLACK] = compute_non_pawn_material(BLACK);
st->value = compute_value();
st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
st->npMaterial[BLACK] = compute_non_pawn_material(BLACK);
bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
assert(move_is_ok(m));
assert(pinned == pinned_pieces());
assert(move_is_ok(m));
assert(pinned == pinned_pieces());
bool Position::move_is_pl(const Move m) const {
bool Position::move_is_pl(const Move m) const {
Color us = sideToMove;
Color them = opposite_color(sideToMove);
Square from = move_from(m);
Color us = sideToMove;
Color them = opposite_color(sideToMove);
Square from = move_from(m);
bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
assert(move_is_ok(m));
assert(ci.dcCandidates == discovered_check_candidates());
assert(piece_color(piece_on(move_from(m))) == side_to_move());
assert(move_is_ok(m));
assert(ci.dcCandidates == discovered_check_candidates());
assert(piece_color(piece_on(move_from(m))) == side_to_move());
// Our StateInfo newSt is about going out of scope so copy
// its content before it disappears.
detach();
// Our StateInfo newSt is about going out of scope so copy
// its content before it disappears.
detach();
void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck) {
void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck) {
assert(move_is_ok(m));
assert(&newSt != st);
assert(move_is_ok(m));
assert(&newSt != st);
void Position::undo_move(Move m) {
void Position::undo_move(Move m) {
assert(move_is_ok(m));
sideToMove = opposite_color(sideToMove);
assert(move_is_ok(m));
sideToMove = opposite_color(sideToMove);
void Position::do_null_move(StateInfo& backupSt) {
void Position::do_null_move(StateInfo& backupSt) {
assert(!in_check());
// Back up the information necessary to undo the null move to the supplied
assert(!in_check());
// Back up the information necessary to undo the null move to the supplied
st->rule50++;
st->pliesFromNull = 0;
st->value += (sideToMove == WHITE) ? TempoValue : -TempoValue;
st->rule50++;
st->pliesFromNull = 0;
st->value += (sideToMove == WHITE) ? TempoValue : -TempoValue;
void Position::undo_null_move() {
void Position::undo_null_move() {
assert(!in_check());
// Restore information from the our backup StateInfo object
assert(!in_check());
// Restore information from the our backup StateInfo object
sideToMove = opposite_color(sideToMove);
st->rule50--;
st->gamePly--;
sideToMove = opposite_color(sideToMove);
st->rule50--;
st->gamePly--;
// Make a copy of current position before to start changing
const Position pos(*this, threadID);
// Make a copy of current position before to start changing
const Position pos(*this, threadID);
- // No default or copy c'tor allowed, default c'tor will not be generated
- // anyhow because of user-defined c'tors.
+ // No defaul, copy c'tor or assignment allowed, default c'tor will not be
+ // generated anyhow because of user-defined c'tors.
Position(const Position&);
Position(const Position&);
+ Position& operator=(const Position&);
public:
Position(const Position& pos, int threadID);
public:
Position(const Position& pos, int threadID);
limits.time = time[pos.side_to_move()];
limits.increment = inc[pos.side_to_move()];
limits.time = time[pos.side_to_move()];
limits.increment = inc[pos.side_to_move()];
return think(pos, limits, searchMoves);
}
return think(pos, limits, searchMoves);
}