En passant bonus

Discussion of anything and everything relating to chess playing software and machines.

Moderator: Ras

User avatar
lantonov
Posts: 216
Joined: Sun Apr 13, 2014 5:19 pm

Re: En passant bonus

Post by lantonov »

I do not quite understand what rank 4 and rank 5 mean.

From white's point of view, the bonus should be due to any pawn on the 5th rank, with an enemy pawn on the 7th to the left or to the right on adjacent files.

This will hold true for both white and black.

The 7th rank is again seen from white's perspective, so actually the black pawn on the 7th rank from white's point of view is a pawn on the 2nd rank from black's point of view.
... and a white pawn on rank 5 from White's point of view is a black pawn on rank 4 from Black's point of view.
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: En passant bonus

Post by cdani »

I'm testing now in Andscacs. I prefer to code in a compressed and possibly faster way. Also I coded as a penalization, not as a bonus, but it's the same:

Code: Select all

	Bitboard a,b,c;
	const Bitboard rank2 = me ? RANK7 : RANK2;
	const Bitboard rank4 = me ? RANK5 : RANK4;
	a=Pawns(me) & rank2;
	b=Pawns(opponent) & rank4;
	if (a && b) {
		c=ShiftForPawns(me,b,16); //shift 16 or -16
		c=(((c >> 1) & a) << 1) | (((c << 1) & a) >> 1); //they can be taked en passant if advance two squares
		if (c)
			i-=popcount(c) * Penalization;
	}
Pio
Posts: 338
Joined: Sat Feb 25, 2012 10:42 pm
Location: Stockholm

Re: En passant bonus

Post by Pio »

cdani wrote:I'm testing now in Andscacs. I prefer to code in a compressed and possibly faster way. Also I coded as a penalization, not as a bonus, but it's the same:

Code: Select all

	Bitboard a,b,c;
	const Bitboard rank2 = me ? RANK7 : RANK2;
	const Bitboard rank4 = me ? RANK5 : RANK4;
	a=Pawns(me) & rank2;
	b=Pawns(opponent) & rank4;
	if (a && b) {
		c=ShiftForPawns(me,b,16); //shift 16 or -16
		c=(((c >> 1) & a) << 1) | (((c << 1) & a) >> 1); //they can be taked en passant if advance two squares
		if (c)
			i-=popcount(c) * Penalization;
	}
Hi

No, it is not the same. They are the same relative each other but not relative other evaluation terms. Coding this feature as a bonus might make your engine making wrong piece trading decisions for example.

Also I think it is good to put the evaluation terms where they belong (in this case some sort of safe mobility) since other evaluation terms can be a function of this term (in this case safe mobility).

Good luck!
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: En passant bonus

Post by cdani »

Pio wrote: No, it is not the same. They are the same relative each other but not relative other evaluation terms. Coding this feature as a bonus might make your engine making wrong piece trading decisions for example.

Also I think it is good to put the evaluation terms where they belong (in this case some sort of safe mobility) since other evaluation terms can be a function of this term (in this case safe mobility).

Good luck!
I understand. In this particular case if I did not overlook something is the same, because I don't take the resulting value for other tasks. Anyway what you say it's important, to be very ordered, and sometimes I don't take it into account :-)
Pio
Posts: 338
Joined: Sat Feb 25, 2012 10:42 pm
Location: Stockholm

Re: En passant bonus

Post by Pio »

cdani wrote:
Pio wrote: No, it is not the same. They are the same relative each other but not relative other evaluation terms. Coding this feature as a bonus might make your engine making wrong piece trading decisions for example.

Also I think it is good to put the evaluation terms where they belong (in this case some sort of safe mobility) since other evaluation terms can be a function of this term (in this case safe mobility).

Good luck!
I understand. In this particular case if I did not overlook something is the same, because I don't take the resulting value for other tasks. Anyway what you say it's important, to be very ordered, and sometimes I don't take it into account :-)
Hola Daniél!

No it is not the same. You implemented it in the right way as a penalization. If you would have implemented it as a bonus (I think they did that in Stockfish) you get into trouble beacuse you might for example not trade your so called good pawns with other pieces because the pawns were over valued. Of course in Stockfish the problem will probably sooner or later disappear through inserting penalization in the Piece Square Tables in one of their SPSA runs. But it is not the right thing to do and lots of other people copying/rewriting Stockfish's code do not have the same testing possibilities that can cover up those errors.

