Search for mate not found the "best" sequence.

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Luis Babboni
Posts: 464
Joined: Sat Feb 28, 2015 4:37 pm
Location: Argentina

Search for mate not found the "best" sequence.

Post by Luis Babboni »

I´m fighting in my engine project and I found something that at first seems to be a bug but now I think it could be simply a "not human" way to see :D

If I put my program searching for "mate in 3" that I found in literature for example, sometimes found a mate in 2!!! Well, it is possible cause the other side colaborate not choicing the best options.
That´s what I thought at the begining.

But now I think that may be, what happens is that for the other side, there is no difference in be checkmated in 3 or 2 moves if anyway at last it can´t do nothing to avoid it.

It is something known?

As allways, sorry if I´m asking a nonsense. I still consider me too new in this matters.

Thanks!
Robert Pope
Posts: 558
Joined: Sat Mar 25, 2006 8:27 pm

Re: Search for mate not found the "best" sequence.

Post by Robert Pope »

Yes, that is a problem. When your eval returns a checkmate score, you need to adjust it for the distance to the root, so it prefers a mate in 1 over a mate in 10. Otherwise, it may happily choose moves that give mate in 5, but never progress towards actually winning the game.
User avatar
Luis Babboni
Posts: 464
Joined: Sat Feb 28, 2015 4:37 pm
Location: Argentina

Re: Search for mate not found the "best" sequence.

Post by Luis Babboni »

Robert Pope wrote:Yes, that is a problem. When your eval returns a checkmate score, you need to adjust it for the distance to the root, so it prefers a mate in 1 over a mate in 10. Otherwise, it may happily choose moves that give mate in 5, but never progress towards actually winning the game.
Thanks!
In fact there is not exact my problem but so similar (my english is not good to explain myself).
What I saw in my engine is not that the side near to win choice a longer path than the shortest possible, is that the side near to lost do not choice the longest possible path but someone shorter!! :P

I think is the same problem at the end, and is not too bad in the case I actually have but yes in your example.... so I need to add to the evaluation importance to the number of moves to reach the checkmate.
Robert Pope
Posts: 558
Joined: Sat Mar 25, 2006 8:27 pm

Re: Search for mate not found the "best" sequence.

Post by Robert Pope »

Yes, it's the same thing I think, because both sides in alpha beta are using the same evaluation function. If the stronger side isn't programmed to always choose the fastest win, then similarly, the weaker side won't know to choose the slowest loss.
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Search for mate not found the "best" sequence.

Post by hgm »

Minimax (and thus alpha-beta, which is guaranteed to get the same result) does not care how long it takes to reach the same position, and thus often lead to undecisive behavior of the engine, which starts to aimlessly push pieces around, happy as long as these moves do not permanently destroy the prospects for the planned gain, but just postpone it. This does not only apply to mate, but for other gains as well.

In fact it is often worse for other gains, as the game continues after them. A mate is a mate, but gaining a Pawn in a leaf is a much less reliable gain then when you reach the position after the capture close to the root, so that you could search 4 ply beyond it to make sure there is no backlash. So it starts to intentionally postpone the gain of a poisoned Pawn (e.g. by interjecting checks) to just within the horizon, so it cannot see that it is poisoned, and keep imagining it will gain a Pawn by playing these checks.

A general solution is to award a delayed-loss bonus: when a node scores less than the current evaluation, (so that the side to move expects an unavoidable loss) you award a small bonus. If there are then many moves between the current position and the node where the loss materializes (i.e. where the static eval actually drops), the losing side gets this bonus many times.

You have to pre-adjust the search window, though, when you plan to add a bonus to the search result, to prevent this bonus could make the score cross the window boundary (thus falsely creating the impression it is another bound type than it actually is). In micro-Max the code for this looks like

Code: Select all

Search(alpha, beta)
{
  int curEval = Evaluate();
  if&#40;alpha < curEval&#41; alpha--;
  if&#40;beta <= curEval&#41; beta --;
  ...
  if&#40;bestScore < curEval&#41; bestScore++;
  return bestScore;
&#125;
User avatar
yurikvelo
Posts: 710
Joined: Sat Dec 06, 2014 1:53 pm

Re: Search for mate not found the "best" sequence.

Post by yurikvelo »

How Stockfish and Komodo select best PV among resolved to +250/-250 (+123/-123) with Syzygy?

Looking at multiPV, seem like captures and pawn advances get higher.
Is it accidental in my observations, or this is programmed (DTZ-penalty for Distance-To-Capture/Advance?)
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Search for mate not found the "best" sequence.

Post by hgm »

Playing by DTZ would go for the fastest Pawn push or capture. (Unfortunately also if it is the opponant that makes that capture, leading to a quick sacrificeof all the material not absolutely needed to win.) So if you derive the evaluation by adding a constant to the probed DTx of an EGT, the delayed-loss bonus would automatically be built into it.
User avatar
yurikvelo
Posts: 710
Joined: Sat Dec 06, 2014 1:53 pm

Re: Search for mate not found the "best" sequence.

Post by yurikvelo »

hgm wrote:Playing by DTZ would go for the fastest Pawn push or capture. (Unfortunately also if it is the opponant that makes that capture, leading to a quick sacrificeof all the material not absolutely needed to win.) So if you derive the evaluation by adding a constant to the probed DTx of an EGT, the delayed-loss bonus would automatically be built into it.
so how are PV-s sorted in Stockfish (or recent Gull) implementation?
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Search for mate not found the "best" sequence.

Post by hgm »

I have no idea. I don't know these engines other than by name. In a recent discussion about multi-PV in Stockfish it turned out to be pretty sick, though. It was not even able to provide the requested number of PVs, let alone sensibly sort them.