Are captures best only ~60% of the time?

Discussion of chess software programming and technical issues.

Moderator: Ras

rdhoffmann
Posts: 54
Joined: Fri Apr 21, 2023 3:46 pm
Full name: Richard Hoffmann

Are captures best only ~60% of the time?

Post by rdhoffmann »

I did some analysis on a small set of midgame positions, gathered from nodes once my engine reaches q-search. So some crap may be already filtered out at this point.

Now it appears that captures are only best about 60% of the time. Is that correct or did I make a mistake somewhere?

If true, there may be room for improvement when it comes to move ordering. I mostly use MVV right now but have dabbled with SEE and various heuristics (with somewhat limited success).
JoAnnP38
Posts: 253
Joined: Mon Aug 26, 2019 4:34 pm
Location: Clearwater, Florida USA
Full name: JoAnn Peeler

Re: Are captures best only ~60% of the time?

Post by JoAnnP38 »

There are other moves to consider as generally being more forcing than truly quiet moves, like: checks, promotions, pins, or pawn moves that threaten an enemy piece or advance to the 7th rank. And then you have to consider killer moves and other quiet moves that have shown to create gains of alpha or even cutoffs in the past. I’m sure someone who is a better chess player can even come up with more categories, but these are the ones that I use and have had some success.
rdhoffmann
Posts: 54
Joined: Fri Apr 21, 2023 3:46 pm
Full name: Richard Hoffmann

Re: Are captures best only ~60% of the time?

Post by rdhoffmann »

Exactly JoAnn, I do some very simple stuff like prioritize checks but overall I have been far too focussed on capture moves it seems.

There is another implication here. Since I gathered my data from q-search (which is mostly or entirely captures), I wonder if the focus on captures is even the optimal strategy. Perhaps it is, simply because captures can be generated efficiently even without magic bitboards, or maybe because we want to end q-search some day and captures do the trick :wink: But just theoretically speaking, it would mean we make the wrong move 40% of the time if my data is any good.
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Are captures best only ~60% of the time?

Post by hgm »

Two issues:

1) 60% is enormously large, as only about 10% of the moves are captures. So that means a randomly picked capture on average will have a 6x larger probability of being the best move than a randomly picked non-capture. This is why engines focus on captures.

2) 99.999% of all positions in the tree are not 'typical midgame positions'. In fact the typical position in the tree looks nothing like it; usually both sides have multiple hanging pieces, because one player (on move in the all moves) plays like a random mover (trying even the most idiotic things), while his opponent plays like a turn passer (doing only null moves instead of punishing all the blunders). So statistics on middle-game positions is meaningless; you would have to collect it for tree positions. And most likely for those the chances that a capture is best is much larger. I would not be surprised if in the overwhelming majority of the positions (where there still is a Queen) the best move is "capture the unprotected Queen".
User avatar
Bo Persson
Posts: 257
Joined: Sat Mar 11, 2006 8:31 am
Location: Malmö, Sweden
Full name: Bo Persson

Re: Are captures best only ~60% of the time?

Post by Bo Persson »

rdhoffmann wrote: Wed May 10, 2023 7:49 pm overall I have been far too focussed on capture moves it seems.
Not really. Captures are important, not only for finding the best move for one side, but also for finding a quick refutation for all of the opponents silly moves. There might be 40 of them, 38 of which are just bad.

The MVV/LVA will trim the search tree heavily.

What if I move this pawn?
Then I'll capture your queen.
Oh, what if I move this other pawn?
PxQ
Right, but I can move my knight.
PxQ
Then I move the knight to this other square
PxQ
...
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Are captures best only ~60% of the time?

Post by hgm »

Bo Persson wrote: Thu May 11, 2023 10:06 amWhat if I move this pawn?
Then I'll capture your queen.
Oh, what if I move this other pawn?
PxQ
Right, but I can move my knight.
PxQ
Then I move the knight to this other square
PxQ
...
The way you present this is more an illustration of how the killer heuristic works (try same move as what worked in sibbling node) than that it illustrates the order is good. Because there also are cases like

What if I move this pawn?
Then I'll capture your queen (PxQ). Oops, Pawn was pinned on my Queen, no luck.
Well, then I will capture your Rook (NxR). This works.
Oh, what if I move this other pawn?
PxQ. Oops!
NxR
Right, but I can move my knight.
PxQ. Oops!
NxR
Then I move the knight to this other square
PxQ. Oops!
NxR
...

So the question that really should be answered is: "why is it better to use a static order for the captures, while for the non-captures we try to learn from what we discovered in the sibbling as a killer?".

