Basic Lone King Mates?

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Basic Lone King Mates?

Postby Steve Maughan » 17 Mar 2006, 01:59

I'm trying to teach Monarch how to mate with KQ V K, KR v K, KBB v K and KBN v K. I thought this would be really quite straight-forward, however it would seem to be more complex than I imagined.

Let's take the KR v K case. I've evaluation the position as (assume White to move and a Rook up):


Code: Select all
e = -King_Near_Center[Black_KingPosition];
e -= (Distance_Between_Kings * 4)
e += Value_Of_Piece[ROOK]


I would have thought that that would be enough for Monarch to mate with a rook but it has difficulty. The magnitude of the King_Near_Center array is +50 in the center and 15 at the edge and 0 at the corner. Using this evaluation the White king heads for the center and then the white rook moves 'randomly' and settles for a draw. What am I missing?

Thanks,

Steve

PS The function 'just' works for KQ v K
Steve Maughan
 
Posts: 48
Joined: 06 Oct 2004, 17:40
Location: Florida USA

Re: Basic Lone King Mates?

Postby Dann Corbit » 17 Mar 2006, 02:46

Steve Maughan wrote:I'm trying to teach Monarch how to mate with KQ V K, KR v K, KBB v K and KBN v K. I thought this would be really quite straight-forward, however it would seem to be more complex than I imagined.

Let's take the KR v K case. I've evaluation the position as (assume White to move and a Rook up):


Code: Select all
e = -King_Near_Center[Black_KingPosition];
e -= (Distance_Between_Kings * 4)
e += Value_Of_Piece[ROOK]


I would have thought that that would be enough for Monarch to mate with a rook but it has difficulty. The magnitude of the King_Near_Center array is +50 in the center and 15 at the edge and 0 at the corner. Using this evaluation the White king heads for the center and then the white rook moves 'randomly' and settles for a draw. What am I missing?

Thanks,

Steve

PS The function 'just' works for KQ v K


First of all, you want to use your rook to limit the opponent king's real estate as much as possible. So try to cut him off with whatever rook move pushes the king closest to ANY edge. Then chase his king with yours until you can get opposite (the edge of the board will force it eventually).

Simple algorithm (also works for queens, but a queen can sometimes mate a little faster than a rook for obvious reasons).

[Event "Edited position"]
[Site "DCORBIT64"]
[Date "2006.03.16"]
[Round "-"]
[White "-"]
[Black "-"]
[Result "1-0"]
[FEN "8/4k3/8/8/2K4R/8/8/8 w - - 0 1"]
[SetUp "1"]

{--------------
. . . . . . . .
. . . . k . . .
. . . . . . . .
. . . . . . . .
. . K . . . . R
. . . . . . . .
. . . . . . . .
. . . . . . . .
white to play
--------------}
1. Rh6 Kd7 2. Kc5 Ke7 3. Kd5 Kf7 4. Ke5 Kg7 5. Ra6 Kh7 6. Kf5 Kg7 7. Rb6
Kh7 8. Kg5 Kg7 9. Rb7+ Kf8 10. Kf6 Ke8 11. Ke6 Kd8 12. Rh7 Kc8 13. Kd6 Kb8
14. Kc6 Ka8 15. Kb6 Kb8 16. Rh8#
{White mates} 1-0
Dann Corbit
 

Re: Basic Lone King Mates?

Postby Dann Corbit » 17 Mar 2006, 02:55

Here is the optimal track as recored by Yace (you can see that it uses the same principles but is better than my clumsy manual effort):

After setboard 8/4k3/8/8/2K4R/8/8/8 w - -

We get this:

1.Kd5 {EGTB} 1...Kf6! 2.Rh5 Kg6 3.Re5! Kf6
4.Kd6! Kf7! 5.Rf5+ Kg7 6.Ke7! Kg6! 7.Re5 Kg7!
8.Re6! Kg8 9.Kf6! Kh8 10.Kg6! Kg8 11.Re8#! {500}

There are two optimal moves, as reported by Chest:

