SF search inconsistency

Discussion of chess software programming and technical issues.

Moderator: Ras

Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

SF search inconsistency

Post by Ralph Stoesser »

In this position (white wins)
[d]8/6QP/8/8/5k2/8/8/K2q4 w - - 0 1
SF default shows drawish score at depth 9 and 12.

If I disable pruning (always return false in ok_to_prun()) I see a 0.00 score at depth 25, 26 and 27. If I additionally disable razoring I see 0.00 score at depth 18 and 19.

But if I only remove this code in qsearch()
search.cpp, line 1657

Code: Select all

    if (bestValue >= beta)
    {
        // Store the score to avoid a future costly evaluation() call
        if (!isCheck && !tte && ei.futilityMargin[pos.side_to_move()] == 0)
            TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_EV_LO, Depth(-127*OnePly), MOVE_NONE);

        return bestValue;
    }
I see no more wrong drawish scores in this position. Also it seems that removing this part doesn't make SF play weaker, rather the other way round. (+315, -296, =1038, @1 min/game in favor of the change).

I have not much time at the moment to analyse and debug SF, so I just write what I've found so far.

Any thoughts about this issue?
User avatar
Eelco de Groot
Posts: 4669
Joined: Sun Mar 12, 2006 2:40 am
Full name:   Eelco de Groot

Re: SF search inconsistency

Post by Eelco de Groot »

Ralph Stoesser wrote:In this position (white wins)
[d]8/6QP/8/8/5k2/8/8/K2q4 w - - 0 1
SF default shows drawish score at depth 9 and 12.

If I disable pruning (always return false in ok_to_prun()) I see a 0.00 score at depth 25, 26 and 27. If I additionally disable razoring I see 0.00 score at depth 18 and 19.

But if I only remove this code in qsearch()
search.cpp, line 1657

Code: Select all

    if (bestValue >= beta)
    {
        // Store the score to avoid a future costly evaluation() call
        if (!isCheck && !tte && ei.futilityMargin[pos.side_to_move()] == 0)
            TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_EV_LO, Depth(-127*OnePly), MOVE_NONE);

        return bestValue;
    }
I see no more wrong drawish scores in this position. Also it seems that removing this part doesn't make SF play weaker, rather the other way round. (+315, -296, =1038, @1 min/game in favor of the change).

I have not much time at the moment to analyse and debug SF, so I just write what I've found so far.

Any thoughts about this issue?
The position seems too difficult without tablebases to base any changes in qsearch on. After 1. Kb2 it is Mate in 44 moves but the other possible move 1. Ka2 only is a draw. So it is a very narrow path to victory and 44 moves is of course beyond the search horizon. I would look at the repetition code first instead of at the Stand Pat rule because that is rather basic to qsearch. Qsearch is a basic feature of Razoring too so the problem could be there somewhere. Or in the static evaluation. I don't think this result is significant, the result without the code is not worse but it does not really tell you if the draw scores are really a problem or are directly related to this piece of code. I think it is too easy to just skip some search code like the Stand Pat rule based on one position, that is, I do think it is worthwhile code but maybe just not working here in conjunction with other pieces of search or eval.

I see one 0.00 score at the moment:

[d]8/6QP/8/8/5k2/8/8/K2q4 w - -

Engine: Rainbow Serpent 1.7.1s(dc) Build 052 (Athlon 2009 MHz, 256 MB)
by Tord Romstad, Marco Costalba, Joona Kiiski

1.00 0:00 +3.22 1.Kb2 (55) 0

2.00 0:00 +3.23 1.Kb2 Qd2+ 2.Kb3 (207) 0

3.00 0:00 +3.43 1.Kb2 Qd2+ 2.Kb3 Qd3+ 3.Kb4 Qd2+
4.Kc5 Qa5+ 5.Kd6 (19.265) 68

4.00 0:00 +3.87 1.Kb2 Qd2+ 2.Kb3 Qd3+ 3.Kb4 Qd6+
4.Kc4 Qe6+ 5.Kc5 (25.593) 86

5.00 0:00 +3.71 1.Kb2 Qd2+ 2.Kb3 Qd3+ 3.Kb4 Qd6+
4.Kc4 Qc6+ 5.Kd4 Qd6+ 6.Kc3 Qc6+
7.Kd4 (32.183) 103

6.00 0:00 +3.55 1.Kb2 Qd2+ 2.Kb3 Qd3+ 3.Kb4 Qd6+
4.Kb5 Qd5+ 5.Kb6 Qd6+ 6.Kb7 Qd5+
7.Kc7 (58.879) 164

7.00 0:00 +3.67 1.Kb2 Qd2+ 2.Kb3 Qd3+ 3.Kb4 Qd6+
4.Kb5 Qd5+ 5.Kb6 Qd6+ 6.Kb7 Qd5+
7.Kc7 Qc5+ 8.Kd8 (88.146) 226

8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 3.Ka4 Qc6+
4.Ka5 Qc5+ 5.Ka6 Qc6+ 6.Ka7 Qa4+
7.Kb7 Qb5+ 8.Kc8 Qa6+ 9.Qb7 Qf6
10.Qc7+ Kf3 11.Qc2 Ke3 12.Kd7 Qf7+
13.Kc6 Qe8+ 14.Kd5 (132.267.162) 872

20.01 3:03 +5.37 1.Kb2 Qd2+ 2.Kb3 Qd5+ 3.Ka4 Qc6+
4.Ka5 Qc5+ 5.Ka6 Qc6+ 6.Ka7 Qa4+
7.Kb7 Qb5+ 8.Kc8 Qa6+ 9.Qb7 Qf6
10.Qc7+ Kf3 11.Qc2 Ke3 12.Kd7 Qf7+
13.Kd8 Qf8+ 14.Kc7 (161.753.573) 881

21.01 4:42 +5.41 1.Kb2 Qd2+ 2.Kb3 Qd5+ 3.Kb4 Qd6+
4.Ka5 Qc5+ 5.Ka6 Qc6+ 6.Ka7 Qa4+
7.Kb7 Qb5+ 8.Kc8 Qa6+ 9.Qb7 Qf6
10.Qc7+ Kf3 11.Qc2 Ke3 12.Kd7 Qf7+
13.Kd8 Qf8+ 14.Kc7 (256.049.611) 907


best move: Ka1-b2 time: 4:47.391 min n/s: 906.712 nodes: 260.580.167


Eelco
Debugging is twice as hard as writing the code in the first
place. Therefore, if you write the code as cleverly as possible, you
are, by definition, not smart enough to debug it.
-- Brian W. Kernighan
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: SF search inconsistency

Post by Ralph Stoesser »

The repetition code seems ok to me. This was the first piece of code I have checked in this regard. Then I have considered late move pruning and razoring as the reason for the wrong draw scores. But they are not the reason for the wrong draw scores.

The stand pat rule in qsearch() seems a bit fishy to me in this kind of positions, because, as far as I understand, it would return many wrong draw scores coming from static eval in tactical postions where a regular quiescence search would easily detect the right non-draw score.
Last edited by Ralph Stoesser on Fri May 21, 2010 1:54 am, edited 1 time in total.
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: SF search inconsistency

Post by Ralph Stoesser »

(deleted)
User avatar
Eelco de Groot
Posts: 4669
Joined: Sun Mar 12, 2006 2:40 am
Full name:   Eelco de Groot

Re: SF search inconsistency

Post by Eelco de Groot »

Ralph Stoesser wrote:The repetition code seems ok to me. This was the first piece of code I have checked in this regard. Then I have considered late move pruning and razoring as the reason for the wrong draw scores. But they are not the reason for the wrong draw scores.