The point is that the difference between what the various captures achieve is very much larger than the typical difference between non-captures, because material is the dominant evaluation term. So statistically capturing a Queen works much more often as capturing a Pawn, and requires much less search to conclude that when they would both work. (So Q x protected Q is to be preferred over N x unprotected P, as in the latter case you have to deal with all kind of mischieve the opponent Queen will endeavor in, while in the former case it is no longer there, and the P will likely still be unprotected.) And captures are very often specific refutations to the previous move, and might not even have been possible after other moves. If the previous move exposed a Queen, you don't want to miss the opportunity to grab the opportunity for a cheap cutoff:

What if I move this pawn?
Then I'll capture your knight (PxN). Hard work, though, as I was already a Knight behind in this branch.
Oh, what if I move this other pawn?
PxN. Hard work.
Right, but I can move my queen.
PxQ. Piece of cake!
Then I move the queen to this other square
PxN. Hard work.
...
rdhoffmann
Posts: 54
Joined: Fri Apr 21, 2023 3:46 pm
Full name: Richard Hoffmann

Re: Are captures best only ~60% of the time?

Post by rdhoffmann »

hgm wrote: Thu May 11, 2023 9:13 am Two issues:

1) 60% is enormously large, as only about 10% of the moves are captures. So that means a randomly picked capture on average will have a 6x larger probability of being the best move than a randomly picked non-capture. This is why engines focus on captures.
That is a great point hgm! I just wonder, if we had great move ordering, whether it would be feasible to just make a few supposedly best moves in quiescence, whether captures or not. As JoAnn pointed out, there may be quiet moves that are instantly winning, like pinning the queen with a bishop or forking the queen with a knight. Now perhaps NNUE or HCE takes care of at least the most obvious wins in the top engines, not sure.
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Are captures best only ~60% of the time?

Post by hgm »

rdhoffmann wrote: Thu May 11, 2023 11:37 am That is a great point hgm! I just wonder, if we had great move ordering, whether it would be feasible to just make a few supposedly best moves in quiescence, whether captures or not. As JoAnn pointed out, there may be quiet moves that are instantly winning, like pinning the queen with a bishop or forking the queen with a knight. Now perhaps NNUE or HCE takes care of at least the most obvious wins in the top engines, not sure.
The problem with this is that 'instantly' is a relative notion here. ;)

When you capture a King, that wins instantly. When you merely pin or fork a Queen with a minor you would have to search many extra ply ahead before you gain anything. QS only searches moves if the current evaluation is below beta (otherwise the stand-pat would already have produced a cutoff). When the non-capturing pin doesn't really raise the evaluation more than a typical non-capture, the opponent would make it fail low by standing pat, even if it was indeed 'instantly winning'. To recognize the pin as a cut move, the daughter node would have to recognize that his Queen is under attack, that this attack is somehow problematic (because it is a pin, and the pinning piece is low-value and protected), and then suppress stand-pat and give an extension instead. One should hope that it then only extends the moves that would actually stand a chance of solving the pin, and not randomly try every non-capture. (Similar to check-evasion.)

So I suppose that 'instantly' should really mean: "so the static evaluation can see it". Perhaps NNUE can do this to some extent. But just awarding high score for a Bishop that pins a Queen isn't enough. Perhaps the opponent can simply interpose a Pawn, and then performing the pinning move is a dud. So to prevent the evaluation counts itself rich by adding bonuses for pins and forks, (which then suppress the score for the pinned or forked player so much that he cannot stand pat), it would also have to enable possible non-capture remedies to the detected problem, and search those to determine whether they are sound. (E.g. the Pawn that can be interposed might have been the only protector of a Bishop that was under attack by a Rook.)

In summary: it takes a large search effort before this can result in a score change, and it is rare it can be done. And even rarer it is the only thing that can be done; almost always it will be simpler to just capture that unprotected Queen.
rdhoffmann
Posts: 54
Joined: Fri Apr 21, 2023 3:46 pm
Full name: Richard Hoffmann

Re: Are captures best only ~60% of the time?

Post by rdhoffmann »

Thank you hgm for the detailed explanation- makes perfect sense.

How about the main search part though? Here advanced move order heuristics could make sense right? Since there is still a lot to come.
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Are captures best only ~60% of the time?

Post by hgm »

If there is really much to come you would have seen the gain resulting from the pin or fork already in the previous iteration, and it would be hash move. A remaining depth d of 2 would be enough to see that the pin gains a Queen by brute force; all moves would be tried at d=1, and if none of those can prevent it BxQ would be tried in QS. A Knight fork on K+Q would even be seen at d=1, because of check extension.

So the question is whether it would pay to see the pin already when the remaining depth is 1, so it can be hash move at d=2. But that means you have to recognize that the loss of the pinned Queen in unavoidable at d=0. Since that is QS, the arguments given before still apply.

And if the required 'unavoidable loss detection' would slow you down so much that you lose 1 ply of depth, you still don't see the pin any earlier timewise. While there are probably lots of things you did not have static recognizers for which you then don't see.