E:\>chest319 -b -z11 easy.epd
8/4k3/8/8/2K4R/8/8/8 w - - acn 2917391; acs 6; bm Kd5 Rh6; ce 32746; dm 11; pv Rh6 Kf7 Rd6 Kg7 Re6 Kh7 Kc5 Kg7 Kd6 Kf7 Kd7 Kf8 Re7 Kg8 Ke8 Kh8 Kf7 Kh7 Re6 Kh8 Rh6#;
Dann Corbit
 

Re: Basic Lone King Mates?

Postby Ferdinand » 17 Mar 2006, 07:13

Steve Maughan wrote:I'm trying to teach Monarch how to mate with KQ V K, KR v K, KBB v K and KBN v K. I thought this would be really quite straight-forward, however it would seem to be more complex than I imagined.

Let's take the KR v K case. I've evaluation the position as (assume White to move and a Rook up):


Code: Select all
e = -King_Near_Center[Black_KingPosition];
e -= (Distance_Between_Kings * 4)
e += Value_Of_Piece[ROOK]


I would have thought that that would be enough for Monarch to mate with a rook but it has difficulty. The magnitude of the King_Near_Center array is +50 in the center and 15 at the edge and 0 at the corner. Using this evaluation the White king heads for the center and then the white rook moves 'randomly' and settles for a draw. What am I missing?

Thanks,

Steve

PS The function 'just' works for KQ v K


Hello Steve,
I suspect,
Code: Select all
e -= (Distance_Between_Kings * 4)
is not optimal for krk game, because the rook cannot mate if not at edge of board also. The queen can mate even if not at edge of board.
maybe try also
Code: Select all
e -= ((Distance_Between_Kings-2) * 4)
assuming that
wk=B6 and bk=B8, has a distance of 2.

Notes:
1. take out this distance between king condition
then increase penalty for opp king at edge of the board.
Please check also your piece sq tables if you have, maybe there are big values there.

2.
Code: Select all
e = -King_Near_Center[Black_KingPosition];

center=50, edge = 15, corner=0.
you mean to say that the bking (in this case) at edge of the board will get a score of +15 for black?
I guess in this position the score of black should be less than 0.

Overall, just increase penalty if the king is at edge of the board.

Best regards,
Ferdinand
User avatar
Ferdinand
 
Posts: 32
Joined: 17 Mar 2006, 06:12
Location: Philippines

Re: Basic Lone King Mates?

Postby Tony van Roon-Werten » 17 Mar 2006, 09:06

Steve Maughan wrote:I'm trying to teach Monarch how to mate with KQ V K, KR v K, KBB v K and KBN v K. I thought this would be really quite straight-forward, however it would seem to be more complex than I imagined.

Let's take the KR v K case. I've evaluation the position as (assume White to move and a Rook up):


Code: Select all
e = -King_Near_Center[Black_KingPosition];
e -= (Distance_Between_Kings * 4)
e += Value_Of_Piece[ROOK]


I would have thought that that would be enough for Monarch to mate with a rook but it has difficulty. The magnitude of the King_Near_Center array is +50 in the center and 15 at the edge and 0 at the corner. Using this evaluation the White king heads for the center and then the white rook moves 'randomly' and settles for a draw. What am I missing?

Thanks,

Steve

PS The function 'just' works for KQ v K


Hi Steve,

I think you are putting to much stuff at the same time in your eval. Make more clear distinct goals. ie if at any point, the king can be force further away from the centre, do so. If not, closen the kings.

Why is the corner higher than the edge ? Can you checkmate easier in the corner than on any other edge square ?
Just make all edge squares the same. That way, once the king is on the edge, the only way to improve score is to closen the kings. Also make sure that the bonus for closeness of the king is never higher than the difference between 2 centre scores ie

Code: Select all

0,0,0,0,0,0,0,0
0,1,1,1,1,1,1,0
0,1,2,2,2,2,1,0
0,1,2,3,3,2,1,0
0,1,2,3,3,2,1,0
0,1,2,2,2,2,1,0
0,1,1,1,1,1,1,0
0,0,0,0,0,0,0,0



If black gets a bonus of centreValue[sq]*10, the kingsDistanceBonus should never be higher than 10, making sure that the black king isn't allowed closer to the centre, just because the kings are closer than. This might not give the shortest mate, but a 2 ply search should suffice to get any mate.


