Page 1 of 1

### evaluating color agnostic terms

Posted: Tue Oct 15, 2013 2:12 pm
Hi everybody ,

suppose I got convinced my engine does better in very complex positions (wich it does not)
and I want my engine to prefer positions with many queens for example.
since the root_ply=1, I do the following in the eval:

//some_weight could be 10 for example (pawn=100, queen=1000),
//WQ and BQ are the queens bitboards of their respective color

Code: Select all

``````if &#40;ply&1&#41; &#123;
int qc = __popcount&#40;WQ | BQ&#41;;
score += qc * some_weight;
&#125; else &#123;
// do nothing &#40;wich might as well go without the "else" statement
// this means the opponent don't evaluate/care this feature
&#125;
``````
is the above code correct ?
Will my engine prefer positions with many queens with the above code?

best regards,
Alvaro

### Re: evaluating color agnostic terms

Posted: Tue Oct 15, 2013 3:51 pm
Why would you do this only for odd values of `ply'? You probably want to do it all the time, making sure the sign goes in the direction it has to go.

### Re: evaluating color agnostic terms

Posted: Tue Oct 15, 2013 10:18 pm
AlvaroBegue wrote:Why would you do this only for odd values of `ply'? You probably want to do it all the time, making sure the sign goes in the direction it has to go.
Hi Álvaro, thanks for your reply.
The reason I do it is because only my engine (at odd plies) cares about this particular feature, the opponent engine (at even plies) isn't supposed to evaluate it. So whatever color my engine plays it will allways be at odd plies, since my root ply starts at 1.
Of course I'm not sure of my logic, that's why I'm asking.

best regards,
Alvaro

### Re: evaluating color agnostic terms

Posted: Tue Oct 15, 2013 10:33 pm
You seem to be confused about how the evaluation function is used by a minimax searcher. It might very well be that odd plies are those where it is your engine's turn to move, but in your search you have to evaluate positions with either player to move, and whether you are happier with more queens on the board or not has nothing to do with whose turn it is.

### Re: evaluating color agnostic terms

Posted: Wed Oct 16, 2013 10:28 pm
Cardoso wrote:
AlvaroBegue wrote:Why would you do this only for odd values of `ply'? You probably want to do it all the time, making sure the sign goes in the direction it has to go.
Hi Álvaro, thanks for your reply.
The reason I do it is because only my engine (at odd plies) cares about this particular feature, the opponent engine (at even plies) isn't supposed to evaluate it. So whatever color my engine plays it will allways be at odd plies, since my root ply starts at 1.
Of course I'm not sure of my logic, that's why I'm asking.

best regards,
Alvaro
If your engine is to move (odd ply in your case) then "many queens" gets a positive bonus. If the opponent is to move (even ply) then you still want the bonus for "many queens" for your engine but now it must be negative (a penalty) since you have the opponent's viewpoint and eval returns a value relative to the moving side. Your example misses the second part. It is important to have a symmetric evaluation function since anything else will confuse your search.

Whether using this type of evaluation feature is actually useful is another point which is out of scope here

Sven

### Re: evaluating color agnostic terms

Posted: Thu Oct 17, 2013 5:01 pm
Sven Schüle wrote:
Cardoso wrote:
AlvaroBegue wrote:Why would you do this only for odd values of `ply'? You probably want to do it all the time, making sure the sign goes in the direction it has to go.
Hi Álvaro, thanks for your reply.
The reason I do it is because only my engine (at odd plies) cares about this particular feature, the opponent engine (at even plies) isn't supposed to evaluate it. So whatever color my engine plays it will allways be at odd plies, since my root ply starts at 1.
Of course I'm not sure of my logic, that's why I'm asking.

best regards,
Alvaro
If your engine is to move (odd ply in your case) then "many queens" gets a positive bonus. If the opponent is to move (even ply) then you still want the bonus for "many queens" for your engine but now it must be negative (a penalty) since you have the opponent's viewpoint and eval returns a value relative to the moving side. Your example misses the second part. It is important to have a symmetric evaluation function since anything else will confuse your search.

Whether using this type of evaluation feature is actually useful is another point which is out of scope here

Sven
Thanks Sven for the explanation, it really makes sense now.

best regards,
Alvaro

### Re: evaluating color agnostic terms

