mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
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:
parent
f148a8f6cc
commit
2f6927ac08
8 changed files with 32 additions and 22 deletions
|
@ -151,7 +151,7 @@ void benchmark(const string& commandLine) {
|
|||
{
|
||||
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")
|
||||
{
|
||||
|
|
|
@ -403,7 +403,7 @@ Key EndgameFunctions::buildKey(const string& keyCode) {
|
|||
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) {
|
||||
|
|
|
@ -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++)
|
||||
|
|
|
@ -139,6 +139,9 @@ class Position {
|
|||
friend class MaterialInfo;
|
||||
friend class EndgameFunctions;
|
||||
|
||||
Position(); // No default or copy c'tor allowed
|
||||
Position(const Position& pos);
|
||||
|
||||
public:
|
||||
enum GamePhase {
|
||||
MidGame,
|
||||
|
@ -146,9 +149,9 @@ public:
|
|||
};
|
||||
|
||||
// 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);
|
||||
|
@ -272,6 +275,7 @@ public:
|
|||
bool has_pawn_on_7th(Color c) const;
|
||||
|
||||
// Game ply information
|
||||
int thread() const;
|
||||
int ply() const;
|
||||
void reset_ply();
|
||||
|
||||
|
@ -328,6 +332,7 @@ private:
|
|||
int castleRightsMask[64];
|
||||
StateInfo startState;
|
||||
File initialKFile, initialKRFile, initialQRFile;
|
||||
int threadID;
|
||||
StateInfo* st;
|
||||
|
||||
// Static variables
|
||||
|
@ -557,6 +562,10 @@ inline PieceType Position::captured_piece() const {
|
|||
return st->capture;
|
||||
}
|
||||
|
||||
inline int Position::thread() const {
|
||||
return threadID;
|
||||
}
|
||||
|
||||
inline int Position::ply() const {
|
||||
return st->ply;
|
||||
}
|
||||
|
|
|
@ -299,7 +299,7 @@ const string line_to_san(const Position& pos, Move line[], int startColumn, bool
|
|||
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++)
|
||||
{
|
||||
|
|
|
@ -603,7 +603,7 @@ namespace {
|
|||
|
||||
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;
|
||||
|
@ -1662,7 +1662,7 @@ namespace {
|
|||
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;
|
||||
|
|
|
@ -205,7 +205,7 @@ void TranspositionTable::new_search() {
|
|||
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++)
|
||||
{
|
||||
|
@ -227,7 +227,7 @@ void TranspositionTable::extract_pv(const Position& pos, Move pv[], const int PL
|
|||
|
||||
const TTEntry* tte;
|
||||
StateInfo st;
|
||||
Position p(pos);
|
||||
Position p(pos, pos.thread());
|
||||
int ply = 0;
|
||||
|
||||
// Update position to the end of current PV
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace {
|
|||
// 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);
|
||||
|
@ -143,7 +143,7 @@ namespace {
|
|||
RootPosition.print();
|
||||
else if (token == "flip")
|
||||
{
|
||||
Position p(RootPosition);
|
||||
Position p(RootPosition, RootPosition.thread());
|
||||
RootPosition.flipped_copy(p);
|
||||
}
|
||||
else if (token == "eval")
|
||||
|
@ -308,7 +308,7 @@ namespace {
|
|||
|
||||
string token;
|
||||
int depth, tm, n;
|
||||
Position pos(RootPosition);
|
||||
Position pos(RootPosition, RootPosition.thread());
|
||||
|
||||
if (!(uip >> depth))
|
||||
return;
|
||||
|
|
Loading…
Add table
Reference in a new issue