In addition, the white king heads for the centre ? Your code doesn't give bonusses for that. Are you sure you didn't mix up the white and black king ?

Cheers,

Tony
Tony van Roon-Werten
 
Posts: 99
Joined: 02 Oct 2004, 15:31
Location: 's Hertogenbosch, Netherlands

Re: Basic Lone King Mates?

Postby Stan Arts » 17 Mar 2006, 11:54

Hi,

In Neurosis I do, if very low on pieces (no danger for my own king) , and my score is good >+1.50 or so, try to get the opponent's king to the edge of the board, also try to get my king as close to the opponent's king as possible.
Here, getting the opponent's king close to the edge I give about 2x as big of a bonus as getting my own king near to the opponent's king.
That seems to work well for KR vs K or KQ vs K endgames etc.
For KNB vs K you also need to take a look at bishop colour and corner colour, and force the opponent's king to a corner where it can give mate. In my program I use an array "squarecolour" (0..63) that quickly tells me what colour a square (or a bishop on it) has.

My actual code to give such mates (In Pascal. (and dutch..) ) :

Code: Select all
 if atsC+atsM<11 then begin
  {koning insluiten}
  if mev+tev*opofferstijl>150 then if dameM=0 then begin
  tev:=tev+((3-cenw[koningxM])+(3-cenw[koningyM]))*4; {rand}
  tev:=tev+((7-abs(koningxM-koningxC))+(7-abs(koningyM-koningyC)))*2;{k<>k}
  if atsC=2 then if (loperC=1)and(paardC=1) then begin {KNB - K goede hoek}
   if vakkleur[loperxC[0]+loperyC[0]*8]=vakkleur[0] then
    tev:=tev-abs(koningxM-koningyM)*6 else
    tev:=tev+abs(koningxM-koningyM)*6-42;end;
  end;
  if mev+tev*opofferstijl<-150 then if dameC=0 then begin
  tev:=tev-((3-cenw[koningxC])+(3-cenw[koningyC]))*4; {rand}
  tev:=tev-((7-abs(koningxM-koningxC))+(7-abs(koningyM-koningyC)))*2;{k<>k}
  if atsM=2 then if (loperM=1)and(paardM=1) then begin {KNB - K goede hoek}
   if vakkleur[loperxM[0]+loperyM[0]*8]=vakkleur[0] then
    tev:=tev+abs(koningxC-koningyC)*6 else
    tev:=tev+42-abs(koningxC-koningyC)*6;end;
  end;


Stan
User avatar
Stan Arts
 
Posts: 28
Joined: 30 Sep 2004, 18:29
Location: The Netherlands

Re: Basic Lone King Mates?

Postby H.G.Muller » 17 Mar 2006, 14:58

It depends a little bit on how deep you typically search in such a situation. What in general helps mating the bare king a lot at low search depth is a piece-square table for the King in which the penalty for being near the edge gets larger as you approach the edge. And I think that even for a Rook driving the bare King to the corner is important. Imagine a bare King trapped along the edge by a distant Rook on a very large board (so that the corner is out of view). You now approach with your King. He will just start running along the edge to avoid opposition (which would result in immediate check-mate). But how do you know that is progress? If you don't search deep enough to see the mate in the corner, the engine will consider the situation with his King much closer to the corner just as bad as any other position. If you only go for the smallest distance between the Kings, you will take the opposition yourself, and he will alternately move to the left or right and you won't get anywhere.

A Table like this would be good:
Code: Select all
 0, 3, 5, 6, 6, 5, 3, 0,
 3, 6, 8, 9, 9, 8, 6, 3,
 5, 8,10,11,11,10, 8, 5,
 6, 9,11,12,12,11, 9, 6,
 6, 9,11,12,12,11, 9, 6,
 5, 8,10,11,11,10, 8, 5,
 3, 6, 8, 9, 9, 8, 6, 3,
 0, 3, 5, 6, 6, 5, 3, 0

