{
Move moves[1] = {MOVE_NONE};
int dummy[2] = {0, 0};
- Position pos(*it);
+ Position pos(*it, 0);
cerr << "\nBench position: " << cnt << '/' << positions.size() << endl << endl;
if (limitType == "perft")
{
s << char(upcase? toupper(keyCode[i]) : tolower(keyCode[i]));
}
s << 8 - keyCode.length() << "/8/8/8/8/8/8/8 w -";
- return Position(s.str()).get_material_key();
+ return Position(s.str(), 0).get_material_key();
}
const string EndgameFunctions::swapColors(const string& keyCode) {
}
-/// 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;
}
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;
}
assert(pos.is_ok());
clear();
+ threadID = pos.thread();
// Board
for (Square s = SQ_A1; s <= SQ_H8; s++)
friend class MaterialInfo;
friend class EndgameFunctions;
+ Position(); // No default or copy c'tor allowed
+ Position(const Position& pos);
+
public:
enum GamePhase {
MidGame,
};
// Constructors
- Position();
- explicit Position(const Position& pos);
- explicit Position(const std::string& fen);
+ explicit Position(int threadID);
+ Position(const Position& pos, int threadID);
+ Position(const std::string& fen, int threadID);
// Text input/output
void from_fen(const std::string& fen);
bool has_pawn_on_7th(Color c) const;
// Game ply information
+ int thread() const;
int ply() const;
void reset_ply();
int castleRightsMask[64];
StateInfo startState;
File initialKFile, initialKRFile, initialQRFile;
+ int threadID;
StateInfo* st;
// Static variables
return st->capture;
}
+inline int Position::thread() const {
+ return threadID;
+}
+
inline int Position::ply() const {
return st->ply;
}
string moveStr;
size_t length = 0;
size_t maxLength = 80 - startColumn;
- Position p(pos);
+ Position p(pos, pos.thread());
for (int i = 0; line[i] != MOVE_NONE; i++)
{
Value id_loop(const Position& pos, Move searchMoves[]) {
- Position p(pos);
+ Position p(pos, pos.thread());
SearchStack ss[PLY_MAX_PLUS_2];
Move EasyMove = MOVE_NONE;
Value value, alpha = -VALUE_INFINITE, beta = VALUE_INFINITE;
int moveCount;
value = -VALUE_INFINITE;
- Position pos(*sp->pos);
+ Position pos(*sp->pos, threadID);
CheckInfo ci(pos);
int ply = pos.ply();
SearchStack* ss = sp->sstack[threadID] + 1;
void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
StateInfo st;
- Position p(pos);
+ Position p(pos, pos.thread());
for (int i = 0; pv[i] != MOVE_NONE; i++)
{
const TTEntry* tte;
StateInfo st;
- Position p(pos);
+ Position p(pos, pos.thread());
int ply = 0;
// Update position to the end of current PV
// The root position. This is set up when the user (or in practice, the GUI)
// sends the "position" UCI command. The root position is sent to the think()
// function when the program receives the "go" command.
- Position RootPosition;
+ Position RootPosition(0);
// Local functions
bool handle_command(const string& command);
RootPosition.print();
else if (token == "flip")
{
- Position p(RootPosition);
+ Position p(RootPosition, RootPosition.thread());
RootPosition.flipped_copy(p);
}
else if (token == "eval")
string token;
int depth, tm, n;
- Position pos(RootPosition);
+ Position pos(RootPosition, RootPosition.thread());
if (!(uip >> depth))
return;