Improved corner painting

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

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

Re: Improved corner painting

Post by hgm »

Evert wrote:

Code: Select all

eval += centre_table2[defending king] - 3*centre_table2[attacking king];
where centre_table2 just holds the squared-distance to the centre:

Code: Select all

centre_table2[sqr] = offset - (rank-RANKS/2)*(rank-RANKS/2-1) - (file-FILES/2)*(file-FILES/2-1);
This is a piece-square-like term, not dependent on the relative location of the Kings, but just on their own. It could have been put in the normal PST for Kings. BTW, centr_table2 is just what Fairy-Max uses as PST for all pieces that benefit from centralization. But I am surprised that you weight the attacking King more (3 vs 1). In Fairy-Max I do just the opposite, the weight of the attacking King is always 1, and that of the bare King increases from 1 to 10 over 50 moves.

The original idea of the quadratic table was that it would pay for the attacking King to step out of the center in order to prevent the defending King from stepping towards the center. Basically two Kings in opposition act like a dipole in an inhomogeneous field, which is pulled to the region of maximum field gradient (the board edge) if it is oriented such that the defending King is nearest to the edge. This was fine for the Kings, (and in KRK, where the Rook is neutral), but when in addition you would have to use 3 other weak pieces to confine it, the pull on the total charge back to the center overwhelmed the pull on the dipole towards the edge. On a large board this would need at least a factor 4 for the bare King in KFFFK.

BTW, it is not trivial to extract from a tablebase in which corners you can force mate. My idea was to simply score all mates with the King in quadrants of one color as draws, to see if it would still be a general win by forcing mate in the remaining corners. But sometimes you need the threat of an unforcable mate in the wrong corner as an aid in driving the bare King to the other corner. E.g. in KSFK the assymmetry of the Silver makes mate in the back-rank corners impossible. But when the bare King takes shelter in a1 or h1, you have grave difficulty driving it out. E.g. to prevent it from stepping back from h2 to h1 you cannot put a Ferz on g2, as it would also attack h3, and thus cause stalemate.
But putting the Silver on h4 would refute 1... Kh1? with 2. Fg2+ Kh2 3. Sg3#:
[d]8/8/8/8/5B2/5Q2/5K1k/8 b
So black is forced to play 1... Kh3 (followed by 2. Kg1) here. But if the mate in 2 after 1... Kh1? would have been set a draw because it is in the wrong quadrant, black would not be smoked out of the corner by this threat.

So I guess what you have to look for is whether there are any quick forced mates with the bare King in that quadrant. E.g. if there are no forced mate in 3 in that quadrant, any mate in N with N > 3 cannot end in that corner, as to get to the mate you would necessarily have to pass through a mate in 3, and for mates in 3 with the bare King outside the quadrant there would not be enough time to move back to the corresponding corner even if it was a help mate.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Improved corner painting

Post by Evert »

hgm wrote:
Evert wrote:

Code: Select all

eval += centre_table2[defending king] - 3*centre_table2[attacking king];
where centre_table2 just holds the squared-distance to the centre:

Code: Select all

centre_table2[sqr] = offset - (rank-RANKS/2)*(rank-RANKS/2-1) - (file-FILES/2)*(file-FILES/2-1);
This is a piece-square-like term, not dependent on the relative location of the Kings, but just on their own. It could have been put in the normal PST for Kings. BTW, centr_table2 is just what Fairy-Max uses as PST for all pieces that benefit from centralization. But I am surprised that you weight the attacking King more (3 vs 1). In Fairy-Max I do just the opposite, the weight of the attacking King is always 1, and that of the bare King increases from 1 to 10 over 50 moves.
The king PST for the end game is basically the centre table, but I have a separate evaluation function for mating the bare king, which is why it appears explicitly. It's not the full evaluation though, this is in addition to a term that draws the two kings closer together. I think the weight 3 also depends on the weight for that term. Together they act to drive the kings close together and keep the attacking king more centralised than the defending king.
As I said, if I don't weigh centralisation for the attacking king higher, the result is that it brings the kings closer together, but is happy to driver the defending king to the centre to do so.
The original idea of the quadratic table was that it would pay for the attacking King to step out of the center in order to prevent the defending King from stepping towards the center. Basically two Kings in opposition act like a dipole in an inhomogeneous field, which is pulled to the region of maximum field gradient (the board edge) if it is oriented such that the defending King is nearest to the edge. This was fine for the Kings, (and in KRK, where the Rook is neutral), but when in addition you would have to use 3 other weak pieces to confine it, the pull on the total charge back to the center overwhelmed the pull on the dipole towards the edge. On a large board this would need at least a factor 4 for the bare King in KFFFK.
I should really test if the term scales well on large boards; I don't fully remember what I used to tune it, might have been a combination of KBNK and KFFFK on 8x8. It works nicely there though. I don't use PSQ tables for the other pieces (only for the kings), just distance to the defending king.
BTW, it is not trivial to extract from a tablebase in which corners you can force mate. My idea was to simply score all mates with the King in quadrants of one color as draws, to see if it would still be a general win by forcing mate in the remaining corners. But sometimes you need the threat of an unforcable mate in the wrong corner as an aid in driving the bare King to the other corner. E.g. in KSFK the assymmetry of the Silver makes mate in the back-rank corners impossible. But when the bare King takes shelter in a1 or h1, you have grave difficulty driving it out. E.g. to prevent it from stepping back from h2 to h1 you cannot put a Ferz on g2, as it would also attack h3, and thus cause stalemate.
But putting the Silver on h4 would refute 1... Kh1? with 2. Fg2+ Kh2 3. Sg3#:
[d]8/8/8/8/5B2/5Q2/5K1k/8 b
So black is forced to play 1... Kh3 (followed by 2. Kg1) here. But if the mate in 2 after 1... Kh1? would have been set a draw because it is in the wrong quadrant, black would not be smoked out of the corner by this threat.

So I guess what you have to look for is whether there are any quick forced mates with the bare King in that quadrant. E.g. if there are no forced mate in 3 in that quadrant, any mate in N with N > 3 cannot end in that corner, as to get to the mate you would necessarily have to pass through a mate in 3, and for mates in 3 with the bare King outside the quadrant there would not be enough time to move back to the corresponding corner even if it was a help mate.
Hmm... that does sound like more hassle than I want to deal with in SjaakII. I guess I'll have to test how well it handles KSFK in practice.
My Makruk engine has no problems here because it builds a tablebase on the fly (which annoyingly turns out to be far too expensive for KFFFK; I guess I could look for some time to speed that up).