The crux is that taking a single step from the edge gains you 3 points, while making a single step out of the center only costs 1 point. So it is much more important for the winning King to keep the other King trapped on the edge, even if it has to approach the edge for this himself. You would not even need 'attraction' between the Kings. If the two Kings could walk along a line with piece-square values {center} 0,-1,-3,-6,-10,-15,-21,-28,-36,-45 {corner} (on a very big board), one King would chase the other to the corner. His King score will get more negative because of this, but the difference between the two King scores will increase in his favor, and is maximum if his own King is on -28 and the enemy King on -45 (an advantage of 17). Of course it would be better if his own King was on 0 and the enemy King on -45, but the search will tell him there is no way to force the King to that corner without involving his own King. Staying at 0 will make the opponent move to -3, an advantage of only 3.

If a Rook is position-neutral, cutting off the bare King from the center is the first thing that will occur, followed by approaching the center with his own King. This usually will lead to the Rook closing in on the bare King, shrinking the area in which it is trapped towards a corner, defended by its own King from outside this area. Zugzwang will make the bare King step back, and it is then favorable for the winning King to step towards it, to make sure the bare King can not recover the lost ground. This continues untill the bare King reaches the corner. The search must be deep enough to see the check-mate from a position like

[diag]8/k7/1R6/2K5/8/8/8/8[/diag]

With sufficiently deep search this even works for KbnK, provided that the King scores are weighted more than the center scores for B and N, and that you fill the table in a way to drive the bare king towards the proper corner. Otherwise it will be a 50-50 chance to get trapped into the wrong one.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Basic Lone King Mates?

Postby Sven Schüle » 17 Mar 2006, 18:32

Tony van Roon-Werten wrote:if at any point, the king can be force further away from the centre, do so. If not, closen the kings. [...] Also make sure that the bonus for closeness of the king is never higher than the difference between 2 centre scores
Hi, Steve,

I can only support what Tony writes, I think this simple rule is sufficient for "nearly perfect" play (not optimal in terms of TB but good enough). I do the same for Surprise, and I claim that Surprise has no problems mating with KQK, KRK, KBBK, KBNK.

Sven
User avatar
Sven Schüle
 
Posts: 240
Joined: 26 Sep 2004, 20:19
Location: Berlin, Germany

Re: Basic Lone King Mates?

Postby Tom Likens » 17 Mar 2006, 20:01

Sven Sch?le wrote:
Tony van Roon-Werten wrote:if at any point, the king can be force further away from the centre, do so. If not, closen the kings. [...] Also make sure that the bonus for closeness of the king is never higher than the difference between 2 centre scores
Hi, Steve,

I can only support what Tony writes, I think this simple rule is sufficient for "nearly perfect" play (not optimal in terms of TB but good enough). I do the same for Surprise, and I claim that Surprise has no problems mating with KQK, KRK, KBBK, KBNK.

Sven

Hello Sven,

Are you sure you mean KBNK here. Tony's method is good for driving the enemy king to the edge of the board, but for a BN mate this isn't enough. To mate with NB, you need to drive the enemy king to one of the corners which is the same color as your bishop. Often this first means letting the enemy king go to one of the colors of the opposite color and then using the KNB to force the enemy king into one of the other same-color corners, where you deliver the mate with the bishop.

Tony, I believe was referring mainly to the other basic mates. The heurstics and piecetable(s) for this mate need to be a bit more sophisticated.

regards,
--tom
Tom Likens
 
Posts: 41
Joined: 27 Oct 2004, 05:03

Re: Basic Lone King Mates?

Postby Sven Schüle » 17 Mar 2006, 22:53

Hi Tom,

you're right, KBNK is excluded. Surprise indeed has no special handling for this case, so unfortunately it can't enforce the mate with BN using only this rule. I always apply the rule when one side has the lonely king and it is not a draw.

But KQK, KRK, KBBK works fine with this rule.

Sven
User avatar
Sven Schüle
 
Posts: 240
Joined: 26 Sep 2004, 20:19
Location: Berlin, Germany

Re: Basic Lone King Mates?

Postby H.G.Muller » 17 Mar 2006, 23:09

