ddugovic / Stockfish

Retired multi-variant fork of popular UCI chess engine; please use Fairy-Stockfish instead
https://github.com/ianfab/Fairy-Stockfish
GNU General Public License v3.0
132 stars 44 forks source link

Indirect king attacks in Atomic chess #43

Closed ianfab closed 3 years ago

ianfab commented 8 years ago

So far indirect king attacks are neither prevented from being pruned nor extended like checks are. Therefore the engine often underestimates indirect king attacks and does only correctly evaluate its consequences at high depths. A simple example is the position after 1. Nf3 f6 2. Nc3: 2... Nh6 is a good move, but because of the line 3. Nd5 e6 4. Nxc7, 2...Nh6 is pruned. It takes a lot of time for the engine to see that 4... Ng4 is winning. This should not happen. I think indirect king attacks could be adequatly taken account of by the following steps:

ddugovic commented 8 years ago

This all sounds logical and difficult to identify because the king (or adjacent pieces) can move.

ianfab commented 8 years ago

I was very confident that this would give a big elo gain, but when I implemented the first two bullet points it was a regression. Probably this is because there are many harmless indirect king attacks, e.g. by the queen targeting pawns on the 7th rank when the pawns can simply advance. So it could make sense to only extend them if the attacked piece cannot move, which would make it more similar to checks (you can only move the king, block or capture).

ddugovic commented 8 years ago

But requiring the attacked piece (pawn) to be fixed would fail to address this point:

It takes a lot of time for the engine to see that 4... Ng4 is winning. This should not happen.

ianfab commented 8 years ago

The f2 pawn is blocked by the knight on f3. However, even if it were not black would still be winning because of ...Nf2 and the trapped queen on d1. In the latter case only one of the two indirect king attacks would match my criterion, but it might still help to find the variation. Either way, since I currently do not have a better idea I will probably try it.

ianfab commented 7 years ago

In case someone has an idea on this, the patch in this test contains some useful code to test ideas on indirect king attacks.

ianfab commented 7 years ago

I found that in a recent game on lichess level 8 blundered, because it overlooked a dangerous indirect king attack leading to a forced mate. It seems like an interesting test position, since it also involves two times attacking and capturing the pinned piece to discover checks. I so far did not manage to find a patch that reduces the time until it finds mate (not even testing for Elo if it does not even perform well in the position where it is supposed to).

Output of current master in the position after the blunder:

