Why is my engine making no progress in the endgame?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

konsolas
Posts: 182
Joined: Sun Jun 12, 2016 5:44 pm
Location: London
Full name: Vincent

Why is my engine making no progress in the endgame?

Post by konsolas »

I'm currently testing my engine against BikJump. This is the PGN of the last game I tried:

Code: Select all

[Event "test"]
[Site "?"]
[Date "2016.06.27"]
[Round "1"]
[White "Soot-current"]
[Black "BikJump v2.01 (64-bit)"]
[Result "1/2-1/2"]
[ECO "A82"]
[TimeControl "300"]

1.e4 d6 2.d4 f5 3.e5 Nc6 4.Bb5 dxe5 5.Bxc6+ bxc6 6.dxe5 Qxd1+ 7.Kxd1 Ba6 8.Nf3 O-O-O+ 9.Ke1 Nh6 10.Ng5 Bc4 11.Nd2 Bd5 12.c4 Bf7 13.e6 Bh5 14.f3 Rd6 15.Nb3 Rd3 16.Bf4 Be8 17.Rd1 Rxd1+ 18.Kxd1 g6 19.Be5 Rg8 20.Nxh7 Bg7 21.Bxg7 Rxg7 22.Ng5 Ng8 23.g3 Nf6 24.Nc5 Nh7 25.h4 Nf6 26.Re1 f4 27.g4 Rg8 28.Nd3 Rf8 29.Kc1 a5 30.b3 Kb8 31.Re2 Kc8 32.Rh2 Kb8 33.Nh3 Kc8 34.Nhxf4 Nh7 35.g5 Rf5 36.Re2 Nf8 37.c5 Nh7 38.Re4 Rf8 39.Ne5 Rg8 40.Ra4 Kb7 41.Rxa5 Nf8 42.Ng4 Rh8 43.Nh6 Kb8 44.Ra4 Kb7 45.Re4 Kb8 46.Nd3 Kc8 47.Re2 Nh7 48.a4 Kb7 49.b4 Nf8 50.f4 Kb8 51.a5 Rh7 52.Ne1 Rg7 53.Nf3 Kb7 54.Nd4 Rh7 55.Ra2 Ka6 56.Kb1 Rh8 57.Ra3 Nh7 58.Kc1 Nf8 59.Ra2 Rh7 60.Kb1 Rh8 61.Ra3 Nh7 62.Kc1 Nf8 63.Rb3 Ka7 64.Rg3 Kb7 65.Rc3 Ka7 66.Rh3 Kb7 67.Rc3 Ka7 68.Rh3 Kb7 69.Rc3 1/2-1/2

As a quick synopsis: Black plays the Pirc with 2. ...f5. Over time, white builds up a significant positional advantage. At move 50, most engines score the position at around +7 in favour of white, as does my own engine. However, after move 50, all my engine does is shuffle its rook back and forth, making no progress or pawn breaks, or anything that would be necessary to convert its huge advantage. Every now and then, it notices the 3-move repetition rule and shifts its king, and the game is eventually adjudicated as a draw.

Has anyone else experienced this problem? Is the lack of progress a problem with search or evaluation?
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Why is my engine making no progress in the endgame?

Post by hgm »

Perhaps looking at the PVs the engine prints can give you a clue. I guess it would see the gain of somematerial,otherwise it would not get to +7 in this position. There could be a backlash after the actual capture encouragig the engine togain the material only just before the horizon.

A delayed-lossbonus could help to cure this. 50-move blackmailmight hel as well.
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: Why is my engine making no progress in the endgame?

Post by kbhearn »

It's an evaluation problem primarily (specifically that positions that constitute progress are evaluated less favorably than positions that aren't progressing), though one that in this case will probably be fixed by search. The problem you've got here is that progress first involves a step or two backwards before you can improve the static evaluation. i.e. h5 or f5 has to be played which will improve black's piece activity or possibly even sac a pawn but allow you to move forward. a deeper search will eventually overcome this evaluation valley. a more sophisticated evaluation may allow you to get out of the valley sooner.

the normal way that engines get past these sorts of situations if they can't solve it directly is by 50 move rule proximity. At some point seeing a large advantage and a 50 move rule draw coming your engine should play f5 or h5 just to avoid the draw as it still leaves a sizeable +ive evaluation. It's ugly, but would've allowed you to convert the win in this case - why did your engine eventually prefer the repeat to pushing a pawn?
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: Why is my engine making no progress in the endgame?

Post by kbhearn »