It depends a lot on the search depth. At very low depths pieces like Knights and Bishops are severely handicapped if you give them an urge to centralize. At large depth this effect becomes much smaller, especially for Bishops. Because the search will see that it in the last 2 moves will be able to centralize the Bishops anyway, and only the end nodes contribute to the score. The bare King can not recover from a bad position in so few plies after the Bishop partially releases it, so the program will still make the effort of driving the bare King to the unfavorable corner in the first N-3 plies, and then plan a recentralization of his own pieces. Of course by the time he has executed the first N-3 plies of his plan, he will be able to see much further, and replace the planned centralization by driving the bare King into the corner even further.

Knights are a little more tricky, they are not that much faster then a King. They benifit more from completely clearing their piece-square tables once you recognize the bare King.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Basic Lone King Mates?

Postby Tony van Roon-Werten » 18 Mar 2006, 10:05

Sven Sch?le wrote:Hi Tom,

you're right, KBNK is excluded. Surprise indeed has no special handling for this case, so unfortunately it can't enforce the mate with BN using only this rule. I always apply the rule when one side has the lonely king and it is not a draw.

But KQK, KRK, KBBK works fine with this rule.

Sven


Yes, KBNK would require:

Code: Select all

0 1 2 3 4 5 6 7
1 1 2 3 4 5 6 6
2 2 2 3 4 5 5 5
3 3 3 3 4 4 4 4
4 4 4 4 3 3 3 3
5 5 5 4 3 2 2 2
6 6 5 4 3 2 1 1
7 6 5 4 3 2 1 0

Tony van Roon-Werten
 
Posts: 99
Joined: 02 Oct 2004, 15:31
Location: 's Hertogenbosch, Netherlands

Re: Basic Lone King Mates?

Postby H.G.Muller » 18 Mar 2006, 10:29

Tony van Roon-Werten wrote:Yes, KBNK would require:

Code: Select all

0 1 2 3 4 5 6 7
1 1 2 3 4 5 6 6
2 2 2 3 4 5 5 5
3 3 3 3 4 4 4 4
4 4 4 4 3 3 3 3
5 5 5 4 3 2 2 2
6 6 5 4 3 2 1 1
7 6 5 4 3 2 1 0


No! This is again a linear gradient, so there is no incentive to use your own King to trap the bare King in a corner. Better would be:

Code: Select all
 0  7 13 18 22 25 27 28
 7  7 13 18 22 25 27 27
13 13 13 18 22 25 25 25
18 18 18 18 22 22 22 22
22 22 22 22 18 18 18 18
25 25 25 22 18 13 13 13
27 27 25 22 18 13  7  7
28 27 25 22 18 13  7  0

Intuitively I still think that the bare King at the edge (e.g. f1) is a lot worse (closer to checkmate) then with the King near the center (f3), despite the fact that the distance to the corner is the same. To scientifically support that one should use the KbnK TB to calculate the average DTM of all positions that have the bare King on a certain square, or better perhaps the median DTM. (One can ignore the positions were the DTM is very large due to unfavorable placement of the winning pieces, e.g. Ka1, Bh1, Nh8, because there it doesn't really matter where the bare King starts. Only the cases where the winning side has properly deployed pieces and is in the process of trapping the bare King have significance, and the median or even quartile automatically ignores the positions with a very long DTM, where the DTM is determined by the placing of your own pieces rather than that of the bare King.)
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Basic Lone King Mates?

Postby Gerd Isenberg » 18 Mar 2006, 11:49

Hmm, i think Tony's psq-table for the lonesome king is quite fine_if_ it also interacts with minimizing the distance of both kings.

If i have a look to your psq-table, there is a "huge" difference between c6 (13) and e8 (22), while on the way to the mate at a8, e8 might be closer than c6 - which might lead to oscillations and probably inefficient search.

If i remember correctly the rules from my old chess books, there is a kind of initial position, where a recipe might be applied to force the lonesome king into the right corner:
[diag]5k2/5N2/5K2/5B2/8/8/8/8 w - -
[/diag]
5k2/5N2/5K2/5B2/8/8/8/8 w - -

The white king resides on the 6.th rank, going from f6 to c6 and b6.
White knight does the "W" from f7,e5,d7,c5,b7 and the white bishop makes locking and tempo moves.

Using that recipe the lonesome king has some squares of the bishops square color - where it seems he could escape from the edge, but the bishop can cut off the escape square(s):
[diag]8/3N3B/2k1K3/8/8/8/8/8 w - -
[/diag]
8/3N3B/2k1K3/8/8/8/8/8 w - -

Later the black king comes temporary back to e8 where the search already "smells" the mate.

I think a psq-table for the knight might also helpfull, considering those mirrored W-squares...

My psq-table proposal for the lonesome king
with bishop on light colored squares
(bishop & 0x55aa55aa55aa55aa):

Code: Select all
a8
0  0  1  2  3  4  6  7
0  2  2  5  6  7  7  6
1  2  2  6  7  7  7  4
2  5  6  8  8  7  6  3
3  6  7  8  8  6  5  2
4  7  7  7  6  2  2  1
6  7  7  6  5  2  2  0
7  6  4  3  2  1  0  0
;-)
Last edited by Gerd Isenberg on 18 Mar 2006, 20:31, edited 2 times in total.
Gerd Isenberg
 
