End Game Heuristics

Discussion of chess software programming and technical issues.

Moderator: Ras

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

Re: End Game Heuristics

Post by Henk »

hgm wrote:Fairy-Max also plays 59. Ke3. Upto 20 ply it prefers Kd2 with score -2.5. But at 21 ply its score for this move drops to -6.9, and it switches to Ke3.

So indeed it seems a lost position.
Ok thank you.

It happens quite often Skipper is two pawns ahead and still able to loose the endgame.

I still haven't implemented an analysis mode so the program can annotate it's own games. But if there is a blunder it would also be nice to know if it shows if (bad) pruning had caused it or so.
ZirconiumX
Posts: 1347
Joined: Sun Jul 17, 2011 11:14 am
Full name: Hannah Ravensloft

Re: End Game Heuristics

Post by ZirconiumX »

Henk wrote: I still haven't implemented an analysis mode so the program can annotate it's own games. But if there is a blunder it would also be nice to know if it shows if (bad) pruning had caused it or so.
Pretend it's a 10000000/1 time control. That would work, at least for now.

Matthew:out
tu ne cede malis, sed contra audentior ito
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: End Game Heuristics

Post by hgm »

Henk wrote:It happens quite often Skipper is two pawns ahead and still able to loose the endgame.
Does the TT work properly? Can Skipper solve Fine #70?

It is very important to know that Kings should be before passers. Spartacus also regularly bungles end-games because it does not know that.
Henk
Posts: 7251
Joined: Mon May 27, 2013 10:31 am

Re: End Game Heuristics

Post by Henk »

hgm wrote:
Henk wrote:It happens quite often Skipper is two pawns ahead and still able to loose the endgame.
Does the TT work properly? Can Skipper solve Fine #70?

It is very important to know that Kings should be before passers. Spartacus also regularly bungles end-games because it does not know that.
Haven't tried it (#70). My program does not have any end game knowledge at all. For I thought it wasn't that important.

By the way first I have to build something to import a position.

With Kings should be before passers you mean the King should stay in the quadrant. But that fails if there are more than one passers.
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: End Game Heuristics

Post by hgm »

Well, Fine #70 doesn't require end-game knowledge. You should be able to solve it when you know it is better to have more Pawns rather than fewer, or, when you search somewhat longer, that Queens are worth more than Pawns. And that is also true in the middle game.

E.g. 'knowledgeless' Fairy-Max on a 1.3GHz Celeron M:

