Programmer bug hunt challenge

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

ed

Programmer bug hunt challenge

Post by ed » Fri May 04, 2007 9:26 am

Yesterday my PGN parser crashed while processing a large PGN file. I located the bastard and saved it as crash.pgn

Code: Select all

[Event ""]
[Site "Niksic"]
[Date "1978.??.??"]
[Round "1"]
[White "Velimirovic,D"]
[Black "Timman,J"]
[Result "0-1"]
[BlackElo "2585"]
[WhiteElo "2520"]

1. a3 g6 2. g3 Bg7 3. Bg2 e5 4. d3 Ne7 5. c3 d5 6. Nd2 O-O 7. h4 h6 8. 
e4 Be6 9. Ngf3 Nd7 10. O-O a5 11. exd5 Bxd5 12. Re1 Nc6 13. Qc2 Nc5 14. 
h5 g5 15. Ne4 Nb3 16. Rb1 f5 17. Ned2 Nxd2 18. Bxd2 a4 19. Be3 e4 20. Nd2 
exd3 21. Qxd3 Bxg2 22. Qxd8 Raxd8 23. Kxg2 f4 24. gxf4 gxf4 25. Bd4 Nxd4 
26. cxd4 Rxd4 27. Nf3 Rd3 28. Rbc1 c6 29. Rc4 Bxb2 30. Rb4 Bc3 0-1
But when parsing crash.pgn everything was ok, no crash, a headache started, non reproducible bugs are a programmers nightmare.

So I added the previous game to crash.pgn too, perhaps there was a connection and indeed my PGN parser crashed again. crash.pgn now looked as follows:

Code: Select all

[Event ""]
[Site "Niksic"]
[Date "1978.??.??"]
[Round "1"]
[White "Velimirovic,D"]
[Black "Gligoric,S"]
[Result "1/2-1/2"]
[BlackElo "2565"]
[WhiteElo "2520"]

1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 d6 
8. c3 O-O 9. h3 h6 10. d4 Re8 11. Nbd2 Bf8 12. Bc2 Bb7 13. d5 Nb8 14. b3 
Nbd7 15. c4 c5 16. cxb5 axb5 17. a4 1/2-1/2

[Event ""]
[Site "Niksic"]
[Date "1978.??.??"]
[Round "1"]
[White "Velimirovic,D"]
[Black "Timman,J"]
[Result "0-1"]
[BlackElo "2585"]
[WhiteElo "2520"]

1. a3 g6 2. g3 Bg7 3. Bg2 e5 4. d3 Ne7 5. c3 d5 6. Nd2 O-O 7. h4 h6 8. 
e4 Be6 9. Ngf3 Nd7 10. O-O a5 11. exd5 Bxd5 12. Re1 Nc6 13. Qc2 Nc5 14. 
h5 g5 15. Ne4 Nb3 16. Rb1 f5 17. Ned2 Nxd2 18. Bxd2 a4 19. Be3 e4 20. Nd2 
exd3 21. Qxd3 Bxg2 22. Qxd8 Raxd8 23. Kxg2 f4 24. gxf4 gxf4 25. Bd4 Nxd4 
26. cxd4 Rxd4 27. Nf3 Rd3 28. Rbc1 c6 29. Rc4 Bxb2 30. Rb4 Bc3 0-1
I then started the annoying procedure of setting breakpoints etc. (boy, I hate that) and after some hours finally discovered the trouble maker, yet I could have saved myself the trouble if I had a good look at the 2 games first, a clear hint was right before my eyes.

Do you see what I did not see?

Ed

User avatar
smrf
Posts: 484
Joined: Mon Mar 13, 2006 10:08 am
Location: Klein-Gerau, Germany
Contact:

Re: Programmer bug hunt challenge

Post by smrf » Fri May 04, 2007 10:09 am

The PGN move lines here are unusual short. But could that be a problem?

Reinhard.

P.S.: moreover the event tags are empty, what might be a problem.

Rob

Re: Programmer bug hunt challenge

Post by Rob » Fri May 04, 2007 10:31 am

Didn't clear en passent square between games?

Tony

Re: Programmer bug hunt challenge

Post by Tony » Fri May 04, 2007 10:49 am

Rob wrote:Didn't clear en passent square between games?
Most likely. Then a new movelist is generated wich has 2 pawns going to a3 (a2 and b2) Since captures are likely generated first, whites first move becomes b2xa3

:)

Tony

Tony

Re: Programmer bug hunt challenge

Post by Tony » Fri May 04, 2007 10:55 am

Or even better. a2-a3 is found, no problems, but the ep-flag is raised, and only when the undo is executed, a magic black pawn arises on a4

:)

Tony

Rob

Re: Programmer bug hunt challenge

Post by Rob » Fri May 04, 2007 11:25 am

Most likely. Then a new movelist is generated wich has 2 pawns going to a3 (a2 and b2) Since captures are likely generated first, whites first move becomes b2xa3
1. It's of course an impossible ep capture for white

2. There's an ambiguity.

3. Move 29. ... Bxb2 becomes impossible.

4. When you go back in the game a ghost black pawn could indeed appear on a2 although there's already a white pawn there.

User avatar
smrf
Posts: 484
Joined: Mon Mar 13, 2006 10:08 am
Location: Klein-Gerau, Germany
Contact:

Re: Programmer bug hunt challenge

Post by smrf » Fri May 04, 2007 12:01 pm

Why should your suggestion be a merely PGN parsing related error? It also should have occurred already earlier at a lot of other moments. Thus I would exclude that idea.

Reinhard.

Tony

Re: Programmer bug hunt challenge

Post by Tony » Fri May 04, 2007 12:02 pm

Rob wrote:
Most likely. Then a new movelist is generated wich has 2 pawns going to a3 (a2 and b2) Since captures are likely generated first, whites first move becomes b2xa3
1. It's of course an impossible ep capture for white

2. There's an ambiguity.

3. Move 29. ... Bxb2 becomes impossible.

4. When you go back in the game a ghost black pawn could indeed appear on a2 although there's already a white pawn there.
A lot of these logical checks are "optimized" out of my engine :oops: .

The possibilities I mentioned are not guesses what Rebel will do, they are descriptions what my engine will do.

1. My engine takes a bitboard of the opponent pieces and or's it with the ep square. It is then fed to the pawnattack bitboard so the ep move will show up.

2. My engine generates a legal move list (when pgn parsing). The first move that fullfils the criteria (Pawn moving to a3) will be taken.

3. No problem, my engine captures allways. With a noncapture move, the captured piece will be "Empty" rather than a piece.

4. Yes, a2 instead of a4. The white pawn on a2 will be overwritten with a black pawn. No check is done for that.

Cheers,

Tony

ed

Re: Programmer bug hunt challenge

Post by ed » Fri May 04, 2007 1:51 pm

Rob wrote:Didn't clear en passent square between games?
Bravo!

Funny because my PGN parser is about to celebrate its first decade and the bug has been there all along, it seems that it is rare a game to end with white moves like a4/b4 etc.

Ed

Uri Blass
Posts: 7993
Joined: Wed Mar 08, 2006 11:37 pm
Location: Tel-Aviv Israel

Re: Programmer bug hunt challenge

Post by Uri Blass » Fri May 04, 2007 4:46 pm

I do not understand the bug

There was no enpassent capture possible in the end of the first game
so I do not see how clearing enpassent square between games could be relevant.

There was no black pawn at b4 in the final position of the game.

Uri

Post Reply