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

About KomodoChess #322

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

About KomodoChess #322

wants to merge 11 commits into from

Conversation

Frosty54
Copy link

@Frosty54 Frosty54 commented Mar 2, 2023

Sorry if I write there.
@KomodoChess why u need Stockfish when you have your own engine?

Rewrite TB probing code to ovecome the main
traditional TB artifacts:

1. Don't hide forever mate line in a winning position

2. Don't stick to odd sacrifices to simplify in a TB position

This version mostly fixes the above 2 issues. In particular
it keeps searching even in a winning position so that sooner
or later a mate is found and reproted to user. Moreover, although
in rare cases odd sacrifice moves could still be selected for a
temporary and transitory time, keeping searching the engine always
moves off form them.

In both cases these phenomenons are greatly reduced compared to
current version.

This version is stronger than master of a large margin!

Tested with 5-men tables at 10+0.01

Stockfish NTB vs Stockfish master:  2143 - 1736 - 6121 [0.520]
Elo difference: 14.15  +/- 4.23
10000 of 10000 games finished.

Bench: 5417521
We use WDL50 tables so the condition is needed
to ensure the probed WDL score is always correct.

In particular without this condition we could
probe as a win a position that is indeed a draw
because we are already near the 50 rule threshold.
The condition:

VALUE_DRAW + 2 * wdl * drawScore

can be selected only if not using TB::UseRule50 when
wdl is 0 so that it is equivalent to:

VALUE_DRAW + 2 * wdl * drawScore   -->  VALUE_DRAW + 2 * wdl

Or if TB::UseRule50 is set when drawScore == 1 so that:

VALUE_DRAW + 2 * wdl * drawScore   -->  VALUE_DRAW + 2 * wdl
Correctly take in account these rare cases.
In this case alpha != beta - 1 and we should
take care of that.
Win or loss scores are reliable only if we are probing after a rule50 reset move.
Instead, draw scores are reliable in any case. So take in account this to relax
the condition on rule50.

This is very sensible because with this patch SF will probe TB even if root
position is a pawnless endgame and will play without mistakes without relying on
DTZ.

With this patch SF plays perfectly, even with short TC, this tricky endgame:

4q3/7R/8/4r2Q/8/4k3/8/2K5 w - - 0 1
If rootPos is in TB and we can't rely on WDL score, then we have
to use the big artillery to differentiate between a win/loss and
a cursed/blessed draw. This is critical because search alone
can detect it only at ply 101...too late.

To avoid to probe DTZ at eevry iteration use a small cache. This
is not needed in current master becuase moves are filtered before
searching.
When we increase one ply, we correspondingly decrease
remaining depth, so if no LMR exists then simply:

RootDepth = ss->ply + depth

In case of (recursive) LMR we have instead:

RootDepth = ss->ply + depth + LMR

From here:

depth = RootDepth - ss->ply - LMR

and repalcing it in the farFromRoot condition we have:

ss->ply - (RootDepth - ss->ply - LMR)/2 >= 0

Hence:

3 * ss->ply >= (RootDepth - LMR)

So a node it is far from root if ply >= (RootDepth - LMR)/3,
and at a given ply, nodes with high LMR are considered
farther from root than nodes near the PV line.

No functional change.

Conflicts:
	src/search.cpp
With this fix, starting from

position fen 8/8/5N2/5K2/3p3k/3N4/8/8 b - - 71 36

best move h4g3 is correctly detected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants