Static exchange evaluation with promotion

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Jakob Progsch
Posts: 40
Joined: Fri Apr 16, 2021 4:44 pm
Full name: Jakob Progsch

Re: Static exchange evaluation with promotion

Post by Jakob Progsch »

Thinking about this some more I'm now wondering about order in linear SEE. This is one of those examples where you stand to gain more from taking with the more valuable piece first. Iterative SEE implementation however rely on working their way up the values. Are there cases where bottom up linear approach fails?

I couldn't figure out an example where it does. But is there some more "formal" argument why it's sufficient to consider out of order captures only on the first one?
gflohr
Posts: 57
Joined: Fri Jul 23, 2021 5:24 pm
Location: Elin Pelin
Full name: Guido Flohr

Re: Static exchange evaluation with promotion

Post by gflohr »

I have now implemented this solution to handle promotions:

If the initial move to be considered is a promotion, I set gain[0] accordingly before entering the loop.

Then I changed my move generator for the see() function to handle pawn hits on the 1st or 8th rank specially. The pawn hitting there get assigned a value of Q - P, and their captures are not generated first but between rook and queen captures. With that I could use the SEE algorithm unmodified. If the pawn on the pre-promotion rank hits and gets re-hit, the +Q and -Q just equal out. If it stays on the board, the promotion gain is taken into account.

That may be a rather odd solution but it is easy and efficient to implement and my limited chess knowledge tells me that pawns on the pre-promotion rank really have a value between a rook and a queen inside capture sequences. When I can hit with a rook, a pawn, or a queen on e7, I would first use the rook, then the pawn, and then the queen.

Details here: https://github.com/gflohr/lisco/blob/main/libchi/see.c

Search for "quawn" in the source file. That was a the stupid name I came up with for these pawns.
Jakob Progsch
Posts: 40
Joined: Fri Apr 16, 2021 4:44 pm
Full name: Jakob Progsch

Re: Static exchange evaluation with promotion

Post by Jakob Progsch »

The pawn hitting there get assigned a value of Q - P, and their captures are not generated first but between rook and queen captures.
I'm not convinced yet that this is correct. Don't you have to consider both orderings for those pawns?

Consider this position for example and the move Bxd8:
[d]2nN3r/2P2ppk/5b1p/2B5/8/7P/3R2PK/8 b - - 0 1

im using 100, 300, 300, 500, 1000 for the values

if you order the pawn capture after rooks you get (from blacks perspective):
Bxd8 +300
Rxd8 0
Rxd8 +500
cxd8 -400
which minmaxes to SEE = 0

If you order pawns first you get:
Bxd8 +300
cxd8 -900
Rxd8 +100
Rxd8 -400
which minmaxes to SEE = -400

So by ordering the pawn early white can force the second recapture and eventually gain more.
Jakob Progsch
Posts: 40
Joined: Fri Apr 16, 2021 4:44 pm
Full name: Jakob Progsch

Re: Static exchange evaluation with promotion

Post by Jakob Progsch »

Can this be fixed by adjusting the part in the wiki version that deals with pruning? Essentially you can stop the process once the line becomes non forcing by not flipping the sign between two moves. So that would be the point where you want to play your "trump card" which is the promotion capture?
gflohr
Posts: 57
Joined: Fri Jul 23, 2021 5:24 pm
Location: Elin Pelin
Full name: Guido Flohr

Re: Static exchange evaluation with promotion

Post by gflohr »

Jakob Progsch wrote: Mon Jul 26, 2021 12:24 pm
I'm not convinced yet that this is correct. Don't you have to consider both orderings for those pawns?
Yes, you are right. So it looks to me that all that has to be done for handling promotions is to increase the gain[d] in the code from the wiki by the value of a queen minus the value of a pawn, if the capture is done by a pawn on the promotion rank.

