Detecting known endgames?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

mambofish

Detecting known endgames?

Post by mambofish »

In a recent test position, Ermintrude reached an end-game with R+B vs P, The enemy Pawn was attacked by the Bishop but defended by the opponent's King. A human would simply play BxP if no mate was on, and expect one's opponent to resign. However, Ermintrude didn't want to play the sacrifice, (even though the program has recognisers for all lone king end games), because the material score R+B-P + positional factors was greater than any non-mate score from the KRk recogniser.

One solution would appear to be to award the recogniser scores a huge bonus for being in a won end game, but I wondered what other people do in these cases (short of introducing EGTBs, which I want to avoid)

Vince
Edmund
Posts: 670
Joined: Mon Dec 03, 2007 3:01 pm
Location: Barcelona, Spain

Re: Detecting known endgames?

Post by Edmund »

Strelka has material imbalances tables. The program looks up the value of a board with certain pieces in a table. In the table a KRK ending would probably have a 100% score, whilst KRBKP would have a little lower score.
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Detecting known endgames?

Post by hgm »

Why do you think it was wrong what the engine did? Perhaps it could see an easy way to win the pawn outright, rather than giving the bishop for it, and the following mate with R+B would be faster than that in KRK.

If you think it is always preferrable to simplify to KRK if you can, you should indeed evaluate KRK higher than any other position.
mambofish

Re: Detecting known endgames?

Post by mambofish »

Yes, when I look at this more closely, the engine is right. It was quite easy to capture the pawn without losing the bishop. I think the real issue is that there is no KRBk end-game recogniser in ermintrude, so the engine can make some pretty aimless moves when it gets there. If it had gone to a KRk ending, it would have played "smart" moves, leading (almost optimally) to mate, and I would have felt unjustifiably smug :)

And setting the KRk scores artifically high to force white to make the BxP sac had an unforeseen side-effect: when it's black's turn to play, he avoids capturing the Bishop, because its cheaper not to, despite losing the pawn!

Anyway, I've removed the recognisers for now as I think I'm using them wrongly. What I do instead is give a bonus during eval to the player for being in a winnable pawnless end game again against a lone king. What I should also do (but am not doing yet) is add the relevant recogniser positional score to the bonus, and bypass all other evaluation factors. Hopefully this will a) encourage the engine to enter end-games it knows how to win, and b) play good moves when in the end game.
wgarvin
Posts: 838
Joined: Thu Jul 05, 2007 5:03 pm
Location: British Columbia, Canada

Re: Detecting known endgames?

Post by wgarvin »

There's some tidbits about Darkthought's use of interior node recognizers here: http://people.csail.mit.edu/heinz/dt/node36.html

It sounds like if you have interior node recognizers, you have to be very careful about the scores they return (unless they are mate scores and your engine can definitely find the wins, e.g. with bitbases or something).

IIRC Darkthought used bitbases for all 4-piece endings, and they used heuristic scores to help the engine find the win. So for each recognized ending they had to find a range of scores for the heuristics to return, that had approximately the right relationship with the scores of other endings. For some of their endings they did not have complete W/L/D information---instead, the bitbase would have 1 bit, e.g. for Won vs. Drawn, but if the bit was set to Drawn then they would also use a conservative heuristic that detected all the Lost positions plus a bunch of others, and the recognizer would fail on those. So they would be assigned normal evaluation scores, and so the heuristic scores used by the recognizer had to be compatible with these normal scores.
jesper_nielsen

Re: Detecting known endgames?

Post by jesper_nielsen »

mambofish wrote:Yes, when I look at this more closely, the engine is right. It was quite easy to capture the pawn without losing the bishop. I think the real issue is that there is no KRBk end-game recogniser in ermintrude, so the engine can make some pretty aimless moves when it gets there. If it had gone to a KRk ending, it would have played "smart" moves, leading (almost optimally) to mate, and I would have felt unjustifiably smug :)

And setting the KRk scores artifically high to force white to make the BxP sac had an unforeseen side-effect: when it's black's turn to play, he avoids capturing the Bishop, because its cheaper not to, despite losing the pawn!

Anyway, I've removed the recognisers for now as I think I'm using them wrongly. What I do instead is give a bonus during eval to the player for being in a winnable pawnless end game again against a lone king. What I should also do (but am not doing yet) is add the relevant recogniser positional score to the bonus, and bypass all other evaluation factors. Hopefully this will a) encourage the engine to enter end-games it knows how to win, and b) play good moves when in the end game.
It is not clear to me if you are doing this or not, but:

It is important that the score the recogniser returns is the same score as the evaluation function returns.

So if the position is recognised, return the recogniser score in evaluation.
I.e. if the recogniser says "at least 5.23", the evaluation should be 5.23.

Otherwise the recogniser says one value during the search, and the evaluation function says another value during q-search. A sure way to confuse the engine. :-)

Kind regards,
Jesper
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Detecting known endgames?

Post by bob »

mambofish wrote:In a recent test position, Ermintrude reached an end-game with R+B vs P, The enemy Pawn was attacked by the Bishop but defended by the opponent's King. A human would simply play BxP if no mate was on, and expect one's opponent to resign. However, Ermintrude didn't want to play the sacrifice, (even though the program has recognisers for all lone king end games), because the material score R+B-P + positional factors was greater than any non-mate score from the KRk recogniser.

One solution would appear to be to award the recogniser scores a huge bonus for being in a won end game, but I wondered what other people do in these cases (short of introducing EGTBs, which I want to avoid)

Vince
Here's the ultimate problem in that area. KQQ vs KP. You have the 4-piece tables and know that KQ vs K is an instant mate in N. So do you play QxP KxQ and accept the tablebase mate? (most humans would). Or do you play on with the KQQ and find an even faster mate perhaps? I have seen my program reach a KQNN vs KPP ending and play QxP KxP to reach a won KNN vs KP ending (mate in something like 80 moves or so in a tournament game against a GM, where the KQNN vs KPP was much easier to win by just forcing mate, but the search could not see that mate at the time control it had at the time.

So you can get good looking sacrifices that lead to a win, and you can get ridiculous sacrifices. I just let the program do whatever it wants to follow a path to the largest possible score.