Revert "encapsulated positionIndex and moved isdraw to board class"
This reverts commit aa0d34eb8e.
This commit is contained in:
1 parent
3275cee01e
commit
ce01c7756b
7 files changed
+41
-35
No files matched your search
@@ -65,7 +65,7 @@ void RunBenchmark() {
|
|||||||
Board board;
|
Board board;
|
||||||
int depth = BENCH_DEPTH;
|
int depth = BENCH_DEPTH;
|
||||||
int ply = 0;
|
int ply = 0;
|
||||||
board.positionIndex = 0;
|
positionIndex = 0;
|
||||||
|
|
||||||
// Clearing
|
// Clearing
|
||||||
TT.Clear();
|
TT.Clear();
|
||||||
@@ -81,5 +81,5 @@ void RunBenchmark() {
|
|||||||
|
|
||||||
std::cout << ctx.nodes << " nodes " << int(ctx.nodes/sw.GetElapsedSec()) << " nps" << std::endl;
|
std::cout << ctx.nodes << " nodes " << int(ctx.nodes/sw.GetElapsedSec()) << " nps" << std::endl;
|
||||||
TT.Clear();
|
TT.Clear();
|
||||||
board.positionIndex = 0;
|
positionIndex = 0;
|
||||||
}
|
}
|
||||||
@@ -28,8 +28,6 @@ void Board::Reset() {
|
|||||||
|
|
||||||
currentMoveIndex = 0;
|
currentMoveIndex = 0;
|
||||||
|
|
||||||
positionIndex = 0;
|
|
||||||
|
|
||||||
hashKey = 0ULL;
|
hashKey = 0ULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,29 +441,4 @@ void Board::ResetAccPair() {
|
|||||||
|
|
||||||
blackPieces.PopBit(square);
|
blackPieces.PopBit(square);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsThreefold(Board& board) {
|
|
||||||
for (int i = 0; i < board.positionIndex; i++) {
|
|
||||||
if (positionHistory[i] == board.hashKey) {
|
|
||||||
// repetition found
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no repetition
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsFifty(Board& board) {
|
|
||||||
return (board.halfMoves >= 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsInsuffMat(Board& board) {
|
|
||||||
return (board.occupied.PopCount() <= 3
|
|
||||||
&& !(board.pieces[Pawn] | board.pieces[Queen] | board.pieces[Rook]));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Board::IsDraw() {
|
|
||||||
return IsFifty(*this) || IsInsuffMat(*this) || IsThreefold(*this);
|
|
||||||
}
|
}
|
||||||
+1
-4
@@ -10,6 +10,7 @@ constexpr int noEPTarget = -1;
|
|||||||
|
|
||||||
constexpr int MAX_MOVES = 218;
|
constexpr int MAX_MOVES = 218;
|
||||||
|
|
||||||
|
inline int positionIndex = 0;
|
||||||
inline U64 positionHistory[1000];
|
inline U64 positionHistory[1000];
|
||||||
|
|
||||||
class Board {
|
class Board {
|
||||||
@@ -39,8 +40,6 @@ public:
|
|||||||
int halfMoves = 0;
|
int halfMoves = 0;
|
||||||
int fullMoves = 1;
|
int fullMoves = 1;
|
||||||
|
|
||||||
int positionIndex = 0;
|
|
||||||
|
|
||||||
U64 hashKey = 0ULL;
|
U64 hashKey = 0ULL;
|
||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
@@ -67,6 +66,4 @@ public:
|
|||||||
bool MakeMove(Move move);
|
bool MakeMove(Move move);
|
||||||
|
|
||||||
bool InPossibleZug();
|
bool InPossibleZug();
|
||||||
|
|
||||||
bool IsDraw();
|
|
||||||
};
|
};
|
||||||
+5
-1
@@ -63,7 +63,8 @@ static void PlayRandMoves(Board &board) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool IsGameOver(Board &board) {
|
static bool IsGameOver(Board &board) {
|
||||||
if (board.IsDraw()) return true;
|
bool isDraw = SEARCH::IsDraw(board);
|
||||||
|
if (isDraw) return true;
|
||||||
|
|
||||||
int moveSeen = 0;
|
int moveSeen = 0;
|
||||||
|
|
||||||
@@ -72,6 +73,7 @@ static bool IsGameOver(Board &board) {
|
|||||||
bool isLegal = copy.MakeMove(board.moveList[i]);
|
bool isLegal = copy.MakeMove(board.moveList[i]);
|
||||||
|
|
||||||
if (!isLegal) continue;
|
if (!isLegal) continue;
|
||||||
|
positionIndex--;
|
||||||
moveSeen++;
|
moveSeen++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +99,8 @@ void PlayGame(std::atomic<int>& positions, U64 targetPositions, std::vector<Game
|
|||||||
Board board;
|
Board board;
|
||||||
|
|
||||||
uint8_t wdl = 1;
|
uint8_t wdl = 1;
|
||||||
|
// Since positionIndex is thread-local, no need to protect it
|
||||||
|
positionIndex = 0;
|
||||||
|
|
||||||
SEARCH::SearchContext ctx;
|
SEARCH::SearchContext ctx;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ static U64 HelperPerft(Board board, int depth) {
|
|||||||
bool isLegal = copy.MakeMove(board.moveList[i]);
|
bool isLegal = copy.MakeMove(board.moveList[i]);
|
||||||
if (!isLegal) continue;
|
if (!isLegal) continue;
|
||||||
nodes += HelperPerft(copy, depth - 1);
|
nodes += HelperPerft(copy, depth - 1);
|
||||||
|
positionIndex--;
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
@@ -29,6 +30,7 @@ void Perft(Board &board, int depth) {
|
|||||||
bool isLegal = copy.MakeMove(board.moveList[i]);
|
bool isLegal = copy.MakeMove(board.moveList[i]);
|
||||||
if (!isLegal) continue;
|
if (!isLegal) continue;
|
||||||
U64 nodeCount = HelperPerft(copy, depth - 1);
|
U64 nodeCount = HelperPerft(copy, depth - 1);
|
||||||
|
positionIndex--;
|
||||||
totalNodes += nodeCount;
|
totalNodes += nodeCount;
|
||||||
board.moveList[i].PrintMove();
|
board.moveList[i].PrintMove();
|
||||||
|
|
||||||
|
|||||||
+28
-1
@@ -92,6 +92,31 @@ void ListScores(Board &board, int ply, SearchContext& ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool IsThreefold(Board &board) {
|
||||||
|
for (int i = 0; i < positionIndex; i++) {
|
||||||
|
if (positionHistory[i] == board.hashKey) {
|
||||||
|
// repetition found
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// no repetition
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsFifty(Board &board) {
|
||||||
|
return (board.halfMoves >= 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsInsuffMat(Board &board) {
|
||||||
|
return (board.occupied.PopCount() <= 3
|
||||||
|
&& !(board.pieces[Pawn] | board.pieces[Queen] | board.pieces[Rook]));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsDraw(Board &board) {
|
||||||
|
return IsFifty(board) || IsInsuffMat(board) || IsThreefold(board);
|
||||||
|
}
|
||||||
|
|
||||||
static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int ply) {
|
static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int ply) {
|
||||||
int reduction = 0;
|
int reduction = 0;
|
||||||
|
|
||||||
@@ -149,6 +174,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply, Searc
|
|||||||
if (!isLegal) continue;
|
if (!isLegal) continue;
|
||||||
ctx.nodes++;
|
ctx.nodes++;
|
||||||
int score = -Quiescence<mode>(copy, -beta, -alpha, ply + 1, ctx).score;
|
int score = -Quiescence<mode>(copy, -beta, -alpha, ply + 1, ctx).score;
|
||||||
|
positionIndex--;
|
||||||
|
|
||||||
if (score >= beta) {
|
if (score >= beta) {
|
||||||
return score;
|
return score;
|
||||||
@@ -191,7 +217,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.pvLine.SetLength(ply);
|
ctx.pvLine.SetLength(ply);
|
||||||
if (ply && (board.IsDraw())) return 0;
|
if (ply && (IsThreefold(board) || IsFifty(board) || IsInsuffMat(board))) return 0;
|
||||||
|
|
||||||
|
|
||||||
// if NOT PV node then we try to hit the TTable
|
// if NOT PV node then we try to hit the TTable
|
||||||
@@ -290,6 +316,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
moveSeen++;
|
moveSeen++;
|
||||||
|
positionIndex--;
|
||||||
|
|
||||||
if (ctx.searchStopped) return 0;
|
if (ctx.searchStopped) return 0;
|
||||||
|
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ void UCILoop(Board &board) {
|
|||||||
// parse UCI "position" command
|
// parse UCI "position" command
|
||||||
if (input.find("position") != std::string::npos) {
|
if (input.find("position") != std::string::npos) {
|
||||||
ParsePosition(board, input);
|
ParsePosition(board, input);
|
||||||
|
positionIndex = 0;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -138,6 +139,8 @@ void UCILoop(Board &board) {
|
|||||||
|
|
||||||
ctx.killerMoves = {};
|
ctx.killerMoves = {};
|
||||||
ctx.history.Clear();
|
ctx.history.Clear();
|
||||||
|
|
||||||
|
positionIndex = 0;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user