Newbie's questios about qsearch

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
pocopito
Posts: 238
Joined: Tue Jul 12, 2011 1:31 pm

Newbie's questios about qsearch

Post by pocopito »

Hi all

Just two questions related to qsearch, trying to get my ideas clear. Let's assume we have a qsearch like the one from Bruce Moreland's site:

Code: Select all

int Quies(int alpha, int beta)

{
    val = Evaluate();
    if (val >= beta)
        return beta;
    if (val > alpha)
        alpha = val;
    GenerateGoodCaptures();
    while (CapturesLeft()) {
        MakeNextCapture();
        val = -Quies(-beta, -alpha);
        UnmakeMove();
        if (val >= beta)
            return beta;
        if (val > alpha)
            alpha = val;
    }
    return alpha;
}
The questions are:

1- How should work the sign of the score returned by the Evaluate function in order to Quies to work properly? (Be positive or negative depending on the side to move? The same sign always for the same side?...)

2 - An engine with an alpha-beta search that calls Quies in the leaf nodes, playing white being set at 1 ply depth, after the moves 1-Nc3, d5, should be capable to avoid the at one ply best Nd5?

Thanks in advance regards

E Diaz
Two first meanings of the dutch word "leren":
1. leren [vc] (learn, larn, acquire) acquire or gain knowledge or skills.
2. leren [v] (teach, learn, instruct) impart skills or knowledge to.
mar
Posts: 2665
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Newbie's questios about qsearch

Post by mar »

pocopito wrote:Hi all

Just two questions related to qsearch, trying to get my ideas clear. Let's assume we have a qsearch like the one from Bruce Moreland's site:

Code: Select all

int Quies(int alpha, int beta)

{
    val = Evaluate();
    if (val >= beta)
        return beta;
    if (val > alpha)
        alpha = val;
    GenerateGoodCaptures();
    while (CapturesLeft()) {
        MakeNextCapture();
        val = -Quies(-beta, -alpha);
        UnmakeMove();
        if (val >= beta)
            return beta;
        if (val > alpha)
            alpha = val;
    }
    return alpha;
}
The questions are:

1- How should work the sign of the score returned by the Evaluate function in order to Quies to work properly? (Be positive or negative depending on the side to move? The same sign always for the same side?...)

2 - An engine with an alpha-beta search that calls Quies in the leaf nodes, playing white being set at 1 ply depth, after the moves 1-Nc3, d5, should be capable to avoid the at one ply best Nd5?

Thanks in advance regards

E Diaz
Hi,

since this is negamax, you need the eval from the point of view of the side to move. Which means that you simply negate resulting evaluation if side to move is black.

Martin
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Newbie's questios about qsearch

Post by Sven »

mar wrote:since this is negamax, you need the eval from the point of view of the side to move. Which means that you simply negate resulting evaluation if side to move is black.
Yes, and to be even more perfect:

Code: Select all

int Evaluate()
{
    int v = EvaluateFromWhiteViewpoint();
    return (sideToMove == White) ? v : -v;
}
Sven
User avatar
pocopito
Posts: 238
Joined: Tue Jul 12, 2011 1:31 pm

Re: Newbie's questios about qsearch

Post by pocopito »

Thanks both for your clear answers.

I'm having a problem with qsearch and wanted to be sure of the very basic concepts.
Two first meanings of the dutch word "leren":
1. leren [vc] (learn, larn, acquire) acquire or gain knowledge or skills.
2. leren [v] (teach, learn, instruct) impart skills or knowledge to.
lucasart
Posts: 3241
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Newbie's questios about qsearch

Post by lucasart »

pocopito wrote: 1- How should work the sign of the score returned by the Evaluate function in order to Quies to work properly? (Be positive or negative depending on the side to move? The same sign always for the same side?...)

2 - An engine with an alpha-beta search that calls Quies in the leaf nodes, playing white being set at 1 ply depth, after the moves 1-Nc3, d5, should be capable to avoid the at one ply best Nd5?
1- score should be for the side to move. for example if it's white's turn and white is up a pawn, score should be +1 (or +100 or whatever scale you use)

2 - depth 0 actually. qsearch on Nc3 d5 should return zero (assuming material score in eval only) and chose the stand pat score and understand that Nxd5 is refuted by Qxd5
lucasart
Posts: 3241
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Newbie's questios about qsearch

Post by lucasart »

pocopito wrote:Thanks both for your clear answers.

I'm having a problem with qsearch and wanted to be sure of the very basic concepts.
Question for you: what exactly do you generate in GenerateGoodCaptures() ?
Also, you need to consider a special case: if the position is check, then you cannot stay with the stand pat score (it can even be check mate). In this case you need to generate all legal moves (check evasions) and not update alpha = max(alpha,eval), and return a mated score accordingly if there are no legal moves
mar
Posts: 2665
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Newbie's questios about qsearch

Post by mar »

A very good point. I would add that generating good captures only (SEE >=0 ) implies Nxd5 will not even be considered by qsearch.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Newbie's questios about qsearch

Post by Sven »

lucasart wrote:Also, you need to consider a special case: if the position is check, then you cannot stay with the stand pat score (it can even be check mate). In this case you need to generate all legal moves (check evasions) and not update alpha = max(alpha,eval), and return a mated score accordingly if there are no legal moves
This would only be needed when not using check extensions in main search, since only then qsearch could be called when being in check (unless you include checks in qsearch at its upper levels, in which case I would expect to have a special qsearchEvasion() function that is called instead of qsearch() whenever a checking move has been made).

Sven
lucasart
Posts: 3241
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Newbie's questios about qsearch

Post by lucasart »

Sven Schüle wrote:
lucasart wrote:Also, you need to consider a special case: if the position is check, then you cannot stay with the stand pat score (it can even be check mate). In this case you need to generate all legal moves (check evasions) and not update alpha = max(alpha,eval), and return a mated score accordingly if there are no legal moves
This would only be needed when not using check extensions in main search, since only then qsearch could be called when being in check (unless you include checks in qsearch at its upper levels, in which case I would expect to have a special qsearchEvasion() function that is called instead of qsearch() whenever a checking move has been made).

Sven
A capture can be a checking move too !?

And yes searching quiet checks in the qsearch is useful. After some testing I came to the conclusion that 1 quiet check is best (I'm sure this is all well known, Fruit does it, and probably Cray Blitz did it in the 80s already). But the improvement going from 0 to 1 is small. 2 checks or more was a regression in my testing (which is quite logical)

In terms of design, I think it's a very poor choice to have two distinct qsearch function, one only to handle positions in check. leads to a lot of code being repeated, hence risk of discrepancy (updating sth in one function not the other). I would say the same about having different functions for PV and non PV nodes and the likes.
User avatar
pocopito
Posts: 238
Joined: Tue Jul 12, 2011 1:31 pm

Re: Newbie's questios about qsearch

Post by pocopito »

lucasart wrote: Question for you: what exactly do you generate in GenerateGoodCaptures() ?
Actually I'm generating all the captures. Yes, I know it's not a good idea, but currently the problem is in some part of my code. That's why I was asking these so simple questions, to get sure I'm not wrong in some very basic concept.
Two first meanings of the dutch word "leren":
1. leren [vc] (learn, larn, acquire) acquire or gain knowledge or skills.
2. leren [v] (teach, learn, instruct) impart skills or knowledge to.