Skip to content

Conversation

@BM123499
Copy link
Contributor

@BM123499 BM123499 commented Mar 15, 2021

In all times (except in has_game_cycle()) between_bb() uses or is indifferent if the one of the given square is added. And has shown in here that using prefab results can speed up. So combining both, I reworked between_bb() into ray_bb(), that uses prefab results and includes the last parameter square.

Build Tester: 1.4.7.0
Windows 10 (Version 10.0, Build 0, 64-bit Edition)
Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
SafeMode: No 
Running In VM: No 
HyperThreading Enabled: Yes
CPU Warmup: Yes
Command Line: bench 16 1 5 default perft
Tests per Build: 10
ANOVA: n/a

                Engine# (NPS)                               Speedup     Sp     Conf. 99.5%  S.S.
patch  (102.715.251,9 ) ---> master  (98.242.950,2  ) --->  4,552%  2.105.495,3    Yes       No

Passed STC:
LLR: 2.96 (-2.94,2.94) {-0.25,1.25}
Total: 18736 W: 1746 L: 1607 D: 15383
Ptnml(0-2): 61, 1226, 6644, 1387, 50
https://tests.stockfishchess.org/tests/view/60428c84ddcba5f0627bb6e4

Yellow LTC:
LTC:
LLR: -3.00 (-2.94,2.94) {0.25,1.25}
Total: 39144 W: 1431 L: 1413 D: 36300
Ptnml(0-2): 13, 1176, 17184, 1178, 21
https://tests.stockfishchess.org/tests/view/605128702433018de7a38ca1

No functional change

@snicolet
Copy link
Member

Might be a nice idea.

It would be interesting to have a LTC test also.

@BM123499
Copy link
Contributor Author

@snicolet
Copy link
Member

snicolet commented Mar 17, 2021

The description is still wrong : if the two squares s1 and s2 are not on a same file/rank/diagonal, the comment claims that the function returns 0 but in fact it returns s2.

At this point I have spent one hour reformatting and debugging what should be a trivial patch, so I will continue tomorrow :-)

Current state of pull request: snicolet/Stockfish@d01749b

snicolet pushed a commit to snicolet/Stockfish that referenced this pull request Mar 17, 2021
We remark that in current master, most of our use cases for between_bb() can be
optimized if the second parameter of the function is added to the segment. So we
change the definition of between_bb(s1, s2) such that it excludes s1 but includes s2.

We also use a precomputed array for between_bb() for another small speed gain
(see https://tests.stockfishchess.org/tests/view/604d09f72433018de7a389fb).

Passed STC:
LLR: 2.96 (-2.94,2.94) {-0.25,1.25}
Total: 18736 W: 1746 L: 1607 D: 15383
Ptnml(0-2): 61, 1226, 6644, 1387, 50
https://tests.stockfishchess.org/tests/view/60428c84ddcba5f0627bb6e4

Yellow LTC:
LTC:
LLR: -3.00 (-2.94,2.94) {0.25,1.25}
Total: 39144 W: 1431 L: 1413 D: 36300
Ptnml(0-2): 13, 1176, 17184, 1178, 21
https://tests.stockfishchess.org/tests/view/605128702433018de7a38ca1

Closes official-stockfish/Stockfish#3397

No functional change
@BM123499
Copy link
Contributor Author

BM123499 commented Mar 17, 2021

@snicolet Yes, I forgot about that. My goal is ray_bb(s1, s2) = between(s1, s2) | s2. So s2 will always be included. This is because of horse attack.
Your XX is different because it didn't considered it. So when between(s1, s2) is empty, XX is also empty, but it's different of RayBB.
I believe that is the problem you're facing. Sorry if I was too imprecise.

That why I set RayBB as between_bb() was calculated and then add s2. So s2 will always be in RayBB.

@BM123499
Copy link
Contributor Author

You can do something like.

if (PseudoAttacks[pt][s1] & s2){
    LineBB[s1][s2] = (attacks_bb(pt, s1, 0) & attacks_bb(pt, s2, 0)) | s1 | s2;
    XX[s1][s2] = (attacks_bb(pt, s1, square_bb(s2)) & attacks_bb(pt, s2, square_bb(s1)));
}
XX[s1][s2] |= s2;

Remember that it's due to horse attack, you can do another workaround... :)

@snicolet
Copy link
Member

Remember that it's due to horse attack, you can do another workaround... :)

I don't understand what a horse attack is, you mean a knight move?

And why exactly is it relevant to the problem that between(s1, s2) now contains s2, contrary to what the comment says when s1 and s2 are not aligned?

I think that if you could provide a complete example of how your patch work on a concrete position, that would be illuminating. Thanks :-)

