Skip to content

Conversation

@vondele
Copy link
Member

@vondele vondele commented Aug 3, 2025

for positions such as:

position fen rr6/2q2p1k/2P1b1pp/bB2P1n1/R2B2PN/p4P1P/P1Q4K/1R6 b - - 2 38 moves f7f5 position fen 8/p2r1pK1/6p1/1kp1P1P1/2p5/2P5/8/4R3 b - - 0 43 moves f7f5 position fen 4k3/4p3/2b3b1/3P1P2/4K3/8/8/8 b - - moves e7e5

ep is not possible for various reasons. Do not set the ep square and the do not change the zobrist key, as if ep were possible.

This fixes 3-fold detection, which could in rare cases be observed as a warning generated by fastchess for PVs that continued beyond an actual 3-fold.

fixes #6138

failed STC
LLR: -2.93 (-2.94,2.94) <-1.75,0.25>
Total: 130688 W: 33986 L: 34362 D: 62340
Ptnml(0-2): 414, 13292, 38302, 12928, 408
https://tests.stockfishchess.org/tests/view/688bcb35502b34dd5e7111c9

passed LTC
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 99018 W: 25402 L: 25273 D: 48343
Ptnml(0-2): 54, 9097, 31089, 9204, 65
https://tests.stockfishchess.org/tests/view/688c613c502b34dd5e7112d3

originally written and tested by rn5f107s2, with small buglet as https://tests.stockfishchess.org/tests/view/685af90843ce022d15794400

Bench: 2958792

@joergoster
Copy link
Contributor

I don't think this is really necessary. We might even simply flag the ep square after every double pawn push for simplicity. Legality of en-passant moves is taken care of during move-generation and before actually doing the move via pseudo_legal() and legal() methods.

Whether or not we are setting the ep flag should have no impact on the repetition detection, however. If we go forth and then back in the tree, we always restore the previous state as it was. No matter what. Or am i missing something?

@vondele
Copy link
Member Author

vondele commented Aug 3, 2025

Compare the scores for the move a2a1 for this test:

position fen 4k3/1b2p2b/8/3P1P2/4K3/8/8/r7 b - - 0 1 moves e7e5 e4e3 a1a2 e3e4 a2a1 e4f3 a1a2 f3e4
setoption name multiPV value 100
go depth 10
ucinewgame

patch:
info depth 10 seldepth 2 multipv 27 score cp 0 nodes 111631 nps 1449753 hashfull 26 tbhits 0 time 77 pv a2a1
master:
info depth 10 seldepth 23 multipv 17 score cp 588 nodes 139288 nps 1601011 hashfull 37 tbhits 0 time 87 pv a2a1 e4e5 a1a5 f5f6 a5d5 e5f4 d5f5 f4g3 f5f6 g3g4 h7e4 g4g5 f6f1 g5g4 e4h7 g4g5 f1a1 g5f4 a1a6 f4e5 a6a5 e5f4

@joergoster
Copy link
Contributor

joergoster commented Aug 3, 2025

Ok, I see. A corner case of a corner case.

What about passing a flag from Engine::set_position() while digesting the moves to do the more thorough ep check and otherwise not?

@vondele
Copy link
Member Author

vondele commented Aug 3, 2025

the original issue (linked above) is from game play, with PVs going beyond the 3-folds.

@joergoster
Copy link
Contributor

Yes, and the protocol requires that the UI must send the whole game history. I don't see a problem with my proposal.

@vondele
Copy link
Member Author

vondele commented Aug 3, 2025

the problem is there in search...

@robertnurnberg
Copy link
Contributor

Btw, as part of this pr or a follow up we could add a correct PV check to the ci.

for positions such as:

position fen rr6/2q2p1k/2P1b1pp/bB2P1n1/R2B2PN/p4P1P/P1Q4K/1R6 b - - 2 38 moves f7f5
position fen 8/p2r1pK1/6p1/1kp1P1P1/2p5/2P5/8/4R3 b - - 0 43 moves f7f5
position fen 4k3/4p3/2b3b1/3P1P2/4K3/8/8/8 b - - moves e7e5

ep is not possible for various reasons. Do not set the ep square and the do not change the zobrist key, as if ep were possible.

This fixes 3-fold detection, which could in rare cases be observed as a warning generated by fastchess for PVs that continued beyond an actual 3-fold.

fixes official-stockfish#6138

failed STC
LLR: -2.93 (-2.94,2.94) <-1.75,0.25>
Total: 130688 W: 33986 L: 34362 D: 62340
Ptnml(0-2): 414, 13292, 38302, 12928, 408
https://tests.stockfishchess.org/tests/view/688bcb35502b34dd5e7111c9

passed LTC
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 99018 W: 25402 L: 25273 D: 48343
Ptnml(0-2): 54, 9097, 31089, 9204, 65
https://tests.stockfishchess.org/tests/view/688c613c502b34dd5e7112d3

originally written and tested by rn5f107s2, with small buglet as https://tests.stockfishchess.org/tests/view/685af90843ce022d15794400

Bench: 2958792

Co-authored-by: Joost VandeVondele <Joost.VandeVondele@gmail.com>
@vondele vondele added the to be merged Will be merged shortly label Aug 4, 2025
vondele added a commit that referenced this pull request Aug 4, 2025
for positions such as:

position fen rr6/2q2p1k/2P1b1pp/bB2P1n1/R2B2PN/p4P1P/P1Q4K/1R6 b - - 2 38 moves f7f5
position fen 8/p2r1pK1/6p1/1kp1P1P1/2p5/2P5/8/4R3 b - - 0 43 moves f7f5
position fen 4k3/4p3/2b3b1/3P1P2/4K3/8/8/8 b - - moves e7e5

ep is not possible for various reasons. Do not set the ep square and the do not change the zobrist key, as if ep were possible.

This fixes 3-fold detection, which could in rare cases be observed as a warning generated by fastchess for PVs that continued beyond an actual 3-fold.

Also fixes wrong evals for certain moves e.g. a2a1 for
position fen 4k3/1b2p2b/8/3P1P2/4K3/8/8/r7 b - - 0 1 moves e7e5 e4e3 a1a2 e3e4 a2a1 e4f3 a1a2 f3e4

fixes #6138

originally written and tested by rn5f107s2, with small buglet as
https://tests.stockfishchess.org/tests/view/685af90843ce022d15794400

failed STC
LLR: -2.93 (-2.94,2.94) <-1.75,0.25>
Total: 130688 W: 33986 L: 34362 D: 62340
Ptnml(0-2): 414, 13292, 38302, 12928, 408
https://tests.stockfishchess.org/tests/view/688bcb35502b34dd5e7111c9

passed LTC
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 99018 W: 25402 L: 25273 D: 48343
Ptnml(0-2): 54, 9097, 31089, 9204, 65
https://tests.stockfishchess.org/tests/view/688c613c502b34dd5e7112d3

#6211

Bench: 2946135

Co-authored-by: Joost VandeVondele <Joost.VandeVondele@gmail.com>
@vondele
Copy link
Member Author

vondele commented Aug 4, 2025

merged with 9417552

@vondele vondele closed this Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug to be merged Will be merged shortly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PV continues after threefold repetition

4 participants