Don wrote:
There are many things you can do, but one important principle which was being done even 30 years ago is that the king safety evaluation should be progressive, not linear. Allocate so many points to each "thing" that you measure and then score based on a non-linear function of the number of points you collect. An example of this might be to use the square of the number of points as the amount of weight to assign to king safety i.e. 0, 1, 4, 9, 16, 25, 36 etc.
So if you notice 2 things, you might get 4 points but if there are 3 things your score jumps to 9 points. The above "square table" is just an example, we are actually more severe than that with Komodo but it's usually good to start conservatively and experiment.
What might you get points for? It's typical to give points for an attack right next to the king and Komodo gives different numbers of points for different pieces. A bishop attacking g7 next to the king probably doesn't deserve the same number of points as a queen attacking g7.
Your idea of giving points for having a check possible is a good one too. In Komodo each different piece gets a different number of points for the possibility to attack. We also have a point table for which square of the board the king is on so that a king in the center of the board gets a few points but near the corners no points. Add all the points together and use this to index into the progressive table and of course scale it appropriately for you evaluation function.
Thank you Don, that's an interesting summary. I've always been too lazy to work on my eval, so it's still *really basic*. I've finally made my first attempt at King Safety:
1/ Pawn shelter (using pawn hash table)
* zone1: 3 squares in front of the king (or 2 squares when king on the edge). add a bonus of 4 centipawns (cp) for each friendly pawn there, and -4cp for each enemy pawn there
* zone2: same story but 2 ranks in front of the king i/o 1 rank. and bonus is divided by 2 (so 2 cp for friendly pawn and -2cp for enemy pawn)
This is an extremely crude method, but testing still shows that it's better than nothing. also testing seems to show that 4 cp is a good value.
What do you recommend as a first step to improve this ?
2/ King Attacks
* zone 1 = "king ring" is all the squres adjacent to the king
* zone 2 = zone 1 + sqaures where a knight would give check (ie. squares the king go jump onto it the king was a knight)
* count pieces attacking the relevant zone (zone 1 for B/R/Q and zone 2 for N), where the square(s) attacked are neither occupied by a friendly pawn (blocking our own attack) or defended by an enemy pawn.
* do a weighted cound: weighted_count is incremented by 2 for a N/B attack, by 3 for a R attack and by 5 for a Q attack
* king attack bonus = weighted_count * count.
example, you have a Knight with attacking zone 2, a bishop attacking zone 1, and a Queen attacking zone 1. Then the bonus is (2+2+5)*3 = 21 cp.
So what I'm wondering now is:
* does it make sense ? are there any
simple ways to improve this ?
* intuitively would you say my weights are too small ? too big ?
I suppose I should remove the enemy pawn from the pawn shelter evaluation, and consider them in the king attack mechanism rather ?