Code: Select all

 28	+1.47 	4.0M    	0:11.25	a1b1 a7a8 b1b2 a8a7 b2b3 a7a6 b3c2 a6b7 c2c1 
 27	+1.47 	1.1M    	0:03.51	a1b1 a7b7 b1c1 b7c7 c1d1 c7d7 d1c2 d7c8 
 26	+1.47 	897637	0:03.01	a1b1 a7b7 b1c1 b7c7 c1d1 c7d7 d1c2 d7c8 c2d2 c8d8 d2c3 
 26	+0.89 	440416	0:01.76	a1a2 a7b7 a2b3 b7c7 b3c3 c7b7 c3b3 
 25	+0.91 	347546	0:01.48	a1a2 a7b7 a2b3 b7c7 b3c3 c7b7 c3b3 
 24	+0.94 	292533	0:01.30	a1a2 
 24	+0.93 	292049	0:01.30	a1a2 a7b7 a2b3 b7c7 b3c3 c7b7 c3b3 
 23	+0.95 	251276	0:01.14	a1a2 a7b6 a2a3 b6b7 a3b3 
 23	+0.94 	248279	0:01.12	a1b1 a7b7 b1c2 b7c8 c2c3 c8b7 c3d3 b7c7 
 22	+0.94 	214045	0:01.01	a1b1 a7b7 b1c2 b7b8 c2d3 b8c7 d3c4 
 22	+0.93 	203338	0:00.94	a1a2 a7b7 a2b3 b7c7 b3c4 c7b6 c4b3 
 21	+0.95 	194485	0:00.89	a1a2 a7b7 a2b3 b7c7 
 21	+0.89 	174140	0:00.79	a1b2 a7a8 b2c2 a8b8 c2d3 b8c7 
 20	+0.91 	141053	0:00.67	a1b2 
 20	+0.90 	121870	0:00.59	a1b2 a7a6 b2c2 a6b6 c2d3 b6c7 d3c4 c7b6 c4d3 
 19	+0.95 	108842	0:00.53	a1b2 a7a6 b2c2 a6b6 c2d3 b6c7 
 19	+0.91 	104298	0:00.51	a1b1 a7b6 b1c2 b6c7 c2d3 c7b6 d3e3 
 18	+0.89 	76160  	0:00.42	a1b1 a7b6 b1c2 b6b7 
 18	+0.88 	68084  	0:00.39	a1b2 a7a6 b2c2 a6a7 c2d3 a7b7 d3c2 
 17	+0.89 	58538  	0:00.34	a1b2 a7a6 b2c2 a6b7 c2d2 
 16	+0.95 	38915  	0:00.25	a1b2 a7b6 b2c3 b6c7 c3d3 c7b7 d3c4 b7b6 c4d3 b6b7 
 15	+0.92 	29543  	0:00.20	a1b2 
 15	+0.91 	28983  	0:00.19	a1b2 a7b6 b2c3 b6c7 c3d3 
 14	+0.91 	24360  	0:00.17	a1b2 a7b6 b2c2 b6c7 c2c3 c7b6 c3d2 
 13	+0.97 	18018  	0:00.14	a1b2 a7a6 b2c2 
 13	+0.96 	17666  	0:00.14	a1b1 a7a6 b1c2 a6b6 c2d2 
 13	+0.92 	12602  	0:00.11	a1a2 a7b6 a2b3 b6b7 b3c2 b7c7 c2d3 
 12	+0.95 	11872  	0:00.11	a1a2 a7b6 a2b3 b6b7 b3c2 b7c7 c2d3 
 12	+0.93 	11248  	0:00.10	a1b2 a7a6 b2c2 a6b7 c2b3 
 11	+0.99 	7718    	0:00.09	a1b2 a7b6 b2c3 b6c7 c3d3 c7b7 d3e3 b7c7 e3e2 c7d7 e2d3 
 10	+0.95 	5718    	0:00.06	a1b2 a7b6 b2c2 b6b7 c2d3 b7c7 d3e3 c7d7 e3f3 d7e7 
  9	+0.88 	3699    	0:00.03	a1b2 a7b6 b2c3 b6c7 c3c4 c7b6 c4d3 
  8	+0.88 	3118    	0:00.03	a1b2 
  8	+0.87 	2939    	0:00.03	a1b2 a7b6 b2c3 b6c7 c3c4 c7b6 c4c3 
  7	+0.91 	1762    	0:00.01	a1b2 a7b6 b2c3 b6c7 c3d3 c7d7 d3e3 
  6	+0.86 	1394    	0:00.01	a1b2 a7b6 b2c3 b6c7 c3c4 
  6	+0.82 	1292    	0:00.01	a1a2 a7b6 a2b3 b6c7 b3c4 c7d7 
  6	+0.81 	1094    	0:00.01	a1b1 a7b6 b1c2 b6c7 c2d3 c7d7 
  5	+0.95 	784      	0:00.01	a1b1 a7b6 b1c2 b6c7 c2c3 
  5	+0.84 	575      	0:00.01	a1b2 a7b6 b2c3 b6c7 c3d3 
  4	+0.96 	452      	0:00.01	a1b2 a7b6 b2c3 b6c7 
  4	+0.67 	323      	0:00.01	a1b1 a7b6 b1c2 b6c7 
  4	+0.66 	220      	0:00.01	a1a2 a7b6 a2b3 b6c7 
  3	+0.87 	112      	0:00.01	a1a2 a7b6 a2b3 
  3	+0.75 	66        	0:00.01	a1b2 a7b6 b2c3 
  2	+0.68 	31        	0:00.01	a1b2 a7b6 
  2	+0.66 	15        	0:00.01	a1b1 a7b6 
  1	+0.87 	7          	0:00.01	a1b1 
  0	# 
[d]4k3/8/8/8/8/8/4P3/4K3 w
is also a good test positions for your TT code.

