evaluating color agnostic terms

Discussion of chess software programming and technical issues.

Moderators: Harvey Williamson, Dann Corbit, hgm

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
Cardoso
Posts: 317
Joined: Thu Mar 16, 2006 6:39 pm
Location: Portugal
Full name: Alvaro Cardoso
Contact:

evaluating color agnostic terms

Post by Cardoso » 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 (ply&1) {
   int qc = __popcount(WQ | BQ); 
   score += qc * some_weight; 
} else {
  // do nothing (wich might as well go without the "else" statement
  // this means the opponent don't evaluate/care this feature
}
is the above code correct ?
Will my engine prefer positions with many queens with the above code?

best regards,
Alvaro

AlvaroBegue
Posts: 925
Joined: Tue Mar 09, 2010 2:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: evaluating color agnostic terms

Post by AlvaroBegue » 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.

Cardoso
Posts: 317
Joined: Thu Mar 16, 2006 6:39 pm
Location: Portugal
Full name: Alvaro Cardoso
Contact:

Re: evaluating color agnostic terms

Post by Cardoso » 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

AlvaroBegue
Posts: 925
Joined: Tue Mar 09, 2010 2:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: evaluating color agnostic terms

Post by AlvaroBegue » 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.

Sven
Posts: 3884
Joined: Thu May 15, 2008 7:57 pm
Location: Berlin, Germany
Full name: Sven Schüle
Contact:

Re: evaluating color agnostic terms

Post by Sven » 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

Cardoso
Posts: 317
Joined: Thu Mar 16, 2006 6:39 pm
Location: Portugal
Full name: Alvaro Cardoso
Contact:

Re: evaluating color agnostic terms

Post by Cardoso » 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

Jose Carlos
Posts: 151
Joined: Wed Mar 08, 2006 9:09 pm
Location: Murcia (Spain)

Re: evaluating color agnostic terms

Post by Jose Carlos » 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 (ply&1) {
   int qc = __popcount(WQ | BQ); 
   score += qc * some_weight; 
} else {
  // do nothing (wich might as well go without the "else" statement
  // this means the opponent don't evaluate/care this feature
}
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 = (WhiteAttacks & BlackPieces) | (BlackAttacks & WhitePieces);
  int NumberOfAttackedPieces = popcount(AttackedPieces);

  // assume score from white point of view
  score += some_weight * (programIsWhite ? NumberOfAttackedPieces : -NumberOfAttackedPieces);
__________________________
José Carlos Martínez Galán

User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 2:27 pm

Re: evaluating color agnostic terms

Post by Don » 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 (ply&1) {
   int qc = __popcount(WQ | BQ); 
   score += qc * some_weight; 
} else {
  // do nothing (wich might as well go without the "else" statement
  // this means the opponent don't evaluate/care this feature
}
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
Capital punishment would be more effective as a preventive measure if it were administered prior to the crime.

bob
Posts: 20920
Joined: Mon Feb 27, 2006 6:30 pm
Location: Birmingham, AL

Re: evaluating color agnostic terms

Post by bob » 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 (ply&1) {
   int qc = __popcount(WQ | BQ); 
   score += qc * some_weight; 
} else {
  // do nothing (wich might as well go without the "else" statement
  // this means the opponent don't evaluate/care this feature
}
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.

Post Reply