Endgame woes

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Endgame woes

Post by hgm »

silentshark wrote: Sat Feb 08, 2020 9:26 am@hgm, when you write 'naive eval' I assume you mean the material + positional eval, and that's what gets adjusted?
Indeed, that's the eval you would normally use, and says +3.25 when you are in KBK.

Note that you can cut off some search work in end-games that in general are draws by reducing the search depth at the point where you enter them to a value that would be enough to see any tactics that would provide a winning exit from that end-game. E.g. KBN-KN in general is a draw, but you cannot declare it draw immediately at the point where you enter it (as you could with KBK), as white might be able to gain the Knight, e.g. through a skewer or discovered check. You must do some search to detect such tactics, but if you cannot find any material gain within a few ply, it would be a pure waste of time to deepen to 10 or 20 ply.

Another trick that can be helpful is to recognize inability to involve the King in end-games where this is essential. E.g. when you only have a single piece beside the King, as in KQKP (or KQKPPP). To this end you can keep a 50-move-like counter that resets on captures and King moves. And if its value gets too high (say 10 or 12) you can assume a draw, and apply a large discount factor.
petero2
Posts: 688
Joined: Mon Apr 19, 2010 7:07 pm
Location: Sweden
Full name: Peter Osterlund

Re: Endgame woes

Post by petero2 »

hgm wrote: Sat Feb 08, 2020 8:52 pm Note that you can cut off some search work in end-games that in general are draws by reducing the search depth at the point where you enter them to a value that would be enough to see any tactics that would provide a winning exit from that end-game.
This is true but in practice it might be hard to determine the smallest search depth needed to find all tactics in all possible positions. If the engine uses no forward pruning, using the max DTZ value from the corresponding Syzygy tablebase should work, but with forward pruning this might not be enough.
hgm wrote: Sat Feb 08, 2020 8:52 pm E.g. KBN-KN in general is a draw, but you cannot declare it draw immediately at the point where you enter it (as you could with KBK), as white might be able to gain the Knight, e.g. through a skewer or discovered check. You must do some search to detect such tactics, but if you cannot find any material gain within a few ply, it would be a pure waste of time to deepen to 10 or 20 ply.
This is incorrect, assuming you want to find all wins. You may have to search 100 plies. The following KBNvKN position is won for white with a DTZ value of 100.
[d]8/8/8/8/8/8/1nB5/kNK5 b - - 0 1
See https://syzygy-tables.info/?fen=8/8/8/8 ... _b_-_-_0_1

Assuming you want to maximize playing strength instead of finding all wins, it may still be wise to cut off the search early though.
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Endgame woes

Post by hgm »

Well, if it would take 100 ply after the conversion you would not find it anyway, even if you did search to full depth. But I guess it would indeed be saver to reduce the depth (or the depth over a certain minimum number of ply) by a factor than to put a hard limit on it. Then you won't spoil the property that in the limit of infinite depth it will find anything.