What is king safety?

Discussion of chess software programming and technical issues.

Moderator: Ras

Henk
Posts: 7251
Joined: Mon May 27, 2013 10:31 am

What is king safety?

Post by Henk »

Or what is it not.

Has two rooks and a queen on seventh row something to do with king safety ?
If so what about a rook on seventh row ?
Or a bishop on a diagonal a1-h8 when king on g7 ?
Or knight moving to h1 to get to f5 where it attacks g7 and h6 ?
User avatar
hgm
Posts: 28457
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: What is king safety?

Post by hgm »

A bonus for Rook on 7th when King is on 8th is a useful eval term, but usually it is considered part of Rook evaluation, not King safety.

Terms that are usually referred to as King safety are Pawn shield, and 'King seige', a non-linear function of the number and value of the pieces attacking squares adjacent to the King.

E.g. in CrazyWa I add a bonus that is the product of the number of attacked empty squares adjacent to the enemy King, and the total value of pieces in hand that could be dropped there, which can run up to 900 centi-Pawn.
Henk
Posts: 7251
Joined: Mon May 27, 2013 10:31 am

Re: What is king safety?

Post by Henk »

So two rooks and a queen on seventh row has not much to do with king safety.
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: What is king safety?

Post by cdani »

Henk wrote:So two rooks and a queen on seventh row has not much to do with king safety.
They add to king safety if they affect near the king.
Henk
Posts: 7251
Joined: Mon May 27, 2013 10:31 am

Re: What is king safety?

Post by Henk »

cdani wrote:
Henk wrote:So two rooks and a queen on seventh row has not much to do with king safety.
They add to king safety if they affect near the king.
Then you count them twice (king safety, rook evaluation(BonusOnRow{7, 8})).
Daniel Anulliero
Posts: 773
Joined: Fri Jan 04, 2013 4:55 pm
Location: Nice

Re: What is king safety?

Post by Daniel Anulliero »

Henk wrote:
cdani wrote:
Henk wrote:So two rooks and a queen on seventh row has not much to do with king safety.
They add to king safety if they affect near the king.
Then you count them twice (king safety, rook evaluation(BonusOnRow{7, 8})).
That's why we must choose the bonuses not too high to avoid some material overflow
Ed Trice
Posts: 100
Joined: Fri Sep 19, 2014 5:03 am

Re: What is king safety?

Post by Ed Trice »

Henk wrote:Or what is it not.

Has two rooks and a queen on seventh row something to do with king safety ?
If so what about a rook on seventh row ?
Or a bishop on a diagonal a1-h8 when king on g7 ?
Or knight moving to h1 to get to f5 where it attacks g7 and h6 ?
Don't think of it in terms of fixed square locations. Everything is a function of where the king is, which is a variable.

Put the king at the center of a bull's eye.
The more piece attacks on the bull's eye, the higher the bonus.
These bonuses still work when not attacking the king directly, but squares near the king.

The bonuses fade quickly the further they are from the king.

Proper encoding of these values has a remarkable effect on a program's play. It will naturally develop pawn shields to keep enemy pieces from being able to get close to your king while landing attacks closer and closer to your opponent.

But, giving too many points can be bad also. You end up sacrificing a pawn or two just to create a temporary incursion that can be repelled easily. Afterwards, you're down material without an attack.