Posts: 285
Joined: 31 Jan 2005, 20:31
Location: Hattingen, Germany

Re: Basic Lone King Mates?

Postby H.G.Muller » 18 Mar 2006, 15:32

If you use the table just for the bare King, and not for your own King, a linear scale will do. My point is mainly that if you apply the same table to both Kings, you have to construct it in such a way that if the pair, with fixed-distance between them, moves closer to the corner you have to award that for the side that is closest to the center.

In physics we would say that the pair of Kings is not a charge, but a dipole. And dipoles are pushed around by field gradients, rather than by the fields itself, seeking out the region where the field is strongest. 8-)

It would be an interesting study to find out which is the optimal piece-square table if you want to steer the process by only a table for the bare King. (You could also give each piece its own table, but my suspicion is that for most piece the table should simply be blank, and that it is mainly the bare King that matters.) You could define "optimal" as the one that on average leads to the quickest mate for a random initial position. But this would depend on the search depth as well (obviously, for a 66-ply serch you would not need any tables at all). So you could also define "optimal" as the table that still leads to a certain checkmate within 50 moves for as shallow a search as possible!

It seems a good optimalization problem to attack with genetic algorithms.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Basic Lone King Mates?

Postby Uri Blass » 19 Mar 2006, 09:43

Steve Maughan wrote:I'm trying to teach Monarch how to mate with KQ V K, KR v K, KBB v K and KBN v K. I thought this would be really quite straight-forward, however it would seem to be more complex than I imagined.

Let's take the KR v K case. I've evaluation the position as (assume White to move and a Rook up):


Code: Select all
e = -King_Near_Center[Black_KingPosition];
e -= (Distance_Between_Kings * 4)
e += Value_Of_Piece[ROOK]


I would have thought that that would be enough for Monarch to mate with a rook but it has difficulty. The magnitude of the King_Near_Center array is +50 in the center and 15 at the edge and 0 at the corner. Using this evaluation the White king heads for the center and then the white rook moves 'randomly' and settles for a draw. What am I missing?

Thanks,

Steve

PS The function 'just' works for KQ v K


For me simple piece square table was enough to mate with KR vs K even without distance between the kings and distance between the king is needed only to mate KQ vs KR.

I see no reason that you have constant numbers like 50 15 and 0

you can look at the piece square table of movei

king_table -60 -60 -60 -60 -60 -60 -60 -60 -50 -50 -50 -50 -50 -50 -50 -50 -45 -45 -45 -45 -45 -45 -45 -45 -40 -40 -40 -40 -40 -40 -40 -40 -35 -35 -35 -35 -35 -35 -35 -35 -30 -30 -30 -30 -30 -30 -30 -30 -10 -10 -20 -20 -20 -20 -10 -10 30 20 0 0 0 0 20 30 -24 -12 0 4 4 0 -12 -24 -12 8 20 24 24 20 8 -12 0 20 32 36 36 32 20 0 4 24 36 40 40 36 24 4 4 24 36 40 40 36 24 4 0 20 32 36 36 32 20 0 -12 8 20 24 24 20 8 -12 -24 -12 0 4 4 0 -12 -24

first 64 numbers are for the opening stage.

Here are the numbers for the endgame