Posted: Sat Oct 19, 2013 5:46 pm
Cardoso wrote:Hi everybody ,

suppose I got convinced my engine does better in very complex positions (wich it does not)
and I want my engine to prefer positions with many queens for example.
since the root_ply=1, I do the following in the eval:

//some_weight could be 10 for example (pawn=100, queen=1000),
//WQ and BQ are the queens bitboards of their respective color

Code: Select all

``````if &#40;ply&1&#41; &#123;
int qc = __popcount&#40;WQ | BQ&#41;;
score += qc * some_weight;
&#125; else &#123;
// do nothing &#40;wich might as well go without the "else" statement
// this means the opponent don't evaluate/care this feature
&#125;
``````
is the above code correct ?
Will my engine prefer positions with many queens with the above code?

best regards,
Alvaro
If you want complex positions, you might want to try something like:

Code: Select all

``````  bitboard AttackedPieces = &#40;WhiteAttacks & BlackPieces&#41; | &#40;BlackAttacks & WhitePieces&#41;;
int NumberOfAttackedPieces = popcount&#40;AttackedPieces&#41;;

// assume score from white point of view
score += some_weight * &#40;programIsWhite ? NumberOfAttackedPieces &#58; -NumberOfAttackedPieces&#41;;
``````

### Re: evaluating color agnostic terms

Posted: Sun Nov 10, 2013 12:46 am
Cardoso wrote:Hi everybody ,

suppose I got convinced my engine does better in very complex positions (wich it does not)
and I want my engine to prefer positions with many queens for example.
since the root_ply=1, I do the following in the eval:

//some_weight could be 10 for example (pawn=100, queen=1000),
//WQ and BQ are the queens bitboards of their respective color

Code: Select all

``````if &#40;ply&1&#41; &#123;
int qc = __popcount&#40;WQ | BQ&#41;;
score += qc * some_weight;
&#125; else &#123;
// do nothing &#40;wich might as well go without the "else" statement
// this means the opponent don't evaluate/care this feature
&#125;
``````
is the above code correct ?
Will my engine prefer positions with many queens with the above code?

best regards,
Alvaro
This probably is not how you would want to handle this. Normally you would want to add incentives and bonus only at evaluation time.

So at evaluation time you would want something like this:

int x = pop_count( wq | bq );

score[computers_color] += x * some_weight;

It's neater to keep 2 separate scores, one for white and one for black and then when you return from the evaluation function you sum them - and of course make sure you are expressing the score from the proper side.

Basically this is called asymmetrical evaluation, where you score the computers side differently.

Don

### Re: evaluating color agnostic terms

Posted: Sun Nov 10, 2013 4:54 pm
Cardoso wrote:Hi everybody ,

suppose I got convinced my engine does better in very complex positions (wich it does not)
and I want my engine to prefer positions with many queens for example.
since the root_ply=1, I do the following in the eval:

//some_weight could be 10 for example (pawn=100, queen=1000),
//WQ and BQ are the queens bitboards of their respective color

Code: Select all

``````if &#40;ply&1&#41; &#123;
int qc = __popcount&#40;WQ | BQ&#41;;
score += qc * some_weight;
&#125; else &#123;
// do nothing &#40;wich might as well go without the "else" statement
// this means the opponent don't evaluate/care this feature
&#125;
``````
is the above code correct ?
Will my engine prefer positions with many queens with the above code?

best regards,
Alvaro
Since you asked me to look, first an assumption... namely that you want the queens to stay on to lead to more complications? If that is the case, you need an asymmetric evaluation term. The ply&1 doesn't seem like the right way.

In your evaluation, you probably want something like this, using pseudo-code:

q_bonus = 0;
if (program_is_playing_white) {
q_bonus = PopCnt(white_queens) * queen_bonus;
} else
q_bonus = -PopCnt(black_queens) * queen_bonus;

Later:

score += q_bonus;

This assumes you compute score from white POV and then at the end you do something like:

return (wtm) ? score : -score;

If I didn't blow the above, it should add a bonus if your program has one or more queens, anywhere that an evaluation is done.

I wouldn't write the code quite as above, but it is easier to read than trying to condense it using a conditional assignment. The "q_bonus" is relative to the side your program is playing. If white, the bonus is + for each white queen, if black, the bonus is - for each black queen (making the bonus for white POV.