a bit more detail for the position in particular should you try to tackle it by eval (but you should try to fix the 50 move rule thing besides as it'll help these situations in general):

position after 51 ... Rh7

[d]1k2bn2/2p1p2r/2p1P1pN/P1P3P1/1P3P1P/3N4/4R3/2K5 w - - 1 52

what you need to recognise as progress here is that h5 gxh5 f5 is an improvement

[d]1k2bn2/2p1p2r/2p1P2N/P1P2PPp/1P6/3N4/4R3/2K5 b - - 0 53

after that there's many varied possibilities for further progress/counterattacks/etc so it's possible this may not be enough (i.e. some lines white sacs more pawns for a piece so if it likes its pawns so much that it doesn't want to win a piece that could again create a problem)
konsolas
Posts: 182
Joined: Sun Jun 12, 2016 5:44 pm
Location: London
Full name: Vincent

Re: Why is my engine making no progress in the endgame?

Post by konsolas »

Code: Select all

info depth 20 score cp 702 nodes 38012896 time 25546 nps 1488017 hashfull 32473 pv d3e1 h7g7 e2e3 g7h7 e1f3 b8b7 f3d4 b7a7 e3a3 a7a6 c1b1 h7g7 f4f5 g7h7 a3h3 g6f5 h6f5 e8h5 b1c1 h5g4
My engine comes up with that after searching to depth 20. It seems to want to re-position the knight...

I'm not sure if this is a search depth issue, or an issue with my pruning or something else. Most of the evaluation of 702 comes from positional aspects, e.g. the safe mobility of the black pieces, white space, etc.

I'm not sure how evaluation can be improved to encourage sac'ing a pawn, so I will experiment to see if it is search pruning that is the issue.
konsolas
Posts: 182
Joined: Sun Jun 12, 2016 5:44 pm
Location: London
Full name: Vincent

Re: Why is my engine making no progress in the endgame?

Post by konsolas »

kbhearn wrote:a bit more detail for the position in particular should you try to tackle it by eval (but you should try to fix the 50 move rule thing besides as it'll help these situations in general):

position after 51 ... Rh7

[d]1k2bn2/2p1p2r/2p1P1pN/P1P3P1/1P3P1P/3N4/4R3/2K5 w - - 1 52

what you need to recognise as progress here is that h5 gxh5 f5 is an improvement

[d]1k2bn2/2p1p2r/2p1P2N/P1P2PPp/1P6/3N4/4R3/2K5 b - - 0 53

after that there's many varied possibilities for further progress/counterattacks/etc so it's possible this may not be enough (i.e. some lines white sacs more pawns for a piece so if it likes its pawns so much that it doesn't want to win a piece that could again create a problem)
After testing, my engine scores the first position at 725 statically, and the second one at 670. I'm not entirely sure what aspect of the evaluation I need to fiddle with; perhaps candidate passed pawns?
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: Why is my engine making no progress in the endgame?

Post by kbhearn »

konsolas wrote:

Code: Select all

info depth 20 score cp 702 nodes 38012896 time 25546 nps 1488017 hashfull 32473 pv d3e1 h7g7 e2e3 g7h7 e1f3 b8b7 f3d4 b7a7 e3a3 a7a6 c1b1 h7g7 f4f5 g7h7 a3h3 g6f5 h6f5 e8h5 b1c1 h5g4
My engine comes up with that after searching to depth 20. It seems to want to re-position the knight...

I'm not sure if this is a search depth issue, or an issue with my pruning or something else. Most of the evaluation of 702 comes from positional aspects, e.g. the safe mobility of the black pieces, white space, etc.

I'm not sure how evaluation can be improved to encourage sac'ing a pawn, so I will experiment to see if it is search pruning that is the issue.
- you could try reducing the magnitude of the penalty the no-mobility black pieces get a bit to facilitate transitioning that advantage to a different advantage
- you could recognise black's new h-pawn as weak somehow and give it a small penalty compared to a stronger passed pawn (this one might be tough - it is weak but i have a hard time giving algorithmic conditions to identify how none of the black pieces can come to its aid)
- you could give a bonus to have a fluid duo of pawns well advanced (f5+g5 both able to advance)
- you could try adjusting your backward pawn penalty to make f4+h4 less valuable and thus more willing to be sacced
- you could try measuring the lockedness of the position and give a bonus to the side with the advantage for having said advantage in a less locked up position (perhaps a multiplier)

recognising earlier in the line that the position is good will probably help with pruning decisions as well so if it wants to make the move early
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: Why is my engine making no progress in the endgame?

Post by kbhearn »

the plan in that pv isn't unreasonable. i have to think when it gets closer to the point where it would actually play f5 it must give up on it. when you keep advancing through the game moves does f5 keep getting delayed further and further (indicating a reluctance to give up some of its positional goodies giving it that giant score) - like what's the pv when it decides to play 56. Kb1 (as from then on it seems to stick to pointless shuffling)
konsolas
Posts: 182
Joined: Sun Jun 12, 2016 5:44 pm
Location: London
Full name: Vincent

Re: Why is my engine making no progress in the endgame?

Post by konsolas »

Thanks for the advice;

I've been pulling down the weights for everything apart from pawn structure to try to experiment with these ideas. However, I noticed that when I disabled my PST/PCSQ completely, my engine found h4h5 in a heartbeat. (f4f5 at depths 1-4, d3e1 at depths 6-11, h4h5 further on).

Perhaps scaling down the weight of the PST tables (which are mainly used for opening play) as the game progresses is the way to go?
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: Why is my engine making no progress in the endgame?

Post by kbhearn »

normal is to have two PST values (middlegame/endgame) and taper between them as material comes off the board.