king safety: hard positions for zurichess

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

king safety: hard positions for zurichess

Post by brtzsnr »

Below is a list of positions that are losing for the side to move (side to move is mated in 1), but zurichess' statitic evaluation returns +500 cp for the side to move.

How does your engine king safety fares here? Is there a particular evaluation that detects these ones?

Code: Select all

2b2q1k/5P1p/p7/1p1pB3/3P4/1P6/5PP1/6K1 b - -
1q5r/pp3N2/n3rp1k/2P4p/3PP3/PP6/1K5R/6R1 b - -
1r6/5Q2/4p2k/1n1pP1P1/2bP2P1/6K1/q4P2/4N3 b - -
r1b5/1p1n4/p3q1r1/4p3/7Q/5P2/P2Bp1kR/K7 b - -
5r1r/1bqnQp2/1pp1n3/p6p/P1PpPk1N/3P3P/P5P1/1RB3K1 b - -
1k3N2/1p4Q1/p4N2/1b6/1q6/3r3P/3p2P1/1K1R3R w - -
r1b5/1p3p2/p3p1pp/6P1/7k/1P4QP/P4P2/2q2BK1 b - -
3rb2r/NRk5/4p1p1/p4pq1/2PP4/P7/P4PB1/4R1K1 b - -
1r1kbb2/1n4R1/p3N3/1p5r/7p/2B4P/1P3PP1/6K1 b - -
rr3k2/qb2b1pB/2p1Nnp1/3pN3/3P1P2/4P2P/P5P1/1R3RK1 b - -
r1b5/pp3p2/n3Bq1b/1Np5/2Pp1kR1/3P4/PP2PP2/R3K3 b Q -
2r1r2k/2qN1B2/p1b1pBPb/PpPp4/1P3P2/3R4/8/6K1 b - -
2r3k1/3n2p1/2pbNn1p/3pNp1P/3P4/1pQPP3/qP1B1PP1/1K1R3R w - -
q3brk1/2n2p2/rp2pB2/2b5/P1P1p3/4PB2/3N1P2/R3K2R b KQ -
1kN2b1r/Qprbqp2/p4npp/4p3/P3P3/3P3P/1PP3P1/R4RK1 b - -
3r4/4qp1Q/r3p3/3pP1k1/PpPR3p/1P3PpP/8/6K1 b - -
q3r3/1b5N/1p3Q2/3p4/PP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014 10:24 am
Location: Andorra

Re: king safety: hard positions for zurichess

Post by cdani »

Hi!
You can try for example with stockfish. For example your first position:

Code: Select all

Stockfish 7 64 BMI2 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
position fen 2b2q1k/5P1p/p7/1p1pB3/3P4/1P6/5PP1/6K1 b - - 0 1
eval
      Eval term |    White    |    Black    |    Total
                |   MG    EG  |   MG    EG  |   MG    EG
----------------+-------------+-------------+-------------
       Material |   ---   --- |   ---   --- | -8.45 -8.39
      Imbalance |   ---   --- |   ---   --- | -0.20 -0.20
          Pawns |   ---   --- |   ---   --- | -0.06 -0.01
        Knights |  0.00  0.00 |  0.00  0.00 |  0.00  0.00
         Bishop |  0.04 -0.06 | -0.12 -0.19 |  0.17  0.12
          Rooks |  0.00  0.00 |  0.00  0.00 |  0.00  0.00
         Queens |  0.00  0.00 |  0.00  0.00 |  0.00  0.00
       Mobility |  0.28  0.27 |  0.35  0.46 | -0.08 -0.19
    King safety |  0.42 -0.06 | -0.18 -0.06 |  0.60  0.00
        Threats |  0.00  0.00 |  0.19  0.11 | -0.19 -0.11
   Passed pawns |  0.96  0.40 |  0.00  0.00 |  0.96  0.40
          Space |  0.03  0.00 |  0.02  0.00 |  0.01  0.00
----------------+-------------+-------------+-------------
          Total |   ---   --- |   ---   --- | -7.25 -8.34

Total Evaluation: -6.09 (white side)
In general I think is not necessary to evaluate those positions well in the evaluation function. The search will take care of them.
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: king safety: hard positions for zurichess

Post by brtzsnr »

If the position comes up in the middle of the search tree, yes, but at leafs, it's not. For example this one prompted me to find more of bad examples.

[d] r7/1b3pkp/np4p1/p1ppR1Q1/2P3N1/Pq4P1/4BP1P/6K1 w - - 0 28

The position above caused a blunder on FICS. Higher depths mitigate some of the king-safety issues, but they are harder to reach.
Stan Arts
Posts: 179
Joined: Fri Feb 14, 2014 10:53 pm
Location: the Netherlands

Re: king safety: hard positions for zurichess

Post by Stan Arts »

But why evaluate when in check in the first place? The position is not quiet.
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: king safety: hard positions for zurichess

Post by cdani »

brtzsnr wrote:If the position comes up in the middle of the search tree, yes, but at leafs, it's not. For example this one prompted me to find more of bad examples.

r7/1b3pkp/np4p1/p1ppR1Q1/2P3N1/Pq4P1/4BP1P/6K1 w - - 0 28

The position above caused a blunder on FICS. Higher depths mitigate some of the king-safety issues, but they are harder to reach.
I'm with Stan that mostly is unnecessary to evaluate when in check.
This position you show should be also resolved by search. What was the blunder?
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: king safety: hard positions for zurichess

Post by brtzsnr »

This was the blunder http://en.lichess.org/8yXyDEYG/black#47

Code: Select all