The stand pat rule in qsearch() seems a bit fishy to me in this kind of positions, because, as far as I understand, it would return many wrong draw scores coming from static eval in tactical postions where a regular quiescence search would easily detect the right non-draw score.
The idea behind Stand Pat is something like "I have the move and the static evaluation is already above beta. If I can't improve on this with any move I can make, tactical or otherwise, I must be in Zugzwang. But barring that there is no need to search further if static eval > beta is correct. I could only look at tactical moves anyway in qsearch so I have no sure way to detect Zugzwang. There may however be still some of my pieces en prise". Threat information helps but I am sure you can see something missing now in the code that you have examined yourself: ei.futilityMargin only contains King Safety, the threat information is not added to the futility margin. It is in Rainbow Serpent and I think it makes some difference.

Regards, Eelco
Debugging is twice as hard as writing the code in the first
place. Therefore, if you write the code as cleverly as possible, you
are, by definition, not smart enough to debug it.
-- Brian W. Kernighan
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: SF search inconsistency

Post by mcostalba »

Ralph Stoesser wrote: I see no more wrong drawish scores in this position. Also it seems that removing this part doesn't make SF play weaker, rather the other way round. (+315, -296, =1038, @1 min/game in favor of the change).
Thi is an unexpected result and if I found some testing time it would be interesting to try to verify it...although not top priority ;-)
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: SF search inconsistency

Post by mcostalba »

Eelco de Groot wrote:Threat information helps but I am sure you can see something missing now in the code that you have examined yourself: ei.futilityMargin only contains King Safety, the threat information is not added to the futility margin. It is in Rainbow Serpent and I think it makes some difference.
Hi Eelco,

I mostly agree on stand pat rationale that you exposed. But in the evaluation used to "stand pat" threats are _already_ accounted for.

Instead you suggest to add them also in ei.futilityMargin that is _not_ used by stand pat, so is an off-topic and has nothing to do with what we are discussing now. Or am I missing something ?

Regarding your idea to add threast to futility margin, it would be important first try to undertsand where this parameter is uded. And is used in qsearch and specifically in this line:

Code: Select all

futilityBase = staticValue + FutilityMarginQS + ei.futilityMargin[pos.side_to_move()];
From where we can see that, because of staticValue is the position evaluation that already includes the threats, if you add the threats score also to ei.futilityMargin you end up counting threats score two times in the final futilityBase value.

I don't know if your idea works or not, but for sure is not intuitive why it should work. IMHO it seems should not and if it does it means threats scores are much underestimated, so that your patch would be a (wrong) fix of an unrelated issue.

Marco
zamar
Posts: 613
Joined: Sun Jan 18, 2009 7:03 am

Re: SF search inconsistency

Post by zamar »

Ralph Stoesser wrote: Any thoughts about this issue?
It's a known fact that Transposition table does not work fully correctly when it comes to repetition draws. So it's not surprising that lesser use of TT could solve the problem for this specific position. How this affects in other positions is of course different issue...
Joona Kiiski
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: SF search inconsistency

Post by Ralph Stoesser »

zamar wrote:
Ralph Stoesser wrote: Any thoughts about this issue?
It's a known fact that Transposition table does not work fully correctly when it comes to repetition draws. So it's not surprising that lesser use of TT could solve the problem for this specific position. How this affects in other positions is of course different issue...
I don't understand what you mean. SF detect repetition by comparing position hash keys from the history stack of the current search line. Positions detected as draw by repetition will not end up in the TT. It would be an error to save positions detected as draw by repetition in the TT, because the draw score is not related to the position itself but to current search line only.

@Marco: After 3000 games the score is +555, -568, =1877. So SF default has taken the lead. I'll test until 5000 games, because I have nothing else to test at the moment.
zamar
Posts: 613
Joined: Sun Jan 18, 2009 7:03 am

Re: SF search inconsistency

Post by zamar »

Ralph Stoesser wrote: I don't understand what you mean. SF detect repetition by comparing position hash keys from the history stack of the current search line. Positions detected as draw by repetition will not end up in the TT. It would be an error to save positions detected as draw by repetition in the TT, because the draw score is not related to the position itself but to current search line only.
Draw scores detected in leaf nodes affect scores of parent-nodes, grand-parent nodes etc. and those get saved in TT. Those nodes get probed in some completely other line and provide false information. That is the problem, but there is no sane way to fix this without radically affecting performance of program.
Joona Kiiski