setoption name UCI_Variant value atomic
position fen 2k2r2/p3p2p/5r2/1p1p1n2/8/3PP3/PPPB2PP/R3KR2 w Q - 5 17 moves e1c1
go depth 20
info string variant atomic startpos rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
info depth 1 seldepth 1 multipv 1 score cp -87 nodes 34 nps 17000 tbhits 0 time 2 pv f5e3
info depth 2 seldepth 2 multipv 1 score cp -84 nodes 132 nps 66000 tbhits 0 time 2 pv f5e3 f1f6
info depth 3 seldepth 3 multipv 1 score cp -100 nodes 221 nps 110500 tbhits 0 time 2 pv f5e3 f1f6 b5b4
info depth 4 seldepth 4 multipv 1 score cp -124 nodes 514 nps 171333 tbhits 0 time 3 pv f5e3 f1f5 f6f5 d1e1
info depth 5 seldepth 5 multipv 1 score cp -93 nodes 814 nps 203500 tbhits 0 time 4 pv f5e3 f1f5 f6f5 d1e1 f8f2
info depth 6 seldepth 6 multipv 1 score cp -47 nodes 2932 nps 366500 tbhits 0 time 8 pv f5e3 f1f5 e7e5 d1f1 e5e4 c1b1
info depth 7 seldepth 7 multipv 1 score cp -23 nodes 6097 nps 435500 tbhits 0 time 14 pv f5e3 f1f5 e7e5 d1f1 e5e4 c1b1 c8b7
info depth 8 seldepth 8 multipv 1 score cp -42 nodes 7128 nps 445500 tbhits 0 time 16 pv f5e3 f1f5 e7e5 c2c4 b5c4 d1f1 e5e4 f5f6
info depth 9 seldepth 14 multipv 1 score cp -45 nodes 17114 nps 475388 tbhits 0 time 36 pv f5e3 f1f2 e7e5 g2g4 f6f2 d1f1 f8f2 f1f2 e5e4
info depth 10 seldepth 13 multipv 1 score cp -5 nodes 32125 nps 573660 tbhits 0 time 56 pv f5e3 f1f5 e7e5 d3d4 e5e4 c2c4 e4e3 c4c5 e3e2 d1e1
info depth 11 seldepth 15 multipv 1 score cp 0 nodes 67302 nps 715978 tbhits 0 time 94 pv f5e3 c1b1 f6f2 f1f2 f8f2 d1d2 f2f1 d2d1 f1f2
info depth 12 seldepth 10 multipv 1 score cp 0 nodes 74726 nps 739861 tbhits 0 time 101 pv f5e3 c1b1 f6f2 f1f2 f8f2 d1d2 f2f1 d2d1 f1f2
info depth 13 seldepth 10 multipv 1 score cp 0 nodes 86620 nps 780360 tbhits 0 time 111 pv f5e3 c1b1 f6f2 f1f2 f8f2 d1d2 f2f1 d2d1 f1f2
info depth 14 seldepth 17 multipv 1 score cp 0 nodes 107497 nps 853150 tbhits 0 time 126 pv f5e3 c1b1 f6f2 f1f2 f8f2 d1d2 f2f1 d2d1 f1f2
info depth 15 seldepth 10 multipv 1 score cp 0 nodes 146050 nps 942258 tbhits 0 time 155 pv f5e3 c1b1 f6f2 f1f2 f8f2 d1d2 f2f1 d2d1 f1f2
info depth 16 seldepth 22 multipv 1 score mate 9 nodes 345703 nps 1289936 tbhits 0 time 268 pv f6c6 c2c3 b5b4 e3e4 f5e3 d2e3 c6c7 f1f6 e7f6 d1h1 b4c3 c1d1 c7c1 d1e2 f8f2 e2e3 d5e4
info depth 17 seldepth 18 multipv 1 score mate 9 nodes 350828 nps 1294568 tbhits 0 time 271 pv f6c6 c2c3 b5b4 e3e4 f5e3 d2e3 c6c7 f1f6 e7f6 d1f1 b4c3 c1d1 c7c1 d1d2 c1d1 d2e2 f8f1
info depth 18 seldepth 18 multipv 1 score mate 9 nodes 355275 nps 1301373 tbhits 0 time 273 pv f6c6 c2c3 b5b4 e3e4 f5e3 d2e3 c6c7 f1f6 e7f6 d1f1 b4c3 c1d1 c7c1 d1d2 c1d1 d2e2 f8f1
info depth 19 seldepth 18 multipv 1 score mate 9 nodes 360752 nps 1307072 tbhits 0 time 276 pv f6c6 c2c3 b5b4 e3e4 f5e3 d2e3 c6c7 f1f6 e7f6 d1f1 b4c3 c1d1 c7c1 d1d2 c1d1 d2e2 f8f1
info depth 20 seldepth 18 multipv 1 score mate 9 nodes 367823 nps 1318362 tbhits 0 time 279 pv f6c6 c2c3 b5b4 e3e4 f5e3 d2e3 c6c7 f1f6 e7f6 d1f1 b4c3 c1d1 c7c1 d1d2 c1d1 d2e2 f8f1
bestmove f6c6 ponder c2c3
ddugovic commented 5 years ago

Now that f36c4c8d01c1487a44b97b83684b6b2f43201e2b is merged (so SF is less likely to play into lost endgames), I'll try re-tuning some parameters and retry some old ideas.

ddugovic commented 4 years ago

be5a2f015e45886e32867b4559ef51dd694a3cec fixes several TT bugs related to checkmate which may have undermined our earlier efforts. Time permitting I'll run some more tests.

ddugovic commented 4 years ago

Another example of a misplayed attack: https://lichess.org/YIQo8JtV/white#36 and a failed defense: https://lichess.org/Gs10gSkl#31

echo "3q1rk1/p3n3/4p2p/1N4pB/2pp1P2/3P3N/PPP3PP/R1B3K1 w - - 0 16" > test.fen
./stockfish bench atomic 1 1 6160791 test.fen nodes |& sed -u -e 's/info depth //' | sed -u -e 's/seldepth //' | sed -u -e 's/multipv //' | sed -u -e 's/tbhits 0 //' | tee 1.txt
./stockfish bench atomic 1 1 6160792 test.fen nodes |& sed -u -e 's/info depth //' | sed -u -e 's/seldepth //' | sed -u -e 's/multipv //' | sed -u -e 's/tbhits 0 //' | tee 2.txt
sdiff --width=237 1.txt 2.txt

Stockfish 2020-10-30 Multi-Variant by D. Dugovic, F. Fichter et al.                                                     Stockfish 2020-10-30 Multi-Variant by D. Dugovic, F. Fichter et al.
info string variant atomic startpos rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1                            info string variant atomic startpos rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1

Position: 1/1 (3q1rk1/p3n3/4p2p/1N4pB/2pp1P2/3P3N/PPP3PP/R1B3K1 w - - 0 16)                                             Position: 1/1 (3q1rk1/p3n3/4p2p/1N4pB/2pp1P2/3P3N/PPP3PP/R1B3K1 w - - 0 16)
info string classical evaluation enabled                                                                                info string classical evaluation enabled
1 2 1 score cp 240 nodes 40 nps 20000 time 2 pv h5f7 g8g7                                                             | 1 2 1 score cp 240 nodes 40 nps 40000 time 1 pv h5f7 g8g7
2 3 1 score cp 240 nodes 118 nps 59000 time 2 pv h5f7 g8g7 f4g5                                                         2 3 1 score cp 240 nodes 118 nps 59000 time 2 pv h5f7 g8g7 f4g5
3 4 1 score cp 259 nodes 189 nps 94500 time 2 pv h5f7 g8g7 f4g5 h6h5                                                    3 4 1 score cp 259 nodes 189 nps 94500 time 2 pv h5f7 g8g7 f4g5 h6h5
4 5 1 score cp 840 nodes 248 nps 124000 time 2 pv h5f7 g8g7 b5d6                                                        4 5 1 score cp 840 nodes 248 nps 124000 time 2 pv h5f7 g8g7 b5d6
5 6 1 score cp 367 nodes 804 nps 268000 time 3 pv h5f7 g8g7 f4f5 e6f5 b5d6 g7h7                                         5 6 1 score cp 367 nodes 804 nps 268000 time 3 pv h5f7 g8g7 f4f5 e6f5 b5d6 g7h7
6 7 1 score cp 482 nodes 893 nps 223250 time 4 pv h5f7 g8g7 f4f5 e6f5 b5d6 h6h5                                       | 6 7 1 score cp 482 nodes 893 nps 297666 time 3 pv h5f7 g8g7 f4f5 e6f5 b5d6 h6h5
7 9 1 score cp 699 nodes 1046 nps 261500 time 4 pv h5f7 g8g7 b5d6                                                       7 9 1 score cp 699 nodes 1046 nps 261500 time 4 pv h5f7 g8g7 b5d6
8 12 1 score cp 635 nodes 2955 nps 492500 time 6 pv h5f7 g8g7 b5d6 h6h5 f4g5 g7h7 g1h1                                  8 12 1 score cp 635 nodes 2955 nps 492500 time 6 pv h5f7 g8g7 b5d6 h6h5 f4g5 g7h7 g1h1
9 14 1 score cp 337 nodes 10086 nps 630375 time 16 pv h5f7 g8h7 b2b4 c4b3 f4f5 e6f5 c1d2 e7f5                         | 9 14 1 score cp 337 nodes 10086 nps 672400 time 15 pv h5f7 g8h7 b2b4 c4b3 f4f5 e6f5 c1d2 e7f5
10 12 1 score cp 51 nodes 30705 nps 697840 time 44 pv h5f7 g8h8 b2b4 e7c6 b5d6 c6e5 f4f5 c4c3                         | 10 12 1 score cp 51 nodes 30705 nps 714069 time 43 pv h5f7 g8h8 b2b4 e7c6 b5d6 c6e5 f4f5 c4c3
11 15 1 score cp 51 nodes 78994 nps 724715 time 109 pv b5c7 g5g4 g2g3 g8h8 h5f7 e7c6 c7d5 c6e5 f4f5 g4h3              | 11 15 1 score cp 51 nodes 78994 nps 731425 time 108 pv b5c7 g5g4 g2g3 g8h8 h5f7 e7c6 c7d5 c6e5 f4f5 g4h3
12 15 1 score cp 136 nodes 85053 nps 726948 time 117 pv b5c7 g5g4 g2g3 g4h3 f4f5 e6f5 c1f4                            | 12 15 1 score cp 136 nodes 85053 nps 733215 time 116 pv b5c7 g5g4 g2g3 g4h3 f4f5 e6f5 c1f4
13 20 1 score cp 75 nodes 256777 nps 742130 time 346 pv g2g3 e7c6 h5g6 c6e5 g6f7 g8h8 f4e5 d8d7 b5c7 d7c6 c7d5 c4c3   | 13 20 1 score cp 75 nodes 256777 nps 746444 time 344 pv g2g3 e7c6 h5g6 c6e5 g6f7 g8h8 f4e5 d8d7 b5c7 d7c6 c7d5 c4c3
14 24 1 score cp 9 nodes 968518 nps 749626 hashfull 1000 time 1292 pv g2g3 e7c6 a2a4 c6e5 h5f7 g8h8 f4e5 d8d7 c1f4 g5 | 14 24 1 score cp 9 nodes 968518 nps 752539 hashfull 1000 time 1287 pv g2g3 e7c6 a2a4 c6e5 h5f7 g8h8 f4e5 d8d7 c1f4 g5
15 23 1 score cp -32 nodes 1860299 nps 750725 hashfull 1000 time 2478 pv g2g3 e7c6 b2b4 c6e5 b5c7 c4c3 h5f7 g8h8 f4e5 | 15 23 1 score cp -32 nodes 1860299 nps 748912 hashfull 1000 time 2484 pv g2g3 e7c6 b2b4 c6e5 b5c7 c4c3 h5f7 g8h8 f4e5
16 22 1 score cp -24 lowerbound nodes 1936579 nps 752069 hashfull 1000 time 2575 pv g2g3                              | 16 22 1 score cp -24 lowerbound nodes 1936579 nps 750321 hashfull 1000 time 2581 pv g2g3
16 22 1 score cp -16 lowerbound nodes 1947732 nps 752020 hashfull 1000 time 2590 pv g2g3                              | 16 22 1 score cp -16 lowerbound nodes 1947732 nps 750281 hashfull 1000 time 2596 pv g2g3
16 22 1 score cp -12 nodes 1952100 nps 751964 hashfull 1000 time 2596 pv g2g3 e7c6 b2b4 c6e5 h5f7 g8h8 f4e5 d8d7 c1f4 | 16 22 1 score cp -12 nodes 1952100 nps 750230 hashfull 1000 time 2602 pv g2g3 e7c6 b2b4 c6e5 h5f7 g8h8 f4e5 d8d7 c1f4
17 27 1 score cp -4 lowerbound nodes 1990952 nps 752154 hashfull 1000 time 2647 pv g2g3                               | 17 27 1 score cp -4 lowerbound nodes 1990952 nps 750736 hashfull 1000 time 2652 pv g2g3
17 27 1 score cp -20 upperbound nodes 2089869 nps 752292 hashfull 1000 time 2778 pv g2g3 e7c6                         | 17 27 1 score cp -20 upperbound nodes 2089869 nps 750671 hashfull 1000 time 2784 pv g2g3 e7c6
17 27 1 score cp -33 upperbound nodes 2420751 nps 753893 hashfull 1000 time 3211 pv g2g3 e7c6                         | 17 27 1 score cp -33 upperbound nodes 2420751 nps 752487 hashfull 1000 time 3217 pv g2g3 e7c6
17 27 1 score cp -27 nodes 2491508 nps 754545 hashfull 1000 time 3302 pv g2g3 e7c6 b2b4 c6e5 h5f7 g8h8 f4e5 d8d7 c1f4 | 17 27 1 score cp -27 nodes 2491508 nps 752948 hashfull 1000 time 3309 pv g2g3 e7c6 b2b4 c6e5 h5f7 g8h8 f4e5 d8d7 c1f4
18 28 1 score cp -36 upperbound nodes 2912549 nps 756113 hashfull 1000 time 3852 pv g2g3 d8c8                         | 18 28 1 score cp -36 upperbound nodes 2912549 nps 755329 hashfull 1000 time 3856 pv g2g3 d8c8
18 28 1 score cp -44 upperbound nodes 3343859 nps 756700 hashfull 1000 time 4419 pv g2g3 d8c8                         | 18 28 1 score cp -44 upperbound nodes 3343859 nps 754821 hashfull 1000 time 4430 pv g2g3 d8c8
18 28 1 score cp -56 upperbound nodes 3753029 nps 758034 hashfull 1000 time 4951 pv g2g3 d8c8                         | 18 28 1 score cp -56 upperbound nodes 3753029 nps 756201 hashfull 1000 time 4963 pv g2g3 d8c8
18 28 1 score cp -74 upperbound nodes 4186249 nps 759616 hashfull 1000 time 5511 pv g2g3 d8c8                         | 18 28 1 score cp -74 upperbound nodes 4186249 nps 757280 hashfull 1000 time 5528 pv g2g3 d8c8
18 28 1 score cp -99 upperbound nodes 5131214 nps 761872 hashfull 1000 time 6735 pv g2g3 d8c8                         | 18 28 1 score cp -99 upperbound nodes 5131214 nps 760743 hashfull 1000 time 6745 pv g2g3 d8c8
18 28 1 score cp -131 upperbound nodes 6160791 nps 769233 hashfull 1000 time 8009 pv g2g3 d8c8                        | 18 28 1 score cp -79 lowerbound nodes 6161600 nps 767035 hashfull 1000 time 8033 pv h5f7
bestmove g2g3 ponder d8c8                                                                                             | 18 28 1 score cp -79 nodes 6162176 nps 767012 hashfull 1000 time 8034 pv h5f7
                                                                                                                      > bestmove h5f7 ponder g8h8

===========================                                                                                             ===========================
Total time (ms) : 8009                                                                                                | Total time (ms) : 8034
Nodes searched  : 6160791                                                                                             | Nodes searched  : 6162177
Nodes/second    : 769233                                                                                              | Nodes/second    : 767012