/// object do not depend on any external data so we detach state pointer from
/// the source one.
-Position& Position::operator=(const Position& pos) {
+void Position::operator=(const Position& pos) {
memcpy(this, &pos, sizeof(Position));
startState = *st;
st = &startState;
nodes = 0;
- return *this;
+
+ assert(pos_is_ok());
}
/// string. This function is not very robust - make sure that input FENs are
/// correct (this is assumed to be the responsibility of the GUI).
-void Position::from_fen(const string& fenStr, bool isChess960) {
+void Position::from_fen(const string& fenStr, bool isChess960, Thread* th) {
/*
A FEN string defines a particular position using only the ASCII character set.
st->npMaterial[BLACK] = compute_non_pawn_material(BLACK);
st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove);
chess960 = isChess960;
+ thisThread = th;
assert(pos_is_ok());
}
}
// Prefetch pawn and material hash tables
- prefetch((char*)this_thread->pawnTable.entries[st->pawnKey]);
- prefetch((char*)this_thread->materialTable.entries[st->materialKey]);
+ prefetch((char*)thisThread->pawnTable.entries[st->pawnKey]);
+ prefetch((char*)thisThread->materialTable.entries[st->materialKey]);
// Update incremental scores
st->psqScore += psq_delta(piece, from, to);
void Position::flip() {
- // Make a copy of current position before to start changing
const Position pos(*this);
clear();
- // Board
+ sideToMove = ~pos.side_to_move();
+ thisThread = pos.this_thread();
+ nodes = pos.nodes_searched();
+ chess960 = pos.is_chess960();
+ startPosPly = pos.startpos_ply_counter();
+
for (Square s = SQ_A1; s <= SQ_H8; s++)
if (!pos.square_empty(s))
put_piece(Piece(pos.piece_on(s) ^ 8), ~s);
- // Side to move
- sideToMove = ~pos.side_to_move();
-
- // Castling rights
if (pos.can_castle(WHITE_OO))
set_castle_right(BLACK, ~pos.castle_rook_square(WHITE_OO));
if (pos.can_castle(WHITE_OOO))
if (pos.can_castle(BLACK_OOO))
set_castle_right(WHITE, ~pos.castle_rook_square(BLACK_OOO));
- // En passant square
if (pos.st->epSquare != SQ_NONE)
st->epSquare = ~pos.st->epSquare;
- // Checkers
- st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove);
-
- // Hash keys
st->key = compute_key();
st->pawnKey = compute_pawn_key();
st->materialKey = compute_material_key();
-
- // Incremental scores
st->psqScore = compute_psq_score();
-
- // Material
+ st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove);
st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
st->npMaterial[BLACK] = compute_non_pawn_material(BLACK);