Stockfish and a forced-mate problem it cannot solve
The rise of chess engines in the last decade or so is an interesting topic from which I’ve been somewhat insulated, because of my focus on chess compositions. Frequenting Chess.com has helped me to catch up with the advances of these incredible programs, which perform at superhuman levels on modest hardware. Thus I learnt something most of you would know already, that Stockfish, one of the strongest engines with an Elo rating of around 3500, is open source software that is accessible for free. And you don’t even have to install it on your computer; you can play against Stockfish directly on this site, or set up any position for the engine to analyse.
As a problemist, I was naturally curious to see how efficiently Stockfish deals with long directmate compositions. This is the type of problem in which the aim is to force mate in the fewest number of moves, e.g. the stipulation “Mate in 5” means it’s White to play and mate in 5 moves against any defence. (If you’re not familiar with this vast and fascinating area of chess, check out my blog, An introduction to composed chess problems.) Unsurprisingly, Stockfish was very efficient at handling tasks of this sort. It solved the great majority of directmates of up to about 12 moves that I tested in mere seconds, and even “cooked” a few by finding alternative solutions that were not intended. (Note that when you run Stockfish on Chess.com, its speed still depends on your own computer’s processing power.)
Although this is impressive, Stockfish is no substitute for the specialised programs used by problemists, such as Popeye, which uncovers all of the variations in a problem and provides certainty to its soundness. Stockfish is designed to keep looking for the best move indefinitely, or it stops analysing according to a time-limit, so you can’t tell if any forced mating sequence it has discovered is in fact the shortest possible. Furthermore, Stockfish can be inconsistent in being unable to crack some not-very-long directmates in a reasonable time. Here is an excellent 9-move problem that stumped the engine, but was solved by Popeye in less than eight minutes.
[Note: This blog was written in 2018 and used the then current Stockfish version 8.]
White’s plan is to mate on e7 with the bishop, while avoiding stalemate from capturing the knight. Black is almost in zugzwang, since most knight moves allow the bishop mate and 1…Nd5/Nc6 is answered by the waiting move 2.Bc5, after which the knight must unguard the mating square. However, White has to move the king first to fend off 1…Nc2+. 1.Kb2? fails to 1…Nxd3!+ 2.K-any Nc5 3.Bb4 Nxe4!, creating an escape square on f5 for the black king. White therefore plays 1.Kb1!, but after 1…Nd5, 2.Bc5? is premature because of 2…Nc3+!, again winning the vital e4-pawn. If White tries 2.Kc2? instead, Black counters with the resourceful 2…Ne3+! 3.K-any Nf5!, which simultaneously protects e7 and attacks g7, thus dislodging the white rook. So where should White place the king? No progress is made if it stays on the queen-side, because the black knight can continue to switch between b4 to block the bishop and d5/c6, where the knight either checks directly or (if White plays Bc5) executes a fork that will give the piece access to e4 or f5, as previously seen. Correct is 2.Kc1! forcing 2…Nb4, and then 3.Kd1! Nd5.
At this point, if you have some experience in solving composed problems – which are designed to show an attractive idea – you might guess that the theme of the problem is that the white king marches all the way from a1 to h1 without leaving the first rank. Hence not 4.Bc5? or 4.Ke2? because of 4…Nc3+ again, but 4.Ke1! Nb4 5.Kf1! Nd5 6.Kg1! Nb4 7.Kh1! Nd5/Nc6, and finally the king is safe from checks by the pesky knight – 8.Bc5 N-any 9.Bxe7. The solution exploits a curious geometric feature: h1 is the only white square on the board that cannot be attacked in one move by a knight on either d5 or c6. The maximum-length orthogonal trip by the white king is superbly engineered in this first-rate composition.
When Stockfish tackled this position, it took a few minutes to find a forced mate in 13, starting with 1.Rxh7. After a couple of hours, it picked the right first move, 1.Kb1!, but based that on a wrong continuation, 1…Nd5 2.exd5?, which lets the black king escape to f5, and this leads to mate only on move 12. Are there directmates even shorter than this 9-mover that cannot be solved – within an hour, say – by Stockfish? With few clues on what would give the engine trouble, I threw some random 7- and 8-move problems at it, but most were handled quickly. Then it occurred to me that I could try using the current problem by Siers but with the first few moves of its solution shaved off; at which point of the shortened variation will Stockfish get it right? As it turns out, the engine found the solution only at the mate-in-5 stage. That means the shortest forced-mate sequence I know of that cannot be solved by Stockfish is a mate-in-6, with the white king starting on d1 and the black knight on d5. Can anyone unearth a mate-in-5 position that is too difficult for Stockfish!?