If you don't know that a King should better move to the center in the end-game, you won't win many games. (OTOH, if you do that in the middle-game...).

Being in the path (as defending King) is better then being in the square. For the attacking King being in the path is not good, but being next to it is. and being in the square means very little. If the opponent has multiple passers, you are likely lost anyway. But certainly if you march your King behind them. Being in the square is also worth very little if there are Rooks, and the opponent Rook cuts you off from the Pawn. That is why it is much better to be in its path. In Rook endings this typically means the difference between draw and loss.

If your engine doesn't know these elementary principles, it will bungle many games against engines that do.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: End Game Heuristics

Post by Sven »

Henk wrote:Do you think there is something wrong with the end game playing of Skipper. 59. Ke3 ?? I think I better call my program Crappy Duck.
43.Kg1? +/= (better b4 +-)
50.Bb4+? = (better Ke2 +/-)
53.f6? =/+ (better Ke2 or Ke1 =)
54.Kg1?? -+ (better Ke2 =/+)

Moves 43 and 54 might indicate that your engine does not know about king centralization in the endgame. Moves 50 and 53 might indicate that your search does not go deep enough to see that losing the f-pawn (f5/f6) also means losing most winning chances. This is not an easy task, though, since sometimes you need to "know" when being a pawn ahead actually wins, and when it doesn't, but often the static eval is insufficient for that purpose.

Btw 51.c5 is not ?? even though it looks like a blunder. At that point the position is already a draw even with a move better than c5.

Sven
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: End Game Heuristics

Post by lauriet »

Thanks guys HGM is correct, my problem is much more general. Its a bit early to implement specific endings yet. I do have piece tables that encourage pushing pawns but I think that the suggestion of pushing the enemy king to the edge or corner of the board will help a lot. I will try this first. I guess that once its near the edge/corner the depth required for mate will be in reach of the normal search.

Would you keep the PST that encourages the King to go to the center AND add a bonus for minimum distance to the other King ? Or would you leave out the king endgame PST ?


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

Re: End Game Heuristics

Post by Henk »

Sven Schüle wrote:
Henk wrote:Do you think there is something wrong with the end game playing of Skipper. 59. Ke3 ?? I think I better call my program Crappy Duck.
43.Kg1? +/= (better b4 +-)
50.Bb4+? = (better Ke2 +/-)
53.f6? =/+ (better Ke2 or Ke1 =)
54.Kg1?? -+ (better Ke2 =/+)

Moves 43 and 54 might indicate that your engine does not know about king centralization in the endgame. Moves 50 and 53 might indicate that your search does not go deep enough to see that losing the f-pawn (f5/f6) also means losing most winning chances. This is not an easy task, though, since sometimes you need to "know" when being a pawn ahead actually wins, and when it doesn't, but often the static eval is insufficient for that purpose.

Btw 51.c5 is not ?? even though it looks like a blunder. At that point the position is already a draw even with a move better than c5.

Sven
Yes Kg1 is the clue. Field g1 in the Piece Square Table of the king in the middle game has highest value. I looked at my interpolation formula and I saw a silly bug. I use scale = Math.Max(pos.moveCount, 80) / 80 which is always 1 instead of scale = Math.Min(pos.moveCount, 80) / 80. I assume endgame starts with move (= ply)80. So Skippers game phase is crap.
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: End Game Heuristics

Post by hgm »

Using the move number, rather than characteristics of the position to determine game phase is a bad idea. Some games proceed quickly, others drag on forever. The same position can be reached in 30 moves in one game, and in 130 moves in another. Even Fairy-Max uses a material-based game state (Q=6, R=3, minor=2, so ranging from 0-40 in orthodox Chess).
Henk
Posts: 7251
Joined: Mon May 27, 2013 10:31 am

Re: End Game Heuristics

Post by Henk »

hgm wrote:Using the move number, rather than characteristics of the position to determine game phase is a bad idea. Some games proceed quickly, others drag on forever. The same position can be reached in 30 moves in one game, and in 130 moves in another. Even Fairy-Max uses a material-based game state (Q=6, R=3, minor=2, so ranging from 0-40 in orthodox Chess).
Yes I have to change that too. I just took a simple formula (with a major bug in it, bug have been there for weeks).