bug?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

flok

Re: bug?

Post by flok »

Evert wrote:
flok wrote:
hgm wrote:Well, if c6-e7 increased alpha to -110 (which is reasonable) then it becomes best move at that point. If Qxa2 later scores also -110 it is a fail low, and thus an upper bound only. (And indeed its true score should be somewhere around -900.) It should never have been able to replace c6-e7 as best move in the root,and get played.
So the root, the code around search() should only update the score if new_score > alpha?
The score at the root is the score for the best move. This should be an exact score, not a bound.

So it depends a bit on how your search is ordered. If you don't iterate over root moves in your root search, then the result of search() is just the score for the node. If that is not within bounds, you need to research with a wider window.
That I understand. And that is also what happens: the second time depth 9 is searched, beta is set to infinite (alpha -160, beta 10000). So if it returns -110 then that is in bounds.

So I don't follow what is going wrong then. We went through the whole search but what to conclude from it is, I don't see.
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: bug?

Post by hgm »

flok wrote:So the root, the code around search() should only update the score if new_score > alpha?
Searching the root is not different from searching any other node: every move that scores <= alpha is completely ignored, and every move that scores > alpha leads to increasing alpha correspondingly.
flok

Re: bug?

Post by flok »

hgm wrote:
flok wrote:So the root, the code around search() should only update the score if new_score > alpha?
Searching the root is not different from searching any other node: every move that scores <= alpha is completely ignored, and every move that scores > alpha leads to increasing alpha correspondingly.
With the root I don't mean the routine where it goes through the moves of the root, I mean the function that calls that. The function performing the aspiration windowing.
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: bug?

Post by hgm »

