Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor get_best_thread #5001

Conversation

peregrineshahin
Copy link
Contributor

Refactors get_best_thread function logic for readability

Passed non-reg STC:
https://tests.stockfishchess.org/tests/view/65a91c6679aa8af82b975500
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 186000 W: 46379 L: 46325 D: 93296
Ptnml(0-2): 269, 21374, 49634, 21480, 243

no functional change

Refactors get_best_thread function logic for readability

Passed non-reg STC:
https://tests.stockfishchess.org/tests/view/65a91c6679aa8af82b975500
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 186000 W: 46379 L: 46325 D: 93296
Ptnml(0-2): 269, 21374, 49634, 21480, 243

no functional change
@Disservin Disservin added simplification A simplification patch no-functional-change to be merged Will be merged shortly labels Jan 21, 2024
@Disservin Disservin closed this in ad9fcbc Jan 21, 2024
windfishballad pushed a commit to windfishballad/Stockfish that referenced this pull request Jan 23, 2024
Make get_best_thread function easier to understand.

Passed non-reg SMP STC:
https://tests.stockfishchess.org/tests/view/65a91c6679aa8af82b975500
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 186000 W: 46379 L: 46325 D: 93296
Ptnml(0-2): 269, 21374, 49634, 21480, 243

closes official-stockfish#5001

No functional change
@mstembera
Copy link
Contributor

Sorry for the late review but I believe line 264 if (newThreadInProvenLoss && newThreadScore < bestThreadScore) didn't get ported correctly. To preserve the original logic I think it should be if (newThreadScore != -VALUE_INFINITE && newThreadScore < bestThreadScore). Do you agree?

@peregrineshahin
Copy link
Contributor Author

Sorry for the late review but I believe line 264 if (newThreadInProvenLoss && newThreadScore < bestThreadScore) didn't get ported correctly. To preserve the original logic I think it should be if (newThreadScore != -VALUE_INFINITE && newThreadScore < bestThreadScore). Do you agree?

It's a pre-calculated boolean so it should be exactly the same, since bestThread is in proven loss the newThread can't be < and not negative infinity unless it's also in proven loss.

@mstembera
Copy link
Contributor

I c ok that makes sense. What I now realize is that I don't understand why we want to select the new thread when newThreadScore < bestThreadScore ? We should want the opposite to maximize the score. Turns out this logic got reversed in #4990 which I believe is a bug. We want to stave off the mate the longest not shortest.

@peregrineshahin
Copy link
Contributor Author

It's the other way around, the bug was that we were staving off the mated in scores.. currently no non proven mated score can be reported by any thread which wasn't the case before. This means that staving off mated in scores was neccessary because threads will stuck with a non proven mated in scores. If we use the previous iteration to prove mated in scores then a lower score has the correct best move anyways.

@mstembera
Copy link
Contributor

It's the other way around, the bug was that we were staving off the mated in scores..

Hmm It seems that we should be staving off mate. Doesn't a more negative score mean the mate is closer so therefore we want a higher(less negative) score? Why was that a bug?

currently no non proven mated score can be reported by any thread which wasn't the case before. This means that staving off mated in scores was neccessary because threads will stuck with a non proven mated in scores. If we use the previous iteration to prove mated in scores then a lower score has the correct best move anyways.

What does it mean for a mate to be proven and why would it change the fact that when we are defending we want the longest as opposed to the shortest mate? That should still correspond to the least negative score as it did before.

Am I'm missing something fundamental about how this works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-functional-change simplification A simplification patch to be merged Will be merged shortly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants