Should the evaluation function be symmetrical for both players?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

osvitashev
Posts: 6
Joined: Tue Sep 07, 2021 6:17 pm
Full name: Olexiy Svitashev

Should the evaluation function be symmetrical for both players?

Post by osvitashev »

Here are some amateurish musings...
Position evaluation function returns a scalar product of position features and their corresponding weights. For example, a rook is worth 500 points, so position evaluation might involve calculating the difference between how many rooks each player has and multiplying that by 500.

On one hand, it makes sense to have feature weights symmetrical for both players. If "d2-d4" is the best move for a given position, then swapping color of every piece on the board and changing the side player whose turn it is would not alter the best move. It would just be mirrored to "d7-d5".

On the other hand, White has the advantage of the first move, which results in significant skew of the outcome statistics in high-level play.
I have come across the maxim "White plays trying to win, black plays trying to draw". Which in my eyes would imply that players are very much asymmetrical and the base worth of a white rook should be somewhat different from that of a black rook. Same would follow for all the other weights being considered in the evaluation.

I am curious how to get out of this logical contradiction...

I realize that there might be a case for symmetrical function for the sake of simplicity and having fewer variables to tune.
Chessnut1071
Posts: 313
Joined: Tue Aug 03, 2021 2:41 pm
Full name: Bill Beame

Re: Should the evaluation function be symmetrical for both players?

Post by Chessnut1071 »

osvitashev wrote: Tue Sep 21, 2021 11:45 pm Here are some amateurish musings...
Position evaluation function returns a scalar product of position features and their corresponding weights. For example, a rook is worth 500 points, so position evaluation might involve calculating the difference between how many rooks each player has and multiplying that by 500.

On one hand, it makes sense to have feature weights symmetrical for both players. If "d2-d4" is the best move for a given position, then swapping color of every piece on the board and changing the side player whose turn it is would not alter the best move. It would just be mirrored to "d7-d5".

On the other hand, White has the advantage of the first move, which results in significant skew of the outcome statistics in high-level play.
I have come across the maxim "White plays trying to win, black plays trying to draw". Which in my eyes would imply that players are very much asymmetrical and the base worth of a white rook should be somewhat different from that of a black rook. Same would follow for all the other weights being considered in the evaluation.

I am curious how to get out of this logical contradiction...

I realize that there might be a case for symmetrical function for the sake of simplicity and having fewer variables to tune.
My objective is to find mate in the minimum possible moves. Using chess puzzles from 4-ply to 20-ply I developed an optimization function for both sides. That function is no where near symmetrical; however, check moves do carry the most significant weights for both sides. In ELO optimization there is no such thing as symmetry. If you optimize by openings and defense, most of the metrics are not included in both sets, let alone symmetrical.
I use minimum calls to the engine, not speed like nps. You can have a very fast engine and lousy evaluation. There is an optimum number of evaluation metrics which differs depending on opening. Symmetry schemmetry.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Should the evaluation function be symmetrical for both players?

Post by Rebel »

For some reason making the own queen 1% more worth than the opponent gave me elo.
90% of coding is debugging, the other 10% is writing bugs.
User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Should the evaluation function be symmetrical for both players?

Post by hgm »

Rebel wrote: Wed Sep 22, 2021 7:19 am For some reason making the own queen 1% more worth than the opponent gave me elo.
One would expect that to work only when your engine handles Queens better than the average opponent. That could of course very well be the case, but one could argue that this makes it a testing artifact.
Karlo Bala
Posts: 373
Joined: Wed Mar 22, 2006 10:17 am
Location: Novi Sad, Serbia
Full name: Karlo Balla

Re: Should the evaluation function be symmetrical for both players?

Post by Karlo Bala »

osvitashev wrote: Tue Sep 21, 2021 11:45 pm Here are some amateurish musings...
Position evaluation function returns a scalar product of position features and their corresponding weights. For example, a rook is worth 500 points, so position evaluation might involve calculating the difference between how many rooks each player has and multiplying that by 500.

On one hand, it makes sense to have feature weights symmetrical for both players. If "d2-d4" is the best move for a given position, then swapping color of every piece on the board and changing the side player whose turn it is would not alter the best move. It would just be mirrored to "d7-d5".

On the other hand, White has the advantage of the first move, which results in significant skew of the outcome statistics in high-level play.
I have come across the maxim "White plays trying to win, black plays trying to draw". Which in my eyes would imply that players are very much asymmetrical and the base worth of a white rook should be somewhat different from that of a black rook. Same would follow for all the other weights being considered in the evaluation.

I am curious how to get out of this logical contradiction...

I realize that there might be a case for symmetrical function for the sake of simplicity and having fewer variables to tune.
I think you are mixing a symmetrical evaluation with a symmetrical position. I don't know if there is a formal definition of the symmetrical evaluation, but I would define it as E(x) = -E(~x) where ~ is the flipping operator. It just means that if you flip the board together with the side to move you get a value of the same magnitude but with the opposite sign. It has almost nothing to do with a symmetrical position.

What you propose to score more for the side to move doesn't make the evaluation asymmetrical. You just decided to score one feature of the position (tempo). To make a true asymmetrical evaluation you should fix the sides and define for example Q=10 and q = 9 (as Rebel pointed out). Asymmetrical evaluation can heavily impact the style of the engine. If you score your pieces more than the opponent's pieces your program will avoid exchanges and vice versa. Like with the evaluation, it is possible to make the search asymmetrical. In the past, there were some famous engines with asymmetrical search. For example, Lang's engines tend to prune more for their own side, making the engine more solid, while Whittington's engines prune more for the opponent's side making the engine more aggressive.

Last, but not least, I think there is no such thing as a symmetrical position since one side has always a move at its disposal.
Best Regards,
Karlo Balla Jr.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Should the evaluation function be symmetrical for both players?

Post by Rebel »

hgm wrote: Wed Sep 22, 2021 11:01 am
Rebel wrote: Wed Sep 22, 2021 7:19 am For some reason making the own queen 1% more worth than the opponent gave me elo.
One would expect that to work only when your engine handles Queens better than the average opponent. That could of course very well be the case, but one could argue that this makes it a testing artifact.
Well, the elo came from self-play, that's why I said for some reason.
90% of coding is debugging, the other 10% is writing bugs.
Karlo Bala
Posts: 373
Joined: Wed Mar 22, 2006 10:17 am
Location: Novi Sad, Serbia
Full name: Karlo Balla

Re: Should the evaluation function be symmetrical for both players?

Post by Karlo Bala »

Rebel wrote: Wed Sep 22, 2021 11:48 am
hgm wrote: Wed Sep 22, 2021 11:01 am
Rebel wrote: Wed Sep 22, 2021 7:19 am For some reason making the own queen 1% more worth than the opponent gave me elo.
One would expect that to work only when your engine handles Queens better than the average opponent. That could of course very well be the case, but one could argue that this makes it a testing artifact.
Well, the elo came from self-play, that's why I said for some reason.
If there is an Elo difference then it is not the same engine. If it is not the same engine then it is not the self-play ;)
Best Regards,
Karlo Balla Jr.
dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: Should the evaluation function be symmetrical for both players?

Post by dangi12012 »

Of course it should be symmetrical.

Think about switching the colors and turning the board 180°. You end up with the same position again. In fact its not a bad idea to do that for the transposition table for every odd move since its the same position.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
PK
Posts: 893
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: Should the evaluation function be symmetrical for both players?

Post by PK »

All the Rodent personalities are based on asymmetric evaluation. A few are within 10 ELo to default. I wouldn't be surprised if there is an asymmetric setting that beats default, haven't found it in 10 years though.
User avatar
yurikvelo
Posts: 710
Joined: Sat Dec 06, 2014 1:53 pm

Re: Should the evaluation function be symmetrical for both players?

Post by yurikvelo »

osvitashev wrote: Tue Sep 21, 2021 11:45 pm I am curious how to get out of this logical contradiction...
To my understanding (I'm not a programmer or math scientist), rules of chess are highly assymetrical.
For symmetrical evaluation, you need rules to be symmetrical. At least this 3 rules (may be some more):

1) a king in check may leave in check, if his side immediately gives check to attacking kingdom (allow 2 kings to be in check simultaneously). OR completely remove check rule.
2) if king is mated and opponent king can be mated in 1 turn - it is draw (allow 2 kings to be mated simultaneously)
3) abandone castling requirment "The king does not pass through a square that is attacked by an enemy piece" (Attacking enemy empty squares cannot prevent his right for castling)