My program is now playing pretty good (certainly not top class). But it is showing typical endgame problems. It was two pieces up against my Fedility excellence, but didn't know what to do after that.
I don't want to put in endgame tables (that seems like cheating) I want it to calculate. So can anyone suggest some heuristics to help 'teach' my program so endgame principles
If there are still Pawns: give higher bonus for advancing pawns, and in particular passers.
In a Pawnless ending: make sure trading equal material increases the evaluation when you are ahead.
Against bare King: make sure the distance of the bare King to the corner becomes the dominant evaluation term (e.g. by multiplying the normal end-game Piece-Square Table for it by 5 or 10.
For KPK a endgame table is useful, you don't have to put it in. You can calculate it when the engine starts. There was a recent thread here about it. My implementation takes less than 100 ms for all 3men tables in total and this is a rather slow implementation. Rupert's and HGM's are much faster.
Your program needs to know what is insufficient material, so it doesn't think it will win KNK or KNNK (or KNKP with a knight, etc.).
For situations where a win is possible but tricky, it is important to write specific evaluation functions for specific endgames. The two most important ones are probably KPK (because it happens often and it's either easily won or a draw, with little in between) and KBPK (because the computer looks really stupid when it thinks it will win with a rook-column pawn and a bishop of the wrong color against a king waiting near the promotion square). After that, you should probably write KNBK (push the enemy king towards a corner where the bishop can attack it) and KBBK (push the enemy king towards any corner).
One more very important heuristic for endgames is that positions with only pawns plus different-color bishops are very drawish. I divide the score by 3 in those situations, which seems to help a lot, although I haven't tuned this.
And another one: If you are ahead but you don't have any pawns, you should reduce your score (not sure by how much), because it's much harder to win without a pawn to promote.
A factor 2 would be about right. With Pawns +2 is usually an easy win, without them +3 is a dead draw, and +4 (Q vs R) just makes it.
But I think all these things are way too subtle for the problem of the OP: he says the program does not know how to win when two pieces up. OK, for KBNK that might be excusable, but normally it should quickly mate with such an advantage, even without Pawns. I assume the complaint was not that it could not win KNNK.
hgm wrote:A factor 2 would be about right. With Pawns +2 is usually an easy win, without them +3 is a dead draw, and +4 (Q vs R) just makes it.
I'll try with a factor of 2. Thanks!
But I think all these things are way too subtle for the problem of the OP: he says the program does not know how to win when two pieces up. OK, for KBNK that might be excusable, but normally it should quickly mate with such an advantage, even without Pawns. I assume the complaint was not that it could not win KNNK.
Yes, he didn't explain what two pieces he was talking about. I did address KBNK and KBBK in my earlier post. If there is a rook or a queen involved, you shouldn't have to do anything, but pushing the lonely king to the edges of the board will help programs with shallow searches.