-24 -12 0 4 4 0 -12 -24
-12 8 20 24 24 20 8 -12
0 20 32 36 36 32 20 0
4 24 36 40 40 36 24 4
4 24 36 40 40 36 24 4
0 20 32 36 36 32 20 0
-12 8 20 24 24 20 8 -12
-24 -12 0 4 4 0 -12 -24

The idea is simple.
The main important thing is to push the opponent king to the corner and not to centralize your own king so the difference in the piece square table between the white king and the black king should be higher between e3 and e1 and not between e4 and e2.

The difference in numbers should be higher when you get closer to the corner and smaller when you get closer to the centre because you want the numbers to encourage pushing the opponent king to the direction of the corner even at the price of not putting your king in the centre.


Uri
User avatar
Uri Blass
 
Posts: 727
Joined: 09 Oct 2004, 05:59
Location: Tel-Aviv

Re: Basic Lone King Mates?

Postby Tony van Roon-Werten » 19 Mar 2006, 10:07

H.G.Muller wrote:If you use the table just for the bare King, and not for your own King, a linear scale will do. My point is mainly that if you apply the same table to both Kings, you have to construct it in such a way that if the pair, with fixed-distance between them, moves closer to the corner you have to award that for the side that is closest to the center.



Ah, now I get your point.Yes, if you use the table for both kings, you need nonlinear values. My own experience however, is that the linear king<->corner + linear king<->king distance works well enough and is much simpler.

H.G.Muller wrote:It would be an interesting study to find out which is the optimal piece-square table if you want to steer the process by only a table for the bare King. (You could also give each piece its own table, but my suspicion is that for most piece the table should simply be blank, and that it is mainly the bare King that matters.) You could define "optimal" as the one that on average leads to the quickest mate for a random initial position. But this would depend on the search depth as well (obviously, for a 66-ply serch you would not need any tables at all). So you could also define "optimal" as the table that still leads to a certain checkmate within 50 moves for as shallow a search as possible!

It seems a good optimalization problem to attack with genetic algorithms.


Personnaly I think that a previous idea of you would perform very well for a lot of endgames.

For every king-king combination (taking symetry into account that would be 462 different combinations) find (for all rook/queen/..) positions the average distance to mate. ( and probably multiply that with 10)

Tony
Tony van Roon-Werten
 
Posts: 99
Joined: 02 Oct 2004, 15:31
Location: 's Hertogenbosch, Netherlands

Re: Basic Lone King Mates?

Postby H.G.Muller » 20 Mar 2006, 11:52

Uri Blass wrote:The idea is simple.
The main important thing is to push the opponent king to the corner and not to centralize your own king so the difference in the piece square table between the white king and the black king should be higher between e3 and e1 and not between e4 and e2.

The difference in numbers should be higher when you get closer to the corner and smaller when you get closer to the centre because you want the numbers to encourage pushing the opponent king to the direction of the corner even at the price of not putting your king in the centre.

Yes! This also what I tried to convey.

It even worked for check-mating with exotic pieces on a large board. I tried a (0,4)+(1,4)+(2,4) compound Leaper on a 16x16 board, with only the Kings subject to such a piece-square table, and it easily runs towards the check-mate. Also with KrK on a 16x16 board. Subjecting the piece to a table as well does not really hurt too much if it is fast and the search depth is large enogh. The mentioned Leaper can reach the center of a 16x16 board in 2 moves, just like a Rook. So no matter how much you award it for being in the center, it will only spoil the last two moves of the search.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Basic Lone King Mates?

Postby Steffen Jakob » 20 Mar 2006, 18:23

H.G.Muller wrote:It depends a little bit on how deep you typically search in such a situation. What in general helps mating the bare king a lot at low search depth is a piece-square table for the King in which the penalty for being near the edge gets larger as you approach the edge. And I think that even for a Rook driving the bare King to the corner is important. Imagine a bare King trapped along the edge by a distant Rook on a very large board (so that the corner is out of view). You now approach with your King. He will just start running along the edge to avoid opposition (which would result in immediate check-mate). But how do you know that is progress? If you don't search deep enough to see the mate in the corner, the engine will consider the situation with his King much closer to the corner just as bad as any other position. If you only go for the smallest distance between the Kings, you will take the opposition yourself, and he will alternately move to the left or right and you won't get anywhere.

