Save threadID info in Position

This is the best place because when we split we do a
copy of the position and also threadID, once set in a
given position, never changes anymore.

Forbid use of Position's default and copy c'tor to avoid
nasty bugs in case a position is created without explicitly
setting the threadID.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2010-06-02 20:13:51 +01:00
parent f148a8f6cc
commit 2f6927ac08
8 changed files with 32 additions and 22 deletions

View File

@@ -74,23 +74,23 @@ CheckInfo::CheckInfo(const Position& pos) {
}
/// Position c'tors. Here we always create a slower but safer copy of
/// the original position or the FEN string, we want the new born Position
/// object do not depend on any external data. Instead if we know what we
/// are doing and we need speed we can create a position with default
/// c'tor Position() and then use just fast_copy().
/// Position c'tors. Here we always create a copy of the original position
/// or the FEN string, we want the new born Position object do not depend
/// on any external data so we detach state pointer from the source one.
Position::Position() {}
Position::Position(int th) : threadID(th) {}
Position::Position(const Position& pos) {
Position::Position(const Position& pos, int th) {
memcpy(this, &pos, sizeof(Position));
detach(); // Always detach() in copy c'tor to avoid surprises
threadID = th;
}
Position::Position(const string& fen) {
Position::Position(const string& fen, int th) {
from_fen(fen);
threadID = th;
}
@@ -340,7 +340,7 @@ void Position::print(Move m) const {
std::cout << std::endl;
if (m != MOVE_NONE)
{
Position p(*this);
Position p(*this, thread());
string col = (color_of_piece_on(move_from(m)) == BLACK ? ".." : "");
std::cout << "Move is: " << col << move_to_san(p, m) << std::endl;
}
@@ -1785,6 +1785,7 @@ void Position::flipped_copy(const Position& pos) {
assert(pos.is_ok());
clear();
threadID = pos.thread();
// Board
for (Square s = SQ_A1; s <= SQ_H8; s++)