Static exchange evaluation with promotion

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

gflohr
Posts: 57
Joined: Fri Jul 23, 2021 5:24 pm
Location: Elin Pelin
Full name: Guido Flohr

Static exchange evaluation with promotion

Post by gflohr »

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?
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Static exchange evaluation with promotion

Post by hgm »

Shouldn't this be R+B-P? (bxc8=Q Bxc8 Rxc8)? My interpretation of SEE of a given move is that it is the result of a Quiesence Search that only takes moves to a given square into account.
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 »

Maybe I used the wrong terminology?

The move given for the test is Rxc8, and so I considered 1. Rxc8 Bxc8 2. bxc8=Q. So the rooks are just exchanged (R - R), the bishop is hit, and the pawn stays on the board, and gets promoted to a queen. For me that is R - R + B.
User avatar
Bo Persson
Posts: 243
Joined: Sat Mar 11, 2006 8:31 am
Location: Malmö, Sweden
Full name: Bo Persson

Re: Static exchange evaluation with promotion

Post by Bo Persson »

gflohr wrote: Fri Jul 23, 2021 10:58 pm
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.
This seems like a very reasonable assumption.

When SSE is just focusing on a single square, it can "stop you" from getting the queen by not recapturing the rook. The fact that you could then easily do b7-b8Q is not part of the SSE, because it happens on a different square - so not considered.

A variation of the horizon effect. :wink:

Perhaps we need a rule that a position with a pawn on the 7th rank is not quiet enough to be statically decided, similar to not do SSE when the king is in check?
User avatar
lithander
Posts: 880
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: Static exchange evaluation with promotion

Post by lithander »

gflohr wrote: Fri Jul 23, 2021 10:58 pm My implementation returns a bishop's value but the test from Arasan expects a rook's value gain.
My implementation also returns 300 - the value of a bishop.

Code: Select all

public static int Evaluate(Board board, Move move)
{
	//Iterative SEE with alpha-beta pruning
	//Inspiration from: http://www.talkchess.com/forum3/viewtopic.php?topic_view=threads&p=310782&t=30905
	//Limitations: http://www.talkchess.com/forum3/viewtopic.php?f=7&t=40046&start=10#p419202
	Board position = new Board(board);
	int square = move.ToSquare;
	int eval = 0;
	SearchWindow window = SearchWindow.Infinite;
	while (true)
	{
		Piece attacker = position[move.FromSquare];
		Piece victim = position[square];
		eval -= PieceValue(victim);
		if (window.Cut(eval, victim.Color()))
			break;
		if (Pieces.Type(victim) == Piece.King)
			break;
		position.Play(move);
		int fromIndex = position.GetLeastValuableAttacker(square, victim.Color());
		if (fromIndex == -1)
		{
			window.Cut(eval, attacker.Color());
			break;
		}
		move = new Move(fromIndex, square);
	}
	int score = window.GetScore(board.SideToMove);
	return score;
}
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess
User avatar
lithander
Posts: 880
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: Static exchange evaluation with promotion

Post by lithander »

//EDIT: accidently double posted due to server problems
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess
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 "speculative" thing in wiki entry never made sense to me. Obviously you don't want to arbitrarily ignore the gains to be had from the last capture. I can't come up with a reason why you would?

I'm honestly baffled that this is even a discussion. After the entire exchange you'd end up with black losing a rook and a bishop and white losing a rook, a pawn and GAINING a queen. Why would you want to ignore the queen part? If you define see to only care about captures but not promotions then that's just a bad definition?
Pio
Posts: 334
Joined: Sat Feb 25, 2012 10:42 pm
Location: Stockholm

Re: Static exchange evaluation with promotion

Post by Pio »

Jakob Progsch wrote: Sat Jul 24, 2021 11:26 am The "speculative" thing in wiki entry never made sense to me. Obviously you don't want to arbitrarily ignore the gains to be had from the last capture. I can't come up with a reason why you would?

I'm honestly baffled that this is even a discussion. After the entire exchange you'd end up with black losing a rook and a bishop and white losing a rook, a pawn and GAINING a queen. Why would you want to ignore the queen part? If you define see to only care about captures but not promotions then that's just a bad definition?
+1
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Static exchange evaluation with promotion

Post by Sven »

Usually we only talk about SEE of given moves (usually captures but not necessarily restricted to those). In the given position, the SEE of the move b7xc8Q is the value of R+B-P because Black must capture the promoted queen. The SEE of the move Rxc8 is the value of a rook because Black must not recapture the rook. I see no way of any different interpretation. Getting "value of a bishop" as SEE of any of these two moves must be caused by an implementation bug. As HGM wrote, SEE is quiescence search restricted to moves to the target square of the given move.

A recursive implementation has to take the maximum of doing nothing ("stand pat") and continuing the capture sequence with the least valuable attacker that is available. Promoting on the target square (which is also always a capture unless it is our first move for which we want to calculate SEE) must obviously be taken into account with a material gain of Q+victim-P. An iterative implementation does essentially the same but is usually a bit faster.
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Static exchange evaluation with promotion

Post by Sven »

gflohr wrote: Fri Jul 23, 2021 11:26 pm Maybe I used the wrong terminology?

The move given for the test is Rxc8, and so I considered 1. Rxc8 Bxc8 2. bxc8=Q. So the rooks are just exchanged (R - R), the bishop is hit, and the pawn stays on the board, and gets promoted to a queen. For me that is R - R + B.
The SEE result of the given move sequence is obviously Q+B-P ... "The pawn stays on the board" is simply wrong, it is replaced by a queen.
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)