I couldn't find any position where the side to move can gain an immediate advantage by postponing the pawn capture.
gflohr
Posts: 57
Joined: Fri Jul 23, 2021 5:24 pm
Location: Elin Pelin
Full name: Guido Flohr

Re: Static exchange evaluation with promotion

Post by gflohr »

gflohr wrote: Mon Jul 26, 2021 3:18 pm I couldn't find any position where the side to move can gain an immediate advantage by postponing the pawn capture.
Essentially, the initial attacker would never hit on the promotion rank, when it can be re-hit by a pawn. The standing-pat is necessarily better in that. case.
Jakob Progsch
Posts: 40
Joined: Fri Apr 16, 2021 4:44 pm
Full name: Jakob Progsch

Re: Static exchange evaluation with promotion

Post by Jakob Progsch »

gflohr wrote: Mon Jul 26, 2021 3:35 pm Essentially, the initial attacker would never hit on the promotion rank, when it can be re-hit by a pawn. The standing-pat is necessarily better in that. case.
That may be the argument/"proof" I was looking for in my previous post. If the target square is threatened by a promoting pawn the threat of the promotion allows you to capture with anything on that square without repercussion since recapturing is always catastrophic?
gflohr
Posts: 57
Joined: Fri Jul 23, 2021 5:24 pm
Location: Elin Pelin
Full name: Guido Flohr

Re: Static exchange evaluation with promotion

Post by gflohr »

Jakob Progsch wrote: Mon Jul 26, 2021 3:49 pm That may be the argument/"proof" I was looking for in my previous post. If the target square is threatened by a promoting pawn the threat of the promotion allows you to capture with anything on that square without repercussion since recapturing is always catastrophic?
Yes. This looks like the proving position to me:

[d]3Q3k/2P2n2/8/8/8/8/8/7K b - - 0 1

Black cannot possibly lose less than a knight and cannot capture more than a queen. But the material balance from black's view for 1. ...Nxd7 2. cxd8=Q is: Q - N + P - Q which is already negative, -200 with your piece values.
gflohr
Posts: 57
Joined: Fri Jul 23, 2021 5:24 pm
Location: Elin Pelin
Full name: Guido Flohr

Re: Static exchange evaluation with promotion

Post by gflohr »

I have updated my code at https://github.com/gflohr/lisco/blob/main/libchi/see.c to use the regular capture ordering again.

One difference to the code in the wiki is that I use piece values instead of pieces in my capture generation so that I do not need lookups in the actual SEE implementation. And if the target rank is the 1st or the 8th, I use Q - P instead of P as the value of a pawn.

The advantage of this is that I there is no need to check for a possible promotion inside the loop of the SEE function. And the code is also less convoluted.
User avatar
Desperado
Posts: 879
Joined: Mon Dec 15, 2008 11:45 am

Re: Static exchange evaluation with promotion

Post by Desperado »

gflohr wrote: Fri Jul 23, 2021 10:58 pm Hi!

Trying to understand chess engine programming just for fun ...

... I have used test positions from https://github.com/jdart1/arasan-chess/ ... c/unit.cpp for testing my implementation of a static exchange evaluation function. I have problems understanding this position with white moving Rxc8:

[d]2r5/1P4pk/p2p1b1p/5b1n/BB3p2/2R2p2/P1P2P2/4RK2 w - - 0 1

My implementation returns a bishop's value but the test from Arasan expects a rook's value gain. Unless I terribly missed something here, my explanation is that Arasan "thinks" that re-hitting the rook with Bxc8 is a bad capture, presumably because it would result in a huge material gain for white by re-hitting with the pawn and promoting it to a queen.

My SEE implementation is based on the well-known code from https://www.chessprogramming.org/SEE_-_ ... _Algorithm. Even if I take the material gain by the promotion into account, I still end up with one bishop gain, essentially because the last hit is always the "speculative store" that gets ignored altogether, so that it doesn't matter what else the final pawn hit may win.

So what would be the correct static exchange evaluation for Rxc8 in this position with taking promotions into account?