A Table like this would be good:
Code: Select all
 0, 3, 5, 6, 6, 5, 3, 0,
 3, 6, 8, 9, 9, 8, 6, 3,
 5, 8,10,11,11,10, 8, 5,
 6, 9,11,12,12,11, 9, 6,
 6, 9,11,12,12,11, 9, 6,
 5, 8,10,11,11,10, 8, 5,
 3, 6, 8, 9, 9, 8, 6, 3,
 0, 3, 5, 6, 6, 5, 3, 0

The crux is that taking a single step from the edge gains you 3 points, while making a single step out of the center only costs 1 point. So it is much more important for the winning King to keep the other King trapped on the edge, even if it has to approach the edge for this himself. You would not even need 'attraction' between the Kings. If the two Kings could walk along a line with piece-square values {center} 0,-1,-3,-6,-10,-15,-21,-28,-36,-45 {corner} (on a very big board), one King would chase the other to the corner. His King score will get more negative because of this, but the difference between the two King scores will increase in his favor, and is maximum if his own King is on -28 and the enemy King on -45 (an advantage of 17). Of course it would be better if his own King was on 0 and the enemy King on -45, but the search will tell him there is no way to force the King to that corner without involving his own King. Staying at 0 will make the opponent move to -3, an advantage of only 3.

If a Rook is position-neutral, cutting off the bare King from the center is the first thing that will occur, followed by approaching the center with his own King. This usually will lead to the Rook closing in on the bare King, shrinking the area in which it is trapped towards a corner, defended by its own King from outside this area. Zugzwang will make the bare King step back, and it is then favorable for the winning King to step towards it, to make sure the bare King can not recover the lost ground. This continues untill the bare King reaches the corner. The search must be deep enough to see the check-mate from a position like

[diag]8/k7/1R6/2K5/8/8/8/8[/diag]

With sufficiently deep search this even works for KbnK, provided that the King scores are weighted more than the center scores for B and N, and that you fill the table in a way to drive the bare king towards the proper corner. Otherwise it will be a 50-50 chance to get trapped into the wrong one.


I am not sure if I understood you correctly, but if the weak king is already in the corner, the king of the stronger side is in the center and the rook pins the weak king to the edge then why should the king of the stronger side approach the position of the weak king if the mate is out of the search horizon? The weak king already has the lowest possible value, the rook is neutral and the strong king has a maximum value.

Best wishes,
Steffen.
Steffen Jakob
 
Posts: 1
Joined: 27 Jan 2006, 11:23
Location: Vienna, Austria

Re: Basic Lone King Mates?

Postby H.G.Muller » 20 Mar 2006, 22:18

The white King will approach in order to prevent the bare King from leaving the corner along the edge. With

[diag]1k6/7R/8/3K4/8/8/8/8 w[/diag]

white will play 1. Kc6, sacrificing 2 points, in order to force black to play 1. ..., Ka8 in stead of 1. ..., Kc8, which loses black 5 points. Condition is of course that the search should be deep enough to see that 1. ..., Kc8 will be followed by 2. Rh8#. But it does not have to see that 1. ..., Ka8 will be followed by 2. Kb6, Kb8; 3. Rh8#. It purely does it because the score difference c6-a8 is larger than d5-c8.

This works also on larger boards. The difference between the corner and the center of an edge (half a board) will be larger than that between the center and the 3rd row (which is still two rows away from the center, and thus less than half a board, by the two most expensive steps). The search has to be deep enough to see the white winning King reach the edge, though. So indeed without attraction between the Kings there might be a problem if the board is too large compared to the search depth.

Funny thing is that the bare King only will profit from this when he is aware of this weakness, and runs to the corner before the other King is close. Once they are close, the other King will make a pusuit to prevent the bare King from retracing its steps.

But I agree that distant attraction between Kings is a more fundamental way to solve the problem. On an 8x8 board this is usually not yet a problem: only a single step out of center is required to trap the opponent's King along the edge, and that is well within the horizon of even very shallow searches.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Next

Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 14 guests