$ ./zurichess 
zurichess glarus https://bitbucket.org/zurichess/zurichess
build with devel +ea0386f Fri Mar 25 11:00:48 2016 +0000 at 2016-03-25 13:01:52, running on amd64
position fen r5k1/1b3p1p/np4p1/p1pp2Q1/2Pq2N1/PP4P1/5PBP/4R1K1 b - - 2 24
go
info depth 0 seldepth 0 score cp 35 nodes 5 time 0 nps 16957 pv
info depth 1 seldepth 1 score cp 55 nodes 138 time 1 nps 112125 pv a6c7
info depth 2 seldepth 3 score cp -45 nodes 1555 time 6 nps 241760 pv d4c3 g4h6 g8g7
info depth 3 seldepth 5 score cp -31 nodes 4155 time 16 nps 253982 pv d4c3 g4h6 g8g7 e1e7
info depth 4 seldepth 6 score cp -92 nodes 11941 time 45 nps 262534 pv d4c3 g5e7 a8b8 g4h6 g8g7 h6f7 c3b3
info depth 5 seldepth 8 score cp -132 nodes 26965 time 96 nps 278808 pv a6c7 g4h6 g8h8 h6f7 h8g8 g5e7 a8e8
info depth 6 seldepth 9 score cp -138 nodes 52913 time 176 nps 299826 pv g8h8 g5e7 d4g4 e7b7 g4c8 b7f7
info depth 7 seldepth 9 score cp -152 nodes 82998 time 250 nps 331728 pv g8h8 g5e7 a8b8 g4e5 f7f5 e5d7 b8c8 d7b6
info depth 8 seldepth 9 score cp -106 nodes 216750 time 483 nps 448727 pv g8g7 c4d5 h7h5 g4h6 d4f6 g5f6 g7f6 d5d6
info depth 9 seldepth 9 score cp -113 nodes 301407 time 599 nps 503123 pv g8g7 c4d5 h7h5 g4h6 d4f6 g5f6 g7f6 d5d6 b7g2 g1g2
info depth 10 seldepth 12 score cp -155 nodes 785187 time 1051 nps 746612 pv g8g7 g5e7 d4g4 e7b7 g4c8 b7b6 a8b8 b6a5 d5d4 a5a4
info depth 11 seldepth 12 score cp -135 nodes 1057771 time 1222 nps 865463 pv g8g7 g5e7 d4g4 e7b7 g4c8 b7d5 a8b8 d5e5 g7g8 h2h4 c8d7 e5f6
info depth 12 seldepth 13 score cp -135 nodes 1490936 time 1477 nps 1009193 pv g8g7 g5e7 d4g4 e7b7 g4c8 b7d5 a8b8 d5d2 g7g8 g2f3 c8h3 f3c6
info depth 13 seldepth 20 score cp -236 nodes 16339408 time 10956 nps 1491319 pv b7c6 c4d5 c6b5 a3a4 b5d3 g4f6 g8g7 d5d6 a8f8 f6d7 d4d6 d7f8 d6f8 g2c6
info depth 14 seldepth 20 score cp -231 nodes 21343976 time 14151 nps 1508223 pv b7c6 c4d5 c6b5 a3a4 b5d3 g4f6 g8g7 d5d6 a8b8 f6h5 g7g8 d6d7 h7h6 e1e8 g8h7 h5f6 h7g7 g5d5 d4d5 g2d5
info depth 15 seldepth 20 score cp -302 nodes 119342379 time 79022 nps 1510235 pv b7c6 c4d5 c6b5 d5d6 a8b8 a3a4 b5d3 d6d7 a6c7 g5e5 d4e5 g4e5 c5c4 e5c6 b8a8 b3c4
The moves g8g7 and b7c6 are equally bad, lichess says so.
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: king safety: hard positions for zurichess

Post by cdani »

brtzsnr wrote: The moves g8g7 and b7c6 are equally bad, lichess says so.
One think I needed relative long time to understand was how was possible that the strongest engines find easy long (or short) tactical lines. Is because as you improve it, this capability emerges from the aggregate of knowledge features in eval function, better search, correct quiescence...
D Sceviour
Posts: 570
Joined: Mon Jul 20, 2015 5:06 pm

Re: king safety: hard positions for zurichess

Post by D Sceviour »

Positions that are in check are not interesting or useful to evaluate. The engine should evade the check and then evaluate. Here is a more interesting position from a recent game that Spartacus won:

[d]3r4/1p1rB1k1/p1p1p1p1/P3P1Pq/1P1R1Q1p/5P1P/6K1/8 b - -

Many engines will assess the position as better for black because of the advantage of material and the weakness of the white king. However, Stockfish correctly evaluates this as a win for white, mainly because of extra code that evaluates the danger of Queen contact.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: king safety: hard positions for zurichess

Post by bob »

D Sceviour wrote:Positions that are in check are not interesting or useful to evaluate. The engine should evade the check and then evaluate. Here is a more interesting position from a recent game that Spartacus won:

[d]3r4/1p1rB1k1/p1p1p1p1/P3P1Pq/1P1R1Q1p/5P1P/6K1/8 b - -

Many engines will assess the position as better for black because of the advantage of material and the weakness of the white king. However, Stockfish correctly evaluates this as a win for white, mainly because of extra code that evaluates the danger of Queen contact.
This is dangerous however. Larry K posted a position last week where the same thing happened but was dead wrong, as the queen contact checks were completely meaningless. Queen contact checks in return for giving up an exchange is risky..
D Sceviour
Posts: 570
Joined: Mon Jul 20, 2015 5:06 pm

Re: king safety: hard positions for zurichess

Post by D Sceviour »

bob wrote: Queen contact checks in return for giving up an exchange is risky..
I recently added a Queen contact evaluation to one of two otherwise identical programs. A 300 game match showed a significant increase in elo, so the risk is worth it. King safety is very important as variations in evaluations are larger than any other evaluation - even material.