A question for engine programmers

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Jack Lad
Posts: 8557
Joined: Wed Mar 08, 2006 10:01 pm
Location: UK

A question for engine programmers

Post by Jack Lad »

According to Mark Uniacke of HIARCS engines can be programmed to understand certain positions.
[d] b6k/8/p1prprp1/PpPpPpPp/1P1P1P1P/2K5/8/8 w - - 0 1
For example in this position it takes SF just over a minute on my computer to realise that it is bad to take a rook.

[d] r5k1/pp1n3r/2pq1np1/6B1/3P3P/8/PPP2PP1/R2QR1K1 b - - 0 1
In this position black should try to keep the queen and trade the rooks by playing Re7.

Both these positions are quite easy for human intuition to see immediately what to do but how do engines know what to to do?
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: A question for engine programmers

Post by bob »

Jack Lad wrote:According to Mark Uniacke of HIARCS engines can be programmed to understand certain positions.
[d] b6k/8/p1prprp1/PpPpPpPp/1P1P1P1P/2K5/8/8 w - - 0 1
For example in this position it takes SF just over a minute on my computer to realise that it is bad to take a rook.

[d] r5k1/pp1n3r/2pq1np1/6B1/3P3P/8/PPP2PP1/R2QR1K1 b - - 0 1
In this position black should try to keep the queen and trade the rooks by playing Re7.

Both these positions are quite easy for human intuition to see immediately what to do but how do engines know what to to do?
There are some old versions of Crafty that solve this type of position almost instantly and correctly. But the "fix" is somewhat harmful overall. You have to recognize blocked pawns first, and realize that unless YOU do something to unblock them, it is a draw. And if you are behind in material, that would be the trigger. But to recognize the original necessary condition of "blocked unless I do something" takes CPU cycles, and those cycles are wasted in almost 100% of the cases, EXCEPT for these kinds of positions. So you have to ask yourself, am I willing to slow the search down in 100% of the positions, by X%, so that I can correctly deal with the one in a zillion position where this will help?" You can sort of guess why this is not being done. In the old versions of Crafty, someone submitted the code to me and it worked, but the slow-down was unacceptable. I turned it into a compile-time option. I don't remember what it was, exactly, perhaps -DDRAW or -DDETECT_DRAWS or something similar, so that those that wanted the feature could have it without making everyone accept the resulting loss of speed.
User avatar
Eelco de Groot
Posts: 4567
Joined: Sun Mar 12, 2006 2:40 am
Full name:   

Re: A question for engine programmers

Post by Eelco de Groot »

Hi Mc Mad,

Just wanted to add that most programs, especially those not so heavy on knowledge, really have no special features for this. Stockfish at least has to rely on brute force. Maybe Sting knows something about the completely closed position one, but I'm not sure. Shredder I believe has some code and Crafty if you compile the code in, was it Jeremiah Penery who developed the special code for Crafty?

In the second position, Stockfish would see that the white Rook has an open e-file so after it exchanges rooks, the position is a bit more even when neither have a rook controlling an open file. That is all, rest is search. And the first position also it is pure search of the tactical consequences of any possible capture and it has to see it goes wrong. It helps that Stockfish almost only looks at captures, checks, pawn promotions in the last six plies. But still it is mostly saved here by extending the principal variation -the main line-, with singular extensions. If it does not do that and you can question if it should do that because it is pretty expensive just extending the PV to see if it fails, then it will not see the eval fall below -13.99 after any pawn capturing a rook, and thinks that any king move is worse, -14 or less. This is a big misevaluation of course when it is really a draw. Without singular extensions in the PV nodes, it takes five plies longer to go to -14 as in my version of Stockfish. The difference is not that big, although after a minute it is a few pawns difference, but that means it will see it much later than one minute here. Still I would like to limit these extesions a bit :) Basically the singular extensions only serve to cover up a 14 pawns misevaluation from Stockfish here ... :P

[D]b6k/8/p1prprp1/PpPpPpPp/1P1P1P1P/2K5/8/8 w - -

Engine: Sf20140810_016 MOD MP (Q6700, 4 threads, 512 MB)
-With no singular extensions in PV nodes
by Tord Romstad, Marco Costalba and Joona Kiiski

33/33 0:00 -8.39 1.cxd6 Rf8 2.Kd3 Kg7 3.Ke2 Kf7 4.Ke3 Rc8
5.Kd3 Ke8 6.Kc3 Rd8 7.Kc2 Kd7 8.Kc3 Bb7
9.Kd3 Re8 10.Ke2 Rf8 11.Kd2 Rd8
12.Kc3 Rf8 13.Kd3 Rd8 14.Ke3 (4.910.014) 4934

34/34 0:01 -8.34 1.cxd6 Rf8 2.Kd3 Kg7 3.Ke2 Kf7 4.Ke3 Rc8
5.Kd3 Ke8 6.Kc3 Rd8 7.Kc2 Kd7 8.Kc3 Bb7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8 13.Kd3 Rab8 14.Kc3 (3.393.331.616) 5649

50/50 10:10 -13.99 1.Kc2 Rd8 2.Kd3 Rff8 3.Ke3 Bb7 4.Kf3 Rc8
5.Kg2 Kg8 6.Kf2 Kf7 7.Kf3 Rfe8 8.Ke3 Ke7
9.Kd3 Ra8 10.Kc3 Kf7 11.Kd3 Ke7 (3.449.540.311) 5654

51/51 10:20 -13.99 1.Kc2 Rd8 2.Kd3 Rff8 3.Ke3 Bb7 4.Kf3 Rc8
5.Kg2 Kg8 6.Kf2 Kf7 7.Kf3 Rfe8 8.Ke3 Ke7
9.Kd3 Ra8 10.Kc3 Kf7 11.Kc2 Rg8
12.Kd3 Rgd8 13.Ke3 Ke7 14.Kf3 (3.511.647.537) 5661

52/52 10:23 -13.99 1.Kc2 Rd8 2.Kd3 Rff8 3.Ke3 Bb7 4.Kf3 Rc8
5.Kg2 Kg8 6.Kf2 Kf7 7.Kf3 Rfe8 8.Ke3 Ke7
9.Kd3 Ra8 10.Kc3 Kf7 11.Kc2 Rg8
12.Kd3 Rgd8 13.Ke3 Ke7 14.Kf3 (3.533.508.387) 5664


best move: Kc3-c2 time: 10:24.441 min n/s: 5.664.080 nodes: 3.533.508.387
Debugging is twice as hard as writing the code in the first
place. Therefore, if you write the code as cleverly as possible, you
are, by definition, not smart enough to debug it.
-- Brian W. Kernighan