KQKP and KRKP endgames

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: KQKP and KRKP endgames

Post by Sven »

lucasart wrote:
Sven Schüle wrote:Btw for KQKP I just found that there are also rare exceptions where a black king on rank 4 is sufficient for a draw, e.g. if the wQ is unable to block the pawn in two plies like in this example:
[D]8/5Q2/5K2/8/1k6/8/2p5/8 w - - 0 1[/D]
That makes a useful predictor slightly more complex (but still doable) ...

EDIT: fixed the diagram (must be white to move)
EDIT2: I meant "black king on rank 4" of course, not "black pawn" :shock:

Sven
On this position the pawn is only one push away from promotion. It's not on rank 4. So this position doesn't look very exceptional. I fail to understand the subtilty here.
"pawn on rank 4" was a typo, I explained it in my late "EDIT2" ... The subtility in this case is, from my viewpoint, that it is not even required for the bK to be close to the promotion square if white pieces are placed very badly. Previously I thought that the Pc2 could only draw if his king were at most two squares away from the promotion square, until I found today that there are positions where the queen can't reach the promotion square in two moves.

Sven
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: KQKP and KRKP endgames

Post by syzygy »

michiguel wrote:If a simplistic case is applied, it should be better to include only basic cases in which you are 100% sure the position is predicted well (draws in this case), and let the other cases be found in search.
This is what my KQKP predictor does. Without tablebases, my engine only recognises the draw at depth 5, but without predictor it would simply never realise it.

So for sure, it is not a problem if a predictor does not catch all draw cases. Without the predictor, the regular "material balance"-based predictor will not catch those anyway, so nothing is lost by having the predictor.

