Does a "en passent" aware PGN2EPD converter exist

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Does a "en passent" aware PGN2EPD converter ex

Post by Evert »

tpetzke wrote: I then have to guess what rules the epd creator implemented in order to decide whether he includes an en passent square or not in a given FEN. Errors introduced by guessing can be much worse than a missed repetition.
Nah. You only ever get a difference in situations where you did not set the ep square because no ep capture is possible - in which case the ep square is irrelevant.
Not that I think the missed repetition is actually relevant (Jazz doesn't do this right either, which has never bothered me).
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Does a "en passent" aware PGN2EPD converter ex

Post by hgm »

tpetzke wrote:I care for the ep because my engine creates standard compliant FEN strings. And if I zobrist hash a FEN string from a pseudo compliant EPD I get no match with my fully compliant FEN even if the position matches.
I don't get it. What has the FEN string to do with a Zobrist hash? Why does an engine create FEN strings in the first place?
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: Does a "en passent" aware PGN2EPD converter ex

Post by tpetzke »

I'm not concerned here with a missed repetition, whatever an engine does internally eg. how it generates its hash signature is not subject to standards anyway, any engine can do this as it likes.

Standards rule when you communicate with the outside world, because if one party does not stick to it communication breaks.

I'll try the pawn presence check idea but if it slows down the engines makeMove I'll go back to my original signature creation.
And thirdly, the code is more what you'd call "guidelines" than actual rules. Welcome aboard the Black Pearl, Miss Turner .
Cpt. Barossa
Thanks for all the feedback
Thomas...
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: Does a "en passent" aware PGN2EPD converter ex

Post by tpetzke »

I'm implementing an opening book for my engine, so in order to assemble the book I feed in a set of epds that contain a position and a move.

In this process a hash signature is created from the epd fen part. If the epd fen has no en passent square set although the standard says it should then my engine will not recognize that this position in its book is actually the position on the board.

This leads to holes in its book.

I will find a solution, one way or another.

Thx
Thomas...
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Does a "en passent" aware PGN2EPD converter ex

Post by Evert »

tpetzke wrote: In this process a hash signature is created from the epd fen part. If the epd fen has no en passent square set although the standard says it should then my engine will not recognize that this position in its book is actually the position on the board.
Only if your engine sets the EP square in the hash even when there is no EP capture possible, which is almost certainly wrong (there are no benefits, you miss transpositions/repetitions and it's actually not in accordance with FIDE rules).
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Does a "en passent" aware PGN2EPD converter ex

Post by hgm »

Beware that not removing false e.p. rights will cause a serious slowdown of your engine, perhaps a hundred times as much as doing the tests for neighboring Pawns. Because it means that almost every position after a double push (and there are many in the middle game!) will now be represented by two different hash keys, leading to hash misses that would otherwise have been hits, with very costly superfluous searches as a result.
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: Does a "en passent" aware PGN2EPD converter ex

Post by tpetzke »

The benefit was that it is very easy to implement (branchless).

But I see with the hash behaviour your point and will try it out.

The argument with the FIDE rule I don't buy

This is how in the polyglot book format it is handled and I think this is how most engines do it. And this is also not compliant to FIDE rules.
If the opponent has performed a double pawn push and there is now a pawn next to it belonging to the player to move then "enpassant" ...is set. It is irrelevant if the potential en passant capturing move is legal or not (examples where it would not be legal are when the capturing pawn is pinned or when the double pawn push was a discovered check).
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Does a "en passent" aware PGN2EPD converter ex

Post by hgm »

Well, as this is mostly a speed issue, a pragmatic approach suffices. Not being able to distinguish the positions after 1. d4 d5 2. c4 and 1. c4 d5 2. d4 is very costly because it happens very frequently, and causes needles searches when it does. Not being able to distinguish a position where a neighboring Pawn exists but happens to be pinned occurs a thousand times less frequently, and would take 100 times longer to check. So the duplication of positions in opening book and hash table (with an occasional re-search) is a much more efficient solution for this case.

In Spartacus' MakeMove I need to catch special moves with a branch anyway, and I make that catch double pushes as well, by encoding these as special moves. So other regular moves don't suffer from this a all:

Code: Select all

if(SPECIAL(move)) {
  moveType = decodeTab[toSqr];
  toSqr = fromSqr + stepTab[toSqr];
  if(moveType == 0) {
    TEST_EP(RIGHT_NEIGHBOR(toSqr));
    TEST_EP(LEFT_NEIGHBOR(toSqr));
  } else if (moveType > 0) {
    // perform promotion, moveType encodes promotion piece

  } else if(moveType == -1) {
    // perform castling

  } else {
    // peform e.p. capture

  }
}
As almost all special moves are double-pushes, the if(moveType == 0) branch is very well predicted.
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Testing results

Post by tpetzke »

I changed the en passent hash signature coding in iCE to the scheme suggested by Sven and Harm and did some quick perft tests with the old and new version

The raw perft (without hash table usage) performed about the same in both versions. 107 sec for perft 7 from the start position.

The perft that utilizes the hash table for storing sub results performed better in the new version as predicted by Harm, significantly better.

Code: Select all

old version: 23 sec

iCE 0.3 build 5 [2011.9.12]
perftTT 7
perft        Nodes    Time
  1             20    0 sec
  2            400    0 sec
  3          8.902    0 sec
  4        197.281    0.016 sec
  5      4.865.609    0.125 sec
  6    119.060.324    1.734 sec
  7  3.195.901.860    23.281 sec

new version: 14 sec

iCE 0.3 build 7 [2011.10.4]
perftTT 7
perft        Nodes    Time
  1             20    0 sec
  2            400    0 sec
  3          8.902    0 sec
  4        197.281    0.016 sec
  5      4.865.609    0.171 sec
  6    119.060.324    1.157 sec
  7  3.195.901.860    14.672 sec
So I'm convinced about the engines internal handling of the EP square.

Thanks to all

Thomas...


[/code]
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Does a "en passent" aware PGN2EPD converter ex

Post by Evert »

tpetzke wrote: The argument with the FIDE rule I don't buy

This is how in the polyglot book format it is handled and I think this is how most engines do it. And this is also not compliant to FIDE rules.
I'm not sure there's anything for sell.
The EPD standard deviates from the FIDE rules for no clear reason, so adhering to it too rigorously doesn't seem particularly "right". You are right that most engines don't strictly follow FIDE rules for setting the EP square either (as I may have said, mine doesn't either). However, cases where it would matter are relatively rare and adding extra code to do the tests (basically a legal move test for the pawn capture) seems a lot of hassle and may be slow (no idea about that though, it may be rare enough that it doesn't actually matter). The worst that can happen is that a repetition is caught one move late, which isn't really a big deal.