Well, none of my engines has such a function, (i.e. Search() is called directly from main(), if the command-processing loop there sees it is the engine's turn), so I have no idea how it would look.

Where it goes wrong is in the function that loops over moves, where at some point the move Qxa2 is promoted to 'best move' (and subsequently played) despite the fact that it failed low (i.e. scored equal to alpha, which was raised to -110 by c6e7). It should have been ignored, as any low-failing move, and have left c6e7 as best move, so that that would have been played.
flok

Re: bug?

Post by flok »

Hmm. Then I think I have an idea what is wrong.

Code: Select all

bool evalResult&#40;const int val, int *const restrict bestVal, int *const restrict alpha, int *const restrict beta, bool *const betaCutOff&#41;
&#123;
        bool useMove = false;

        if &#40;val > *bestVal&#41;
        &#123;
                *bestVal = val;
                useMove = true;
        &#125;

        if &#40;val > *alpha&#41;
        &#123;
                *alpha = val;

                if &#40;val >= *beta&#41;
                        *betaCutOff = true;
        &#125;

        return useMove;
&#125;
I think this needs to be:

Code: Select all

bool evalResult&#40;const int val, int *const restrict bestVal, int *const restrict alpha, int *const restrict beta, bool *const betaCutOff&#41;
&#123;
        bool useMove = false;

        if &#40;val > *bestVal&#41;
                *bestVal = val;

        if &#40;val > *alpha&#41;
        &#123;
                *alpha = val;
                useMove = true;

                if &#40;val >= *beta&#41;
                        *betaCutOff = true;
        &#125;

        return useMove;
&#125;
useMove indicates if it should, well, use the move as a result.
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: bug?

Post by hgm »

Well, I don't know. Qxa2 should not be able to score betterthan bestVal,if c6e7 increased bestVal to -110.
flok

Re: bug?

Post by flok »

hgm wrote:Well, I don't know. Qxa2 should not be able to score betterthan bestVal,if c6e7 increased bestVal to -110.
Yes but due to move ordening Qxa2 is tried first.

first depth 9 attempt:

Code: Select all

START 15f0b8764a43cf81, a -160 b -110 &#58; r3k2r/p1p2p2/2n5/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R b KQkq - 0 18, black

trying c6-e7

info depth 9 seldepth 27 score cp -110 time 2469 nodes 199764 pv c6e7/-110/search 15f0b8764a43cf81 "r3k2r/p1p2p2/2n5/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R b KQkq - 0 18" | c3c4/110/search 3cf586c79cee9b23 "r3k2r/p1p1np2/8/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R w KQkq - 1 19" | a5a4/-110/search 3ae7f2e982ef0378 "r3k2r/p1p1np2/8/qp1Pp1pp/2P1P3/1Q2NPPb/P2B3P/R3K2R b KQkq - 0 19" | b3a4/110/search d6dec693171db8ab "r3k2r/p1p1np2/8/1p1Pp1pp/q1P1P3/1Q2NPPb/P2B3P/R3K2R w KQkq - 1 20" | b5a4/-110/search ab12014f2581d757 "r3k2r/p1p1np2/8/1p1Pp1pp/Q1P1P3/4NPPb/P2B3P/R3K2R b KQkq - 0 20" | a1b1/110/search 7e70d2d4e2062ecc "r3k2r/p1p1np2/8/3Pp1pp/p1P1P3/4NPPb/P2B3P/R3K2R w KQkq - 0 21" | c7c6/-95/search 39ddf9b4aa0243b5 "r3k2r/p1p1np2/8/B2Pp1pp/p1P1P3/4NPPb/P6P/R3K2R b KQkq - 1 21" | d5c6/95/search 41c2b5dd22628635 "r3k2r/p3np2/2p5/B2Pp1pp/p1P1P3/4NPPb/P6P/R3K2R w KQkq - 0 22"
second depth 9 attempt:

Code: Select all

START 15f0b8764a43cf81, a -160 b 10000 &#58; r3k2r/p1p2p2/2n5/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R b KQkq - 0 18, black

trying a5xa2 <---
trying a5xc3
trying a7-a6
trying f7-f6
trying f7-f5
trying b5-b4
trying g5-g4
trying h5-h4
trying c6-e7 <---
trying c6-b4
trying c6-d4
trying c6-b8
trying c6-d8
trying h3-g2
trying h3-f1
trying h3-g4
trying h3-f5
trying h3-e6
trying h3-d7
trying h3-c8
trying a8-b8
trying a8-c8
trying a8-d8
trying h8-h7
trying h8-h6
trying h8-g8
trying h8-f8
trying a5-a4
trying a5-a3
trying a5-b4
trying a5-a6
trying a5-b6
trying o-o-o
trying e8-d7
trying e8-e7
trying e8-d8
trying e8-f8
trying o-o

info depth 9 seldepth 28 score cp -110 time 3517 nodes 287066 pv a5a2/-110/search 15f0b8764a43cf81 "r3k2r/p1p2p2/2n5/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R b KQkq - 0 18" | a1a2/110/search bb79778ed9e44fb4 "r3k2r/p1p2p2/2n5/1p1Pp1pp/4P3/1QP1NPPb/q2B3P/R3K2R w KQkq - 0 19" | b5b4/-110/search a1bd4ada44bfd5ea "r3k2r/p1p2p2/2n5/1p1Pp1pp/4P3/1QP1NPPb/R2B3P/4K2R b Kkq - 0 19"
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: bug?

Post by hgm »

That contradicts what you said before, namely that c6e7 was tried first, and increased alpha.

Either c6e7 is tried first, raises alpha to -110, which then causes Qxa2 to fail low later at -110, or Qxa2 was tried first, while alpha was still at -160. In the latter case it is completely unexplained where the 110 came from against which the null move after Qxa2 Rxa2 b5b4 could fail high.
flok

Re: bug?

Post by flok »

hgm wrote:That contradicts what you said before, namely that c6e7 was tried first, and increased alpha.
Yes, the first time it tried depth 9. The next time it tried depth 9 (with the larger window) it tried a5xa2 first. Sorry for the confusion.
Either c6e7 is tried first, raises alpha to -110,
Yes and then the search is aborted because beta-c.o.

Code: Select all

START 15f0b8764a43cf81, a -160 b -110 &#58; r3k2r/p1p2p2/2n5/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R b KQkq - 0 18, black
trying c6-e7
ret with&#58; 15f0b8764a43cf81 -110 c6e7 9 r3k2r/p1p2p2/2n5/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R b KQkq - 0 18
info depth 9 seldepth 27 score cp -110 time 2447 nodes 199764 pv c6e7/-110/search 15f0b8764a43cf81 "r3k2r/p1p2p2/2n5/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R b KQkq - 0 18" | c3c4/110/search 3cf586c79cee9b23 "r3k2r/p1p1np2/8/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R w KQkq - 1 19" | a5a4/-110/search 3ae7f2e982ef0378 "r3k2r/p1p1np2/8/qp1Pp1pp/2P1P3/1Q2NPPb/P2B3P/R3K2R b KQkq - 0 19" | b3a4/110/search d6dec693171db8ab "r3k2r/p1p1np2/8/1p1Pp1pp/q1P1P3/1Q2NPPb/P2B3P/R3K2R w KQkq - 1 20" | b5a4/-110/search ab12014f2581d757 "r3k2r/p1p1np2/8/1p1Pp1pp/Q1P1P3/4NPPb/P2B3P/R3K2R b KQkq - 0 20" | a1b1/110/search 7e70d2d4e2062ecc "r3k2r/p1p1np2/8/3Pp1pp/p1P1P3/4NPPb/P2B3P/R3K2R w KQkq - 0 21" | c7c6/-95/search 39ddf9b4aa0243b5 "r3k2r/p1p1np2/8/B2Pp1pp/p1P1P3/4NPPb/P6P/R3K2R b KQkq - 1 21" | d5c6/95/search 41c2b5dd22628635 "r3k2r/p3np2/2p5/B2Pp1pp/p1P1P3/4NPPb/P6P/R3K2R w KQkq - 0 22"
and the 2nd time it did depth 9:

Code: Select all

START 15f0b8764a43cf81, a -160 b 10000 &#58; r3k2r/p1p2p2/2n5/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R b KQkq - 0 18, black
trying a5xa2
trying a5xc3
trying a7-a6
trying f7-f6
trying f7-f5
trying b5-b4
trying g5-g4
trying h5-h4
trying c6-e7
trying c6-b4
trying c6-d4
trying c6-b8
trying c6-d8
trying h3-g2
trying h3-f1
trying h3-g4
trying h3-f5
trying h3-e6
trying h3-d7
trying h3-c8
trying a8-b8
trying a8-c8
trying a8-d8
trying h8-h7
trying h8-h6
trying h8-g8
trying h8-f8
trying a5-a4
trying a5-a3
trying a5-b4
trying a5-a6
trying a5-b6
trying o-o-o
trying e8-d7
trying e8-e7
trying e8-d8
trying e8-f8
trying o-o
ret with&#58; 15f0b8764a43cf81 -110 a5a2 9 r3k2r/p1p2p2/2n5/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R b KQkq - 0 18
info depth 9 seldepth 28 score cp -110 time 3479 nodes 287066 pv a5a2/-110/search 15f0b8764a43cf81 "r3k2r/p1p2p2/2n5/qp1Pp1pp/4P3/1QP1NPPb/P2B3P/R3K2R b KQkq - 0 18" | a1a2/110/search bb79778ed9e44fb4 "r3k2r/p1p2p2/2n5/1p1Pp1pp/4P3/1QP1NPPb/q2B3P/R3K2R w KQkq - 0 19" | b5b4/-110/search a1bd4ada44bfd5ea "r3k2r/p1p2p2/2n5/1p1Pp1pp/4P3/1QP1NPPb/R2B3P/4K2R b Kkq - 0 19"
which then causes Qxa2 to fail low later at -110, or Qxa2 was tried first, while alpha was still at -160. In the latter case it is completely unexplained where the 110 came from against which the null move after Qxa2 Rxa2 b5b4 could fail high.
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: bug?

Post by hgm »

So the question remains:

If the window for the second d=9 search was set at {-160, 10000}, how did beta after Qxa2 Rxa2 b5b4 get to be 110, so that the null move from there could refute b5b4 with a -110 score? Nothing was searched before Qxa2 that could have raised alpha from-160 to -110. So it must have happened at ply 3. What move was searched in the node after Qxa2 Rxa2 before b5b4 that would have raised alpha from -160 to -110?