Problem with checkmate detection

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

eligolf
Posts: 114
Joined: Sat Nov 14, 2020 12:49 pm
Full name: Elias Nilsson

Re: Problem with checkmate detection

Post by eligolf »

The output from the position is as expected (see info on how I print the M2 thing below) and it makes the mate in 1:

Image

Yes I print them in my GUI. The scores are saved in the iterative deepening as shown before, then I print everything in the end.

If the score is less than -1e7 I put it as -M and put the depth-1 after the number. This is not exactly correct, but the issue is still the same. It should not save the mate score as the best score for depth 3, it should save the score corresponding to the given PV-line, which should be -3.40. Why is it outputting -1e9 instead from the negamax function?
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Problem with checkmate detection

Post by Ferdy »

eligolf wrote: Thu Jan 07, 2021 9:04 am The output from the position is as expected (see info on how I print the M2 thing below) and it makes the mate in 1:

Image

Yes I print them in my GUI. The scores are saved in the iterative deepening as shown before, then I print everything in the end.

If the score is less than -1e7 I put it as -M and put the depth-1 after the number. This is not exactly correct, but the issue is still the same. It should not save the mate score as the best score for depth 3, it should save the score corresponding to the given PV-line, which should be -3.40. Why is it outputting -1e9 instead from the negamax function?
Could you just print the score in centipawn? Let's see the score as iteration depth increases.
eligolf
Posts: 114
Joined: Sat Nov 14, 2020 12:49 pm
Full name: Elias Nilsson

Re: Problem with checkmate detection

Post by eligolf »

Absolutely, it it hard to read but it is 9:s all the way to the left.

The score isn't changing even at larger depths, it seems as if it gets stuck on some value. But somehow it ignores that during negamax and returns another move ordering (in my original case)

Image
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Problem with checkmate detection

Post by Ferdy »

eligolf wrote: Thu Jan 07, 2021 9:35 am Absolutely, it it hard to read but it is 9:s all the way to the left.

The score isn't changing even at larger depths, it seems as if it gets stuck on some value. But somehow it ignores that during negamax and returns another move ordering (in my original case)

Image
The score is correct. The scores from depth 2 to 5 are consistent and it is mate in 1 move. There is no problem with your engine. It is the problem of the GUI failing to convert properly the cp score into mate score.
eligolf
Posts: 114
Joined: Sat Nov 14, 2020 12:49 pm
Full name: Elias Nilsson

Re: Problem with checkmate detection

Post by eligolf »

In this case yes, but look at my original case where it gives the mate score at depth 3 just because a mate EXISTS at depth 3. But black can play other moves, and rightly does, and then the score output from negamax should be something else than the matescore right? Or am I misunderstanding something?
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Problem with checkmate detection

Post by Ferdy »

eligolf wrote: Thu Jan 07, 2021 9:43 am In this case yes, but look at my original case where it gives the mate score at depth 3 just because a mate EXISTS at depth 3. But black can play other moves, and rightly does, and then the score output from negamax should be something else than the matescore right? Or am I misunderstanding something?
Try it then let's see the cp score.

[d]3r1k1b/5p2/4np2/3R1N2/3P1NPP/2K1PP2/8/8 b - - 0 1
eligolf
Posts: 114
Joined: Sat Nov 14, 2020 12:49 pm
Full name: Elias Nilsson

Re: Problem with checkmate detection

Post by eligolf »

It gives the negative mate score for each depth after 3, -1e9 which is hard to see in the picture.

Image
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Problem with checkmate detection

Post by Ferdy »

eligolf wrote: Thu Jan 07, 2021 9:59 am It gives the negative mate score for each depth after 3, -1e9 which is hard to see in the picture.

Image
Right, something is wrong with the engine in this position as there is no mate.

One suspect would be your QS. Recheck evaluate() as it calls that function.

Code: Select all

evaluation = e.evaluate(self.gamestate)
For example have an assert check the returned value like,

Code: Select all

assert abs(eval_score) < 1e6
eligolf
Posts: 114
Joined: Sat Nov 14, 2020 12:49 pm
Full name: Elias Nilsson

Re: Problem with checkmate detection

Post by eligolf »

There is mate which it finds in a few of the branches, but it is like that score remains as the best score throughout after it has found it, which is strange.

The quiescence search returns only values in the range of around -360 to 360 after printing them all, which seems reasonable.

Thank you for taking the time btw, I have looked at this a few days myself without any progress :( Appreciate any new input.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Problem with checkmate detection

Post by Sven »

What is the meaning of the second parameter of is_square_attacked()? The color of the potential attacker? If so, you should check the call in negamax().
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)