I think it is extremly good of you to be able to make such a strong engine in such a short time frame.

Hasta luego
Lyudmil Tsvetkov
Posts: 6052
Joined: Tue Jun 12, 2012 12:41 pm

Re: En passant bonus

Post by Lyudmil Tsvetkov »

Pio wrote:
cdani wrote:I'm testing now in Andscacs. I prefer to code in a compressed and possibly faster way. Also I coded as a penalization, not as a bonus, but it's the same:

Code: Select all

	Bitboard a,b,c;
	const Bitboard rank2 = me ? RANK7 : RANK2;
	const Bitboard rank4 = me ? RANK5 : RANK4;
	a=Pawns(me) & rank2;
	b=Pawns(opponent) & rank4;
	if (a && b) {
		c=ShiftForPawns(me,b,16); //shift 16 or -16
		c=(((c >> 1) & a) << 1) | (((c << 1) & a) >> 1); //they can be taked en passant if advance two squares
		if (c)
			i-=popcount(c) * Penalization;
	}
Hi

No, it is not the same. They are the same relative each other but not relative other evaluation terms. Coding this feature as a bonus might make your engine making wrong piece trading decisions for example.

Also I think it is good to put the evaluation terms where they belong (in this case some sort of safe mobility) since other evaluation terms can be a function of this term (in this case safe mobility).

Good luck!
If we would like to order our evaluation terms right, than we should give a bonus to the 5th rank pawn. It is that pawn that has the right to capture en passant, and not vice-versa.

So, the mobility of the pawn on the 7th rank is under the discretion of the 5th rank pawn's reaction to its possible double movement. The 5th rank pawn might capture, or not capture.

But this is too dry and philosophical, maybe programmers know better.

Here a diagram:

[d]6k1/8/8/8/1b4p1/2N5/1P5P/4K3 w - - 0 1
You call the pin on the queen side a bishop pin, although the knight is pinned. So you give the bonus to the bishop, that has the power to limit to zero the knight's mobility, and you call the pin a bishop pin.

Same with the g4 and h2 pawns on the king side. the mobility of the h2 pawn is limited, but it is the g4 pawn that has capturing discretion, those powers lie with it, so it is reasonable, much along the pin lines, to give a bonus to the g4 pawn, rather than a penalty to the h2 pawn.

Here we do not emphasize the weakness of the h2 pawn, as with backward and other pawns, but rather the discretion of the g4 pawn to capture at will or not an advancing h2 pawn. So the en passant powers lie with the g4 pawn.

We give the bonus for the special functionality of the g4 pawn.
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: En passant bonus

Post by cdani »

Pio wrote: No it is not the same. You implemented it in the right way as a penalization. If you would have implemented it as a bonus (I think they did that in Stockfish) you get into trouble beacuse you might for example not trade your so called good pawns with other pieces because the pawns were over valued. Of course in Stockfish the problem will probably sooner or later disappear through inserting penalization in the Piece Square Tables in one of their SPSA runs. But it is not the right thing to do and lots of other people copying/rewriting Stockfish's code do not have the same testing possibilities that can cover up those errors.
Hola again!
I understand that you mean that if I compare the values of the bonused pawns they will be different, so the decisions can be different in some cases. It's ok but I don't store neither the individual values nor the white/black values. I store only one value: white+black pawns. So in fact in Andscacs is the same to do the bonus way or do the penalization way.

Anyway I tried as a bonus and in fact was showing the same number of moves. I'm giving it a longer try and I'm testing also. I will explain all the results.

Also a slight improvement:

Code: Select all

c=((a >> 1) & c) | ((a << 1) & c);
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: En passant bonus

Post by xmas79 »

cdani wrote:...Also a slight improvement:

Code: Select all

c=((a >> 1) & c) | ((a << 1) & c);
Hi Daniel,
don't you need to mask A/H files when shifting left/right?
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: En passant bonus

Post by cdani »

xmas79 wrote:
cdani wrote:...Also a slight improvement:

Code: Select all

c=((a >> 1) & c) | ((a << 1) & c);
Hi Daniel,
don't you need to mask A/H files when shifting left/right?
Not really. There is nothing outside the second rank of c that can be "Anded".
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: En passant bonus

Post by cdani »

No way. It never works on Andscacs. I tested with penalization/bonus of 3, 5 and 10 cp. It's only good at selfplay, but never at gauntlet.

Most probably there is something that interferes in the eval function. May be if at some point I recalculate the eval values again of most things, I will try again.