A draw-detector that is too agressive might be more problematic, but as long as the false detections are exceptional (and don't abort the search), I still don't see much of a problem. Of course when there is doubt the predictor should not return a draw score, but only pull the score towards 0.

I guess it does become problematic when the false draw detections last for more than a few ply and can block winning paths.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: KQKP and KRKP endgames

Post by Sven »

syzygy wrote:
michiguel wrote:If a simplistic case is applied, it should be better to include only basic cases in which you are 100% sure the position is predicted well (draws in this case), and let the other cases be found in search.
This is what my KQKP predictor does. Without tablebases, my engine only recognises the draw at depth 5, but without predictor it would simply never realise it.

So for sure, it is not a problem if a predictor does not catch all draw cases. Without the predictor, the regular "material balance"-based predictor will not catch those anyway, so nothing is lost by having the predictor.

A draw-detector that is too agressive might be more problematic, but as long as the false detections are exceptional (and don't abort the search), I still don't see much of a problem. Of course when there is doubt the predictor should not return a draw score, but only pull the score towards 0.

I guess it does become problematic when the false draw detections last for more than a few ply and can block winning paths.
As far as I understood Miguel he prefers the "only predict a draw when being 100% sure" way while you basically say something like "as long as the false detections are exceptional ... I see no problem".

In the given case of KQKP, why do you believe that it is better to accept some false draw predictions in exceptional cases, instead of restricting draw detection by 100% to those cases where exact knowledge is present? I am not saying that accepting some false draw predictions would cause severe trouble, but do you believe it improves playing strength compared to only predicting perfectly known cases? In case you don't then I would always go the "only perfect knowledge" way if it does not hurt otherwise.

Sven
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: KQKP and KRKP endgames

Post by tpetzke »

I also built draw recognizers in iCE for some 4 and 5 man endgames, they definitely help, even if in some endgames only a small percentages of draws is spotted. In KRPKR they spot only 9 Mio of about 210 Mio Draws, but with some additional knowledge about the Lucena position the winning path is usually found.

Thomas...

PS. Thanks Miguel for the TBs, I used them to verify my recognizers.
zamar
Posts: 613
Joined: Sun Jan 18, 2009 7:03 am

Re: KQKP and KRKP endgames

Post by zamar »

I've done some experiments about perfect rule based classifiers.

Kqk, krk, kbk, knk are straightforward.
kpk is difficult, required about 15 rules.
KQQK, KQRK, KQBK, KQNK, KQPK, KRRK, KRBK, KRNK, KRPK are straightforward.
KBBK is relatively straightforward
KBNK is surpisingly difficult (around 10 rules)
KBPK, KNPK, KPP are too difficult

KQKQ is very difficult, likely too difficult
KQKR is doable, but there are some exceptional perpetual stalemate chases which are very difficult
KQKN, KQKB are straightforward
KQKP is very difficult, but I believe is doable (30 rules)
KRKR, KRKB, KRKN are very (maybe too) difficult
KRKP is very difficult but I believe is doable
KBKP complex, but should be doable
KNKP, KPKP are too difficult

There is not AFAIK complete theory about many of these ending, but if you want to build your own classifiers, simply generate all positions, check their status from tablebases and build your own rules with trial and error.

However I must warn you that the task is huge and ELO gain is going to be minimal.
Joona Kiiski
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: KQKP and KRKP endgames

Post by syzygy »

Sven Schüle wrote:In the given case of KQKP, why do you believe that it is better to accept some false draw predictions in exceptional cases, instead of restricting draw detection by 100% to those cases where exact knowledge is present? I am not saying that accepting some false draw predictions would cause severe trouble, but do you believe it improves playing strength compared to only predicting perfectly known cases?
It depends on the rules you can choose from. For example, if rule 1 detects 80% of the KQKP draws with 100% accuracy, and rule 2 detects 99% of the KQKP draws, but with 1% false positives, then rule 2 might be preferable. (A good question here is: 1% of what? 1% of the number of won KQKP positions is huge. 1% of the number of drawn KQKP positions is probably acceptable.)
In case you don't then I would always go the "only perfect knowledge" way if it does not hurt otherwise.
Without specific KQKP rules (and without tablebases), you fall back to the very imperfect knowledge encoded by the regular eval function.

My point is that when not using a specific (im)perfect predictor, you still use a (generic) imperfect predictor. Why is it unacceptable to incorrectly detect some draws if it is acceptable (and in any case inevitable) to incorrectly detect wins?
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: KQKP and KRKP endgames

Post by michiguel »

syzygy wrote:
Sven Schüle wrote:In the given case of KQKP, why do you believe that it is better to accept some false draw predictions in exceptional cases, instead of restricting draw detection by 100% to those cases where exact knowledge is present? I am not saying that accepting some false draw predictions would cause severe trouble, but do you believe it improves playing strength compared to only predicting perfectly known cases?
It depends on the rules you can choose from. For example, if rule 1 detects 80% of the KQKP draws with 100% accuracy, and rule 2 detects 99% of the KQKP draws, but with 1% false positives, then rule 2 might be preferable. (A good question here is: 1% of what? 1% of the number of won KQKP positions is huge. 1% of the number of drawn KQKP positions is probably acceptable.)
In case you don't then I would always go the "only perfect knowledge" way if it does not hurt otherwise.
Without specific KQKP rules (and without tablebases), you fall back to the very imperfect knowledge encoded by the regular eval function.

My point is that when not using a specific (im)perfect predictor, you still use a (generic) imperfect predictor. Why is it unacceptable to incorrectly detect some draws if it is acceptable (and in any case inevitable) to incorrectly detect wins?
Some positions predicted as a win, when there they are draw, could generate bad scenarios. The search find a way to repeat positions with checks of all colors and get at the tip the (wrongly predicted) "won" position. Next ply in the iterative deepening search will be the same, except that the path is extended one ply. It takes forever to see the draw. This may look like a rare case, but the search will find it, and it will make sure it will find it at the tip.

Since the Q has the power to determine what to find, it is riskier to have "predicted wins" that are wrong. It is safer to determine what is a draw (the winning side won't try to find that).

Miguel
Michel
Posts: 2272
Joined: Mon Sep 29, 2008 1:50 am

Re: KQKP and KRKP endgames

Post by Michel »

I think the easiest solution for KQKP is a bitbase of draws with P on a7 and c7.
zamar
Posts: 613
Joined: Sun Jan 18, 2009 7:03 am

Re: KQKP and KRKP endgames

Post by zamar »

Michel wrote:I think the easiest solution for KQKP is a bitbase of draws with P on a7 and c7.
Not enough. There are unbelievably many exceptional positions where pawn on other squares draws as well. The usual reason is that attacking king is somehow misplaced and preventing queen to deliver checks.
Joona Kiiski
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: KQKP and KRKP endgames

Post by syzygy »

michiguel wrote:Some positions predicted as a win, when there they are draw, could generate bad scenarios.
But this is exactly the situation you get with a KQKP-specific rule that only predicts correct draws. When this rule does not give an answer, you fall back on the regular eval which surely will predict a win for K+Q.