Re: Basic endgames
Posted: Wed Sep 18, 2019 3:28 pm
by Henk
This should be a draw:
[d] 1Q6/8/K7/8/8/8/2pk4/8 w - -
Re: Basic endgames
Posted: Wed Sep 18, 2019 5:01 pm
by Joost Buijs
Henk wrote: ↑Wed Sep 18, 2019 3:28 pm
This should be a draw:
[d] 1Q6/8/K7/8/8/8/2pk4/8 w - -
Yes, this is a draw, but without table-bases it is not so easy for an engine to see. The queen can keep on giving checks from many different locations, so it will take quite some time before repetition detection kicks in.
Re: Basic endgames
Posted: Wed Sep 18, 2019 5:14 pm
by Henk
Joost Buijs wrote: ↑Wed Sep 18, 2019 5:01 pm
Henk wrote: ↑Wed Sep 18, 2019 3:28 pm
This should be a draw:
[d] 1Q6/8/K7/8/8/8/2pk4/8 w - -
Yes, this is a draw, but without table-bases it is not so easy for an engine to see. The queen can keep on giving checks from many different locations, so it will take quite some time before repetition detection kicks in.
Stockfish:
Code: Select all
dep score nodes time (not shown: tbhits knps seldep)
35 0.00 181.3M 0:15.70 Qb2 Kd1 Qd4+ Kc1 Qc3 Kb1 Qb3+ Ka1 Qc4 Kb2 Qe2 Kb1 Qe4 Kc1 Qb7 Kd1 Qf3+ Kd2 Qf4+ Kd1 Qd6+ Ke2 Qh6 Kd1
34 0.00 61.5M 0:05.89 Qb2 Kd1 Qd4+ Kc1 Qc3 Kb1 Qb3+ Ka1 Qc4 Kb2 Qe2 Kb1 Qe4 Kb2 Qg2 Ka1 Qc6 Kb2
33 0.00 21.8M 0:02.52 Qb2 Kd1 Qd4+ Kc1 Qc3 Kb1 Qb3+ Ka1 Qc4 Kb2 Qe2 Kb1 Qe4 Kb2 Qg2 Ka1 Qg5 Kb2 Qg1 c1=Q Qxc1+ Kxc1 Ka5 Kd2 Kb6 Kc3 Kc5 Kb3 Kd4 Kb4 Kd3 Kb5 Kd2 Ka6 Kc1 Kb6
32 0.00 14.7M 0:01.88 Qb2 Kd1 Qd4+ Kc1 Qc3 Kb1 Qb3+ Ka1 Qc4 Kb2 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Kc1 Ka4 Kd2 Qd4+ Kc1 Ka3
10 +0.38 20436 0:00.01 Qb2 Kd1 Qd4+ Kc1 Qe5 Kb1 Qb8+ Kc1 Ka5 Kd1 Qd6+ Kc1 Ka4 Kb1 Qb8+ Kc1
9 +0.38 13696 0:00.01 Qb2 Kd1 Qd4+ Kc1 Qe5 Kb1 Qb8+ Kc1 Ka5 Kd1
8 +0.28 7552 0:00.01 Qb2 Kd1 Qd4+ Kc1 Qd6 Kb1 Qb8+ Kc1 Qb7 Kd2
7 +0.28 6421 0:00.01 Qb2 Kd1 Qd4+ Kc1 Qd6 Kb1 Qb8+ Kc1 Qb7
6 +0.28 4637 0:00.00 Qb2 Kd1 Qd4+ Kc1 Qd6 Kb1
5 +0.28 2678 0:00.00 Qd8+ Kc1 Qd4 Kb1 Qc3 Kc1 Qe1+ Kb2
4 +0.28 1104 0:00.00 Qb2 Kd1 Qd4+ Kc1 Qe3+ Kb1 Qe1+ Kb2
3 +0.22 774 0:00.00 Qg3 c1=Q Qf2+ Kd1 Qf3+ Kd2
2 +0.28 384 0:00.00 Qb2 Kd1
1 +0.28 135 0:00.00 Qb2
0 #
Maybe I should add this position to tablebase. But first have to implement tablebase. If I have time.
O wait position of white king also important.
Re: Basic endgames
Posted: Wed Sep 18, 2019 5:23 pm
by hgm
There are two ways to handle this. You can program the knowledge into the evaluation, detecting the KQKP case with a 7th-rank a-, c-, f- or h-Pawn, and scoring it as drawish when the King supporting the Pawn is next to the promotion square, and the other far-enough away from it.
A more general way would be to recognize that progress against a 7th-rank Pawn with an insufficiently protected (empty) promotion square can only be made by approaching a second piece, and maintain a counter similar to the reversible move counter that resets only when you switch to moving another piece. And then score a position as very drawish when the value of this counter rises to, say, 5 or higher. This would even work with, f.e., an extra far-away Knight (KQNKP). Moving K or N would then allow black to convert to KQNKQ (which should be recognized as drawish), while sticking to Queen moves to check or attack an unprotected promotion square would drive up the counter to a drawish value. The only short-term escape would be to drive the black King to the promotion square (or capture the Pawn), and then reset the counter with a King or Knight move. You could even refine it by only resetting the counter for moves towards the promotion square.
Re: Basic endgames
Posted: Wed Sep 18, 2019 9:41 pm
by bob
Henk wrote: ↑Mon Sep 16, 2019 4:48 pm
Pfft. It shouldn't get more complicated. Already took too much time.
Only counts distance from corner and distance between kings.
Maybe hash table needs to be rewritten for it does not take symmetry into account?
O wait I see I introduced a bug. To be provided.
[d] 4k3/8/8/R7/4K3/8/8/8 w - -
Code: Select all
Depth Value Time Nodes
1 261642 00:00:00 22 e4d3
2 261642 00:00:00 70 e4d3 e8d7
3 261642 00:00:00 600 e4d3 e8d7 d3c2
4 261642 00:00:10 1876 e4d3 e8d7 d3c2 d7c6
5 261642 00:00:22 7896 e4d3 e8d7 d3c2 d7c6 c2b1
6 261642 00:00:50 22369 e4d3 e8d7 d3c2 d7c6 c2b1 c6b6
7 261642 00:01:43 62033 e4d3 e8d7 d3c2 d7c6 c2b1 c6b6 b1a1
8 261642 00:05:10 138574 e4d3 e8d7 d3c2 d7c6 c2b1 c6b6 b1a1 b6a5
9 261642 00:10:34 323429 e4d3 e8d7 d3c2 d7c6 c2b1 c6b6 b1a1 b6a5
10 261642 00:16:04 632175 e4d3 e8d7 d3c2 d7c6 c2b1 c6b6 b1a1 b6a5
11 261642 00:15:26 1299875 e4d3 e8d7 d3c2 d7c6 c2b1 c6b6 b1a1 b6a5
12 261642 00:12:37 2128347 e4d3 e8d7 d3c2 d7c6 c2b1 c6b6 b1a1 b6a5
13 261642 00:27:42 3436668 e4d3 e8d7 d3c2 d7c6 c2b1 c6b6 b1a1 b6a5
14 M7 01:19:40 5891050 a5a7 e8d8 e4d5 d8c8 d5d6 c8b8 a7c7 b8a8 d6c5 a8b8 c5b6 b8a8 c7c8
Analysis stopped
Do this in phases. (1) drive opposing king to edge of the board. You can use a PSQ table that has more negative numbers as the losing king gets closer to the edge. (2) get your king close to the opposing king, but honoring the PST so that it avoids the edge. Once you optimize that you ought to see a mate instantly.
Re: Basic endgames
Posted: Thu Sep 19, 2019 9:54 am
by hgm
Fairy-Max 5 uses a special PST for bare Kings, which increases the centralization bonus by a factor up to 11 compared to that of the opponent pieces. This was needed to make it win end-games where many weak pieces (all drawing to the center) have to cooperate in order to drive the bare King into a corner. (Which usually requires them to leave the center.) It turned out to be better to not apply the maximum factor immediately as the King gets bared, but switch it on graduately with the increase of the 50-move counter. That way the winning side will first focus on good positioning of his own pieces before starting the drive. Which is usually the way such end-games have to be played.
Re: Basic endgames
Posted: Sat Sep 21, 2019 10:16 am
by JohnWoe
Only "simple" endgame Sapeli usually have difficulties is KQkr.
It happens quite often.
I think having some special case code for these kind of endgames could be fruitful.
Here Sapeli 1.46 barely managed to find the win.
[pgn][Event "Computer Chess Game"]
[Site "pc"]
[Date "2019.09.21"]
[Round "-"]
[White "Sapeli 1.46"]
[Black "Stockfish 8 64"]
[Result "1-0"]
[TimeControl "40/180"]
[FEN "8/8/8/3r4/4k3/8/8/QK6 w - - 0 1"]
[SetUp "1"]
{--------------
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . r . . . .
. . . . k . . .
. . . . . . . .
. . . . . . . .
Q K . . . . . .
white to play
--------------}
1. Qa8 {+6,01/10} Ke5 {-5,96/30 13} 2. Kc2 {+6,03/10 6} Ke4 {-5,96/31 0,1}
3. Kc3 {+6,01/9 6} Ke5 {-6,04/29 0,1} 4. Qg8 {+6,03/9 5} Rd6 {-50,73/29 5}
5. Qg5+ {+6,05/9 5} Ke6 {-50,73/31 0,1} 6. Kc4 {+6,06/9 5} Kd7
{-50,81/32 0,1} 7. Qe5 {+6,08/9 5} Re6 {-50,89/31 6} 8. Qf4 {+6,09/9 5} Ke7
{-50,97/33 6} 9. Kd5 {+6,10/9 5} Rg6 {-51,02/32 2,1} 10. Qc7+ {+6,12/9 4}
Kf6 {-1000,28/31 24} 11. Qe5+ {+6,14/9 4} Kf7 {-1000,24/34 0,1} 12. Qf5+
{+6,10/9 4} Kg7 {-1000,24/35 0,5} 13. Ke5 {+6,12/9 4} Kh6 {-1000,23/35 1,1}
14. Qf8+ {+6,13/9 4} Kh5 {-1000,20/38 4} 15. Qc8 {+6,14/9 4} Kh4
{-1000,21/31 3} 16. Kf5 {+6,15/9 4} Rg2 {-50,97/22 2,5} 17. Qh8+
{+6,15/9 4} Kg3 {-5,80/1 0,1} 18. Qc3+ {+6,14/9 4} Kh2 {-1000,17/39 12} 19.
Qe5+ {+6,14/9 4} Kg1 {-1000,16/41 1,1} 20. Qe1+ {+6,16/9 4} Kh2
{-1000,15/43 0,1} 21. Kf4 {+6,15/9 4} Rg7 {-1000,14/42 0,1} 22. Qe5
{+6,17/9 4} Rg3 {-1000,13/44 4} 23. Qc7 {+6,19/9 4} Kg2 {-1000,14/46 5} 24.
Qc2+ {+6,19/9 4} Kh3 {-1000,13/48 0,1} 25. Qh7+ {+6,19/9 4} Kg2
{-5,92/1 0,1} 26. Qb7+ {+6,17/9 4} Kh2 {-1000,14/41 4} 27. Qb8 {+6,19/9 4}
Kg2 {-1000,14/48 4} 28. Qb2+ {+6,19/10 4} Kh3 {-1000,13/51 0,1} 29. Qh8+
{+6,19/9 4} Kg2 {-5,92/1 0,1} 30. Qa8+ {+6,14/9 4} Kh2 {-1000,13/51 8} 31.
Qa1 {+6,16/9 4} Rg2 {-1000,14/40 5} 32. Qh8+ {+6,18/9 4} Kg1 {-5,92/1 0,1}
33. Qb8 {+6,14/9 4} Kf1 {-1000,19/35 5} 34. Qb5+ {+6,16/9 4} Ke1
{-1000,16/39 7} 35. Qc4 {+6,16/9 4} Kf2 {-1000,15/42 0,1} 36. Qd5
{+6,19/9 4} Kf1 {-1000,17/41 8} 37. Qd1+ {+6,16/9 4} Kf2 {-5,84/1 0,1} 38.
Qh1 {+6,15/9 4} Rg8 {-1000,13/54 24} 39. Qf3+ {+6,15/9 4} Ke1
{-1000,12/51 4} 40. Qe4+ {+12,08/9 4} Kf2 {-1000,11/64 15} 41. Qd4+
{+12,23/10 6} Ke1 {-1000,10/66 0,1} 42. Qa1+ {+12,20/9 6} Kd2
{-1000,09/71 0,6} 43. Qa2+ {+12,27/9 6} Kc3 {-1000,08/67 0,9} 44. Qxg8
{+12,32/9 6} Kb4 {-1000,07/75 0,1} 45. Qd5 {+12,37/8 5} Kc3
{-1000,06/81 2,6} 46. Ke3 {+12,43/8 5} Kc2 {-1000,05/95 10} 47. Qd3+
{+12,43/6 5} Kc1 {-1000,04/99 0,1} 48. Qd2+ {+104,85/5 0,1} Kb1
{-1000,03/127 0,1} 49. Kd4 {+104,85/4 0,1} Ka1 {-1000,02/1 0,1} 50. Kc3
{+104,85/3 0,1} Kb1 {-1000,01/127 0,1} 51. Qb2# {+104,85/2 0,1}
{Xboard adjudication: Checkmate} 1-0
[/pgn]