break;
case EVASIONS:
target = between_bb(pos.square<KING>(Us), lsb(pos.checkers())) | pos.checkers();
target = ray_bb(pos.square<KING>(Us), lsb(pos.checkers()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snicolet here, if the checker is a knight, we have to mark it, that's the foundation on adding s2 on RayBB. it's not a line anymore, it has also trigger when the knight is attacking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should also be a "ray" for a knight. That's the only place where it needs to include s2 "no matter what", all other use is indifferent on s2. except on has_game_cycle, so there I did a workaround.

snicolet pushed a commit to snicolet/Stockfish that referenced this pull request Mar 17, 2021
We remark that in current master, most of our use cases for between_bb() can be
optimized if the second parameter of the function is added to the segment. So we
change the definition of between_bb(s1, s2) such that it excludes s1 but includes s2.

We also use a precomputed array for between_bb() for another small speed gain
(see https://tests.stockfishchess.org/tests/view/604d09f72433018de7a389fb).

Passed STC:
LLR: 2.96 (-2.94,2.94) {-0.25,1.25}
Total: 18736 W: 1746 L: 1607 D: 15383
Ptnml(0-2): 61, 1226, 6644, 1387, 50
https://tests.stockfishchess.org/tests/view/60428c84ddcba5f0627bb6e4

Yellow LTC:
LTC:
LLR: -3.00 (-2.94,2.94) {0.25,1.25}
Total: 39144 W: 1431 L: 1413 D: 36300
Ptnml(0-2): 13, 1176, 17184, 1178, 21
https://tests.stockfishchess.org/tests/view/605128702433018de7a38ca1

Closes official-stockfish/Stockfish#3397

No functional change
@snicolet snicolet closed this in 5089061 Mar 17, 2021
@snicolet
Copy link
Member

Merged via 5089061, congrats :-)

@snicolet snicolet added the to be merged Will be merged shortly label Mar 19, 2021
MichaelB7 pushed a commit to MichaelB7/Stockfish that referenced this pull request Apr 13, 2021
We remark that in current master, most of our use cases for between_bb() can be
optimized if the second parameter of the function is added to the segment. So we
change the definition of between_bb(s1, s2) such that it excludes s1 but includes s2.

We also use a precomputed array for between_bb() for another small speed gain
(see https://tests.stockfishchess.org/tests/view/604d09f72433018de7a389fb).

Passed STC:
LLR: 2.96 (-2.94,2.94) {-0.25,1.25}
Total: 18736 W: 1746 L: 1607 D: 15383
Ptnml(0-2): 61, 1226, 6644, 1387, 50
https://tests.stockfishchess.org/tests/view/60428c84ddcba5f0627bb6e4

Yellow LTC:
LTC:
LLR: -3.00 (-2.94,2.94) {0.25,1.25}
Total: 39144 W: 1431 L: 1413 D: 36300
Ptnml(0-2): 13, 1176, 17184, 1178, 21
https://tests.stockfishchess.org/tests/view/605128702433018de7a38ca1

Closes official-stockfish#3397

---------

Verified for correctness by running perft on the following position:

./stockfish
position fen 4rrk1/1p1nq3/p7/2p1P1pp/3P2bp/3Q1Bn1/PPPB4/1K2R1NR w - - 40 21
go perft 6

Nodes searched: 6136386434

--------

No functional change
joergoster pushed a commit to joergoster/Stockfish-old that referenced this pull request May 7, 2021
We remark that in current master, most of our use cases for between_bb() can be
optimized if the second parameter of the function is added to the segment. So we
change the definition of between_bb(s1, s2) such that it excludes s1 but includes s2.

We also use a precomputed array for between_bb() for another small speed gain
(see https://tests.stockfishchess.org/tests/view/604d09f72433018de7a389fb).

Passed STC:
LLR: 2.96 (-2.94,2.94) {-0.25,1.25}
Total: 18736 W: 1746 L: 1607 D: 15383
Ptnml(0-2): 61, 1226, 6644, 1387, 50
https://tests.stockfishchess.org/tests/view/60428c84ddcba5f0627bb6e4

Yellow LTC:
LTC:
LLR: -3.00 (-2.94,2.94) {0.25,1.25}
Total: 39144 W: 1431 L: 1413 D: 36300
Ptnml(0-2): 13, 1176, 17184, 1178, 21
https://tests.stockfishchess.org/tests/view/605128702433018de7a38ca1

Closes official-stockfish/Stockfish#3397

---------

Verified for correctness by running perft on the following position:

./stockfish
position fen 4rrk1/1p1nq3/p7/2p1P1pp/3P2bp/3Q1Bn1/PPPB4/1K2R1NR w - - 40 21
go perft 6

Nodes searched: 6136386434

--------

No functional change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

to be merged Will be merged shortly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants