How to solve positions with mate-threats?

Discussion of chess software programming and technical issues.

Moderator: Ras

JBNielsen
Posts: 267
Joined: Thu Jul 07, 2011 10:31 pm
Location: Denmark

How to solve positions with mate-threats?

Post by JBNielsen »

[d]2br1rk1/2qnQ2p/p4pp1/4p3/P1p1P1N1/2Pn1N1P/2B2PP1/1R1R1K2 w Rd1xNd3 Larsen1.99.100

1.Rxd3!, cxd3 2.Bb3+,Kh8 3.Nxf6!,Rxf6 4.Ng5! (Rxf2+ 5.Kg1,Rf1+ 6.Kh2)

I am interested to know if any weak program (rating<2200) can solve this in 30 seconds.

Whites first 2 moves are a capture and a check, so it is easy to allow your engine to search deeper based on this.

Whites 3.Nxf6! and 4.Ng5! are matethreats and should also make the engine search deeper (as we humans do).
But a matethreat can only be detected by a little search.
So how can this be fixed?

The 2 white moves 1.Rxd3! and 3.Nxf6! are also 'surprising' moves, that may give some late-move-reduction or otherwise reduce the search.

On the top of this blacks final checks makes it even more difficult to solve.
gladius
Posts: 568
Joined: Tue Dec 12, 2006 10:10 am
Full name: Gary Linscott

Re: How to solve positions with mate-threats?

Post by gladius »

Are you sure this is a mate? After 1. Rxd3, it seems that 1...Rde8 or 1...Kh8 leads to a very large material gain, but not a forced mate.

GarbochessJS (which is in javascript, and has no king safety) can spot the Rxd3 shot, it found it at ply 12, in about 1:12. Given it runs at least 20x slower than equivalent C++ code, I'd assume other relatively weak programs shouldn't have much trouble here.

Output:
Ply:12 Score:6103 Nodes:10881784 NPS:150633 Rxd3 Kh8 Nxf6 Nxf6 Qxc7 cxd3 Bb3 Nxe4 Nxe5 Rxf2+ Kg1 Re8 Nf7+ Rxf7 Bxf7
JBNielsen
Posts: 267
Joined: Thu Jul 07, 2011 10:31 pm
Location: Denmark

Re: How to solve positions with mate-threats?

Post by JBNielsen »

gladius wrote:Are you sure this is a mate? After 1. Rxd3, it seems that 1...Rde8 or 1...Kh8 leads to a very large material gain, but not a forced mate.

GarbochessJS (which is in javascript, and has no king safety) can spot the Rxd3 shot, it found it at ply 12, in about 1:12. Given it runs at least 20x slower than equivalent C++ code, I'd assume other relatively weak programs shouldn't have much trouble here.

Output:
Ply:12 Score:6103 Nodes:10881784 NPS:150633 Rxd3 Kh8 Nxf6 Nxf6 Qxc7 cxd3 Bb3 Nxe4 Nxe5 Rxf2+ Kg1 Re8 Nf7+ Rxf7 Bxf7
No, it is not a mate.
But there are matethreats in the main line.
User avatar
Steve Maughan
Posts: 1315
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: How to solve positions with mate-threats?

Post by Steve Maughan »

Monarch 1.7 (rated about 2200) find this in 3 seconds. It doesn't have any special mate-threat code. Here's the analysis:

[d]2br1rk1/2qnQ2p/p4pp1/4p3/P1p1P1N1/2Pn1N1P/2B2PP1/1R1R1K2 w - -

Engine: Monarch 1.7 (1024 MB) by Steve Maughan

8/25 0:00 +1.97 1.Nh6+ Kh8 2.Nf7+ Rxf7 3.Qxf7 Qc6
4.Qd5 Qxd5 5.exd5 (642.788)

9/26 0:01 +1.89 1.Nh6+ Kh8 2.Nf7+ Rxf7 3.Qxf7 Qc6
4.Ne1 Rf8 5.Qe7 Nf4 (1.069.821)

9/29 0:03 +1.90++ 1.Rxd3 (3.622.032) 1092

9/30 0:04 +3.37 1.Rxd3 cxd3 2.Nxf6+ Rxf6 3.Bb3+ Kh8
4.Ng5 Rxf2+ 5.Kg1 Rf1+ 6.Kh2 Nc5
7.Qxc7 (5.284.171) 1107

10/35 0:05 +3.62 1.Rxd3 cxd3 2.Nxf6+ Rxf6 3.Bb3+ Kh8
4.Ng5 Rxf2+ 5.Kg1 Rf1+ 6.Kh2 Nf6
7.Qxc7 Rxb1 8.Qxd8+ Kg7 (6.428.661) 1117

11/36 0:12 +4.11 1.Rxd3 cxd3 2.Nxf6+ Rxf6 3.Bb3+ Kh8
4.Ng5 Rxf2+ 5.Kg1 Rf1+ 6.Kh2 Nf6
7.Qxc7 Rxb1 8.Qxd8+ Kg7 9.Qe7+ Kh6
10.Qxf6 Rxb3 11.Qxe5 (14.579.595) 1146
lucasart
Posts: 3243
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: How to solve positions with mate-threats?

Post by lucasart »

JBNielsen wrote:[d]2br1rk1/2qnQ2p/p4pp1/4p3/P1p1P1N1/2Pn1N1P/2B2PP1/1R1R1K2 w Rd1xNd3 Larsen1.99.100

1.Rxd3!, cxd3 2.Bb3+,Kh8 3.Nxf6!,Rxf6 4.Ng5! (Rxf2+ 5.Kg1,Rf1+ 6.Kh2)

I am interested to know if any weak program (rating<2200) can solve this in 30 seconds.

Whites first 2 moves are a capture and a check, so it is easy to allow your engine to search deeper based on this.

Whites 3.Nxf6! and 4.Ng5! are matethreats and should also make the engine search deeper (as we humans do).
But a matethreat can only be detected by a little search.
So how can this be fixed?

The 2 white moves 1.Rxd3! and 3.Nxf6! are also 'surprising' moves, that may give some late-move-reduction or otherwise reduce the search.

On the top of this blacks final checks makes it even more difficult to solve.
Typically things like razoring, futility pruning, eval based pruning, reducing checks and captures with < 0 SEE etc. get in the way, and prevent your engine from searching these lines. All these things are good for your elo, so you should keep them, but when solving tactical position, I think it's good to have a tactical mode in the engine that disables these things, or makes them in a more conservative.

For example, in my developpement version of DiscoCheck, the result is pretty bad: 38.8 M nodes to find it, and although it compensates by being very fast in NPS, it is still unacceptable

Code: Select all

info score cp 295 depth 1 nodes 149 pv g4h6
info score cp 295 depth 2 nodes 400 pv g4h6
info score cp 273 depth 3 nodes 948 pv g4h6
info score cp 273 depth 4 nodes 1828 pv g4h6
info score cp 273 depth 5 nodes 2896 pv g4h6
info score cp 267 depth 6 nodes 5906 pv g4h6
info score cp 263 depth 7 nodes 16451 pv g4h6
info score cp 224 depth 8 nodes 47145 pv g4h6
info score cp 219 depth 9 nodes 94162 pv g4h6
info score cp 236 depth 10 nodes 189532 pv g4h6
info score cp 204 depth 11 nodes 446601 pv g4h6
info score cp 195 depth 12 nodes 1276812 pv g4h6
info score cp 208 depth 13 nodes 2460930 pv g4h6
info score cp 184 depth 14 nodes 6143296 pv g4h6
info score cp 184 depth 15 nodes 10623662 pv g4h6
info score cp 243 depth 16 nodes 12689778 pv g4h6
info score cp 702 depth 17 nodes 38855690 pv d1d3
Now let's switch off razoring and eval based pruning only: found at depth=14 after 21.8 M nodes "only"

Code: Select all

info score cp 562 depth 14 nodes 21828608 pv d1d3
Now let's extend all checks, reagerdless of SEE, instead of reducing SEE < 0 checks:

Code: Select all

info score cp 562 depth 11 nodes 4984479 pv d1d3
... and so on

My advice is:
(i) if you are looking for elo, forget about these tacticla teste, just test every patch in a scientific way, using proven statistical methods
(ii) if you are only interested in tactics, then play around with search extensions, reductions, etc. and test it in tactical test suites. But don't expect your engine to break any elo records that way!
(iii) if you want to make a nice product: do both! Default settings that do (i), and optional "tactical mode" setting(s) that do (ii). But, unfortunately, you cannot have both at the same time.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
JBNielsen
Posts: 267
Joined: Thu Jul 07, 2011 10:31 pm
Location: Denmark

Re: How to solve positions with mate-threats?

Post by JBNielsen »

It is impressive that Monarch can solve it in less than 4M nodes.
How is it searching?

Dabbaba searches 8 ply in 138M nodes without finding the solution.


It is easier with the king at g1.
Dabbaba solves it in 30M nodes.

[d]2br1rk1/2qnQ2p/p4pp1/4p3/P1p1P1N1/2Pn1N1P/2B2PP1/1R1R2K1 w Rd1xNd3
User avatar
Steve Maughan
Posts: 1315
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: How to solve positions with mate-threats?

Post by Steve Maughan »

Monarch 1.7 is not doing anything special. And in general it is not especially good at tactics. It doesn't do LMR - maybe that helps in this situation?

Best,

Steve
gladius
Posts: 568
Joined: Tue Dec 12, 2006 10:10 am
Full name: Gary Linscott

Re: How to solve positions with mate-threats?

Post by gladius »

JBNielsen wrote:It is easier with the king at g1.
Dabbaba solves it in 30M nodes.
With the king on g1, GarbochessJS finds it in 300k nodes. Even the harder position, it finds it in 10M nodes. For comparison, Stockfish finds Rxd3 in the harder position in 3M nodes.

GarbochessJS is using LMR and razoring, but not futility pruning. Source is up here: http://forwardcoding.com/projects/ajaxc ... bochess.js.

Output:
Ply:8 Score:2545 Nodes:303758 NPS:160041 Rxd3 cxd3 Nxf6+ Rxf6 Bb3+ Rf7 Bxf7+ Kh8 Nxe5 d2 Bc4
JBNielsen
Posts: 267
Joined: Thu Jul 07, 2011 10:31 pm
Location: Denmark

Re: How to solve positions with mate-threats?

Post by JBNielsen »

Steve Maughan wrote:Monarch 1.7 is not doing anything special. And in general it is not especially good at tactics. It doesn't do LMR - maybe that helps in this situation?

Best,

Steve
Thanks.

But I wonder if the last moves with black checks are searched brute-force (what should trigger this?).
For me it looks like a quiescence-search, but that would have offered black a score before -,Rxf2+ so the later mate by white would be rejected.
JBNielsen
Posts: 267
Joined: Thu Jul 07, 2011 10:31 pm
Location: Denmark

Re: How to solve positions with mate-threats?

Post by JBNielsen »

Hi Lucas

Thanks for your informative post.

I assume you also are interested to know how fx Monarch can solve this so fast (and it should not even be particulary good at tactics!)....

Blacks last checks is probably also a big problem for DiscoCheck.