No globals #50
No files matched your search
@@ -71,8 +71,6 @@ void RunBenchmark() {
|
|||||||
// Clearing
|
// Clearing
|
||||||
TT.Clear();
|
TT.Clear();
|
||||||
std::memset(killerMoves, 0, sizeof(killerMoves));
|
std::memset(killerMoves, 0, sizeof(killerMoves));
|
||||||
|
|
||||||
history.Clear();
|
|
||||||
|
|
||||||
SearchContext ctx;
|
SearchContext ctx;
|
||||||
|
|
||||||
@@ -86,6 +84,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();
|
||||||
std::memset(killerMoves, 0, sizeof(killerMoves));
|
std::memset(killerMoves, 0, sizeof(killerMoves));
|
||||||
history.Clear();
|
|
||||||
positionIndex = 0;
|
positionIndex = 0;
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,6 @@ void PlayGame(std::atomic<int>& positions, U64 targetPositions, std::vector<Game
|
|||||||
positionIndex = 0;
|
positionIndex = 0;
|
||||||
|
|
||||||
std::memset(SEARCH::killerMoves, 0, sizeof(SEARCH::killerMoves));
|
std::memset(SEARCH::killerMoves, 0, sizeof(SEARCH::killerMoves));
|
||||||
SEARCH::history.Clear();
|
|
||||||
|
|
||||||
SEARCH::SearchContext ctx;
|
SEARCH::SearchContext ctx;
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -29,7 +29,7 @@ void InitLMRTable() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ScoreMove(Board &board, Move &move, int ply) {
|
static int ScoreMove(Board &board, Move &move, int ply, SearchContext& ctx) {
|
||||||
TTEntry *current = TT.GetRawEntry(board.hashKey);
|
TTEntry *current = TT.GetRawEntry(board.hashKey);
|
||||||
if (current->bestMove == move) {
|
if (current->bestMove == move) {
|
||||||
return 50000;
|
return 50000;
|
||||||
@@ -51,20 +51,20 @@ static int ScoreMove(Board &board, Move &move, int ply) {
|
|||||||
return 18000;
|
return 18000;
|
||||||
} else {
|
} else {
|
||||||
// Max 16384
|
// Max 16384
|
||||||
return history[board.sideToMove][move.MoveFrom()][move.MoveTo()];
|
return ctx.history[board.sideToMove][move.MoveFrom()][move.MoveTo()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SortMoves(Board &board, int ply) {
|
static void SortMoves(Board &board, int ply, SearchContext& ctx) {
|
||||||
std::array<int, MAX_MOVES> scores;
|
std::array<int, MAX_MOVES> scores;
|
||||||
std::array<int, MAX_MOVES> indices;
|
std::array<int, MAX_MOVES> indices;
|
||||||
|
|
||||||
// Initialize scores and indices
|
// Initialize scores and indices
|
||||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||||
scores[i] = ScoreMove(board, board.moveList[i], ply);
|
scores[i] = ScoreMove(board, board.moveList[i], ply, ctx);
|
||||||
indices[i] = i;
|
indices[i] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,14 +86,14 @@ static void SortMoves(Board &board, int ply) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListScores(Board &board, int ply) {
|
void ListScores(Board &board, int ply, SearchContext& ctx) {
|
||||||
SortMoves(board, ply);
|
SortMoves(board, ply, ctx);
|
||||||
|
|
||||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||||
Move currentMove = board.moveList[i];
|
Move currentMove = board.moveList[i];
|
||||||
|
|
||||||
std::cout << squareCoords[currentMove.MoveFrom()] << squareCoords[currentMove.MoveTo()];
|
std::cout << squareCoords[currentMove.MoveFrom()] << squareCoords[currentMove.MoveTo()];
|
||||||
std::cout << ": " << ScoreMove(board, currentMove, ply) << '\n';
|
std::cout << ": " << ScoreMove(board, currentMove, ply, ctx) << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply, Searc
|
|||||||
|
|
||||||
MOVEGEN::GenerateMoves<Noisy>(board);
|
MOVEGEN::GenerateMoves<Noisy>(board);
|
||||||
|
|
||||||
SortMoves(board, ply);
|
SortMoves(board, ply, ctx);
|
||||||
|
|
||||||
SearchResults results;
|
SearchResults results;
|
||||||
|
|
||||||
@@ -265,7 +265,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
|
|||||||
|
|
||||||
MOVEGEN::GenerateMoves<All>(board);
|
MOVEGEN::GenerateMoves<All>(board);
|
||||||
|
|
||||||
SortMoves(board, ply);
|
SortMoves(board, ply, ctx);
|
||||||
|
|
||||||
int score = -inf;
|
int score = -inf;
|
||||||
int nodeType = AllNode;
|
int nodeType = AllNode;
|
||||||
@@ -338,10 +338,10 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
|
|||||||
|
|
||||||
int bonus = depth * depth;
|
int bonus = depth * depth;
|
||||||
|
|
||||||
history.Update(board.sideToMove, currMove, bonus);
|
ctx.history.Update(board.sideToMove, currMove, bonus);
|
||||||
|
|
||||||
for (int moveIndex = 0; moveIndex < seenQuietsCount - 1; moveIndex++) {
|
for (int moveIndex = 0; moveIndex < seenQuietsCount - 1; moveIndex++) {
|
||||||
history.Update(board.sideToMove, seenQuiets[moveIndex], -bonus);
|
ctx.history.Update(board.sideToMove, seenQuiets[moveIndex], -bonus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -72,8 +72,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline History history;
|
|
||||||
|
|
||||||
class PVLine {
|
class PVLine {
|
||||||
private:
|
private:
|
||||||
int length[MAX_PLY] = {};
|
int length[MAX_PLY] = {};
|
||||||
@@ -112,10 +110,13 @@ public:
|
|||||||
U64 nodesToGo = 0;
|
U64 nodesToGo = 0;
|
||||||
|
|
||||||
bool doingNullMove = false;
|
bool doingNullMove = false;
|
||||||
|
|
||||||
PVLine pvLine;
|
PVLine pvLine;
|
||||||
|
History history;
|
||||||
|
|
||||||
SearchContext(){
|
SearchContext(){
|
||||||
pvLine.Clear();
|
pvLine.Clear();
|
||||||
|
history.Clear();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -137,5 +138,5 @@ constexpr int moveScoreTable[6][6] = {
|
|||||||
100, 200, 300, 400, 500, 600
|
100, 200, 300, 400, 500, 600
|
||||||
};
|
};
|
||||||
|
|
||||||
void ListScores(Board &board);
|
void ListScores(Board &board, SearchContext& ctx);
|
||||||
}
|
}
|
||||||
+1
-1
@@ -138,7 +138,7 @@ void UCILoop(Board &board) {
|
|||||||
TT.Clear();
|
TT.Clear();
|
||||||
std::memset(SEARCH::killerMoves, 0, sizeof(SEARCH::killerMoves));
|
std::memset(SEARCH::killerMoves, 0, sizeof(SEARCH::killerMoves));
|
||||||
|
|
||||||
SEARCH::history.Clear();
|
ctx.history.Clear();
|
||||||
positionIndex = 0;
|
positionIndex = 0;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in new issue
Block a user