Skip to content

Commit

Permalink
Bench: 23851500
Browse files Browse the repository at this point in the history
  • Loading branch information
TerjeKir committed Dec 22, 2024
1 parent 16ce294 commit e4e66ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,8 @@ static void AspirationWindow(Thread *thread, Stack *ss) {

int score = AlphaBeta(thread, ss, alpha, beta, depth, false);

SortRootMoves(thread, multiPV);

// Give an update when failing high/low in longer searches
if ( mainThread
&& Limits.multiPV == 1
Expand Down Expand Up @@ -732,7 +734,7 @@ static void *IterativeDeepening(void *voidThread) {
AspirationWindow(thread, ss);

// Sort root moves so they are printed in the right order in multi-pv mode
SortRootMoves(thread, multiPV);
SortRootMoves(thread, 0);

// Only the main thread concerns itself with the rest
if (!mainThread) continue;
Expand Down
22 changes: 8 additions & 14 deletions src/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,14 @@ void InitThreads(int count) {
Threads[i].count = count;
}

// Sorts all rootmoves searched by multiPV
void SortRootMoves(Thread *thread, int multiPV) {
for (int i = 0; i < multiPV; ++i) {

int bestIdx = i;
int bestScore = thread->rootMoves[i].score;

for (int k = i + 1; k < thread->rootMoveCount; ++k)
if (thread->rootMoves[k].score > bestScore)
bestScore = thread->rootMoves[bestIdx = k].score;

RootMove best = thread->rootMoves[bestIdx];
thread->rootMoves[bestIdx] = thread->rootMoves[i];
thread->rootMoves[i] = best;
// Sorts all rootmoves beginning from the given index
void SortRootMoves(Thread *thread, int begin) {
for (int i = begin + 1; i < thread->rootMoveCount; ++i) {
RootMove temp = thread->rootMoves[i];
int j = i - 1;
while (j >= 0 && thread->rootMoves[j].score < temp.score)
thread->rootMoves[j+1] = thread->rootMoves[j], --j;
thread->rootMoves[j+1] = temp;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extern Thread *Threads;


void InitThreads(int threadCount);
void SortRootMoves(Thread *thread, int multiPV);
void SortRootMoves(Thread *thread, int begin);
uint64_t TotalNodes();
uint64_t TotalTBHits();
void PrepareSearch(Position *pos, Move searchmoves[]);
Expand Down

0 comments on commit e4e66ce

Please sign in to comment.