Most baffling bug EVER

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Mike Sherwin
Posts: 860
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Most baffling bug EVER

Post by Mike Sherwin »

Starting with this position. Bricabrac playing black. Six seconds per move.
[d]3r1rk1/2p2p2/1b6/p2pP1q1/Qp1P2p1/8/PPR2PPN/3R2K1 w - - 6 32
1. d1d3 f7f5 +0.20
2. a4c6 g5g7 -M293

My immediate thought is that the e.p. code is broken. So I restarted the engine and forced.
1. d1d2 f7f6
2. d2d3 f6f5
3. a4c6 ...
4. ... g8g7 +0.14

Yep it must be the e.p. code. But wait.
1. d1d3 f7f5
2. e5f6 f8f6 -0.41
Engine now plays both sides.
3. c2e2 +0.42 f6f5 -0.34 Hmm, not broken.

Forced.
1. d1d2 f7f5
2. a4c6
2. ... g8g7 -0.01 Not apparently broken but a slightly different score, hmm. But engine played fine after that.

1. d1d3 f7f5 The engine played f5.
2. d3d1 g8g7 +0.14
3. a4c6 f8h8 +0.26 Once again not broken and the engine played fine for the rest of the game. Until I took back all the moves and played d1d3 and it was immediately broken. So i took back all the moves again and restarted the engine.

1. d1d3 f7f5
2. e5f6 f8f6

Took back the moves but did not restart the engine.
1. d1d3 f6f5 illegal move, broken

So then I had the engine print the board to Arena so I could see the internal board and black had pawns on f7 and f6 after e5e6 c.e.p was retracted. But, that does not happen in the search because in the original line even though it was broken the engine's board is correct. :?

My thoughts at the moment are that although according to perfect perft results the engine generates c.e.p moves but never plays them. And when the c.e.p moves are forced the TakeBack function is bugged. Therefore there are at least three bugs at play here. But, now I'm really :? because if the c.e.p take back code is bugged then how in the heck does perft return correct results?
Mike Sherwin
Posts: 860
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: Most baffling bug EVER

Post by Mike Sherwin »

Conclusion 1: Taking back game c.e.p moves is bugged.
Conclusion 2: Since I have never seen the engine play a c.e.p move the scoring of c.e.p moves must be wrong.
Conclusion 3: During search it is only when the score exceeds (+/-)INF does the search break and start printing pv's that look like a1a1 a1a1 a1a1 ... a1a1.

Therefore there are two bugs and the bug in the search is a c.e.p scoring bug.
Mike Sherwin
Posts: 860
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: Most baffling bug EVER

Post by Mike Sherwin »

My conclusions were wrong.

In MakeMove() the ep square is stored at ply + 1 and in TakeBack() the ply is decremented first. The offending line in TakeBack() is.

sq = m->ts - ((epbb[ply] == (one << m->ts)) << 3);

Should be.

sq = m->ts - ((epbb[ply + 1] == (one << m->ts)) << 3);

:D

I hope this is the last search bug. If not I'm going to start naming this thread the "Bug Hunt Chronicles". :roll:

But, still I'm baffled how perft 7 could possibly give a correct number?

Edit: :D :) :| :( :oops: :cry: It might be time for me to retire from chess programming, again. :arrow:
Mike Sherwin
Posts: 860
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: The Bug Hunt Chronicles

Post by Mike Sherwin »

Okay, I fixed the consequences of the bug without finding the bug. It turns out that it is a material problem in MakeMove()/TakeBack(). What I did was save the material in MakeMove() and restored it in TakeBack() removing all other material calculations in TakeBack(). Now I'm going to find that bug and use a flamethrower on it. :evil:

Here's the game with the kludge code.
[pgn][Event "TSCP.at"]
[Site "DESKTOP-HFVHK2B"]
[Date "2021.04.18"]
[Round "42"]
[White "Tscp181"]
[Black "Bricabrac"]
[Result "0-1"]
[BlackElo "2000"]
[ECO "C83"]
[Opening "Spanish"]
[Time "16:38:43"]
[Variation "Open, Classical, 10.Be3"]
[WhiteElo "2200"]
[TimeControl "0+6"]
[Termination "adjudication"]
[PlyCount "141"]
[WhiteType "human"]
[BlackType "human"]

1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O Nxe4 6. d4 b5 7. Bb3 d5 8.
dxe5 Be6 9. c3 Be7 10. Be3 O-O {(e8g8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 f4f5 d3d2 d5e6 d2d1q f5f6 d1g4 e6d6 g4f5
d6e7 b2a3) -15.19/11 5 Arena Adjudication} 0-1
[/pgn]
Jakob Progsch
Posts: 40
Joined: Fri Apr 16, 2021 4:44 pm
Full name: Jakob Progsch

Re: Most baffling bug EVER

Post by Jakob Progsch »

I can't help with this specific one but I recently had a similarily confounding bug for what appear to be similar reasons. I thought my move generation was good because it produced all the usual perft numbers correctly. But once in a while during search nonsensical things would happen such as kings ending up on neighbor squares causing infinite checking sequences blowing up my stack.

Eventually I noticed the common denominator was that those bugs always happened below null moves. It turned out for some reason one side ended up with nine pawns causing an out of bounds write on a piece array after which all bets were off obviously.

The ultimate reason was that on a null move I only flipped the white to move bit in the board but didn't clear the en passant bit allowing a "phantom" en passant capture for the wrong side. And because all changes to the board state happen via XOR ops (so they are trivially reversible) instead of being captured an opposing pawn popped into existence behind the capturing one.
Mike Sherwin
Posts: 860
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: Most baffling bug EVER

Post by Mike Sherwin »

Jakob Progsch wrote: Mon Apr 19, 2021 1:59 am I can't help with this specific one but I recently had a similarily confounding bug for what appear to be similar reasons. I thought my move generation was good because it produced all the usual perft numbers correctly. But once in a while during search nonsensical things would happen such as kings ending up on neighbor squares causing infinite checking sequences blowing up my stack.

Eventually I noticed the common denominator was that those bugs always happened below null moves. It turned out for some reason one side ended up with nine pawns causing an out of bounds write on a piece array after which all bets were off obviously.

The ultimate reason was that on a null move I only flipped the white to move bit in the board but didn't clear the en passant bit allowing a "phantom" en passant capture for the wrong side. And because all changes to the board state happen via XOR ops (so they are trivially reversible) instead of being captured an opposing pawn popped into existence behind the capturing one.
Thanks for sharing your experience! 8-)

My biggest fear is that my new SISSY bitboards will fail in some rare position. So far they have been rock solid. :D After the code hack the engine has been running fine for 69 games. Can it make it to 100? I hope so. Just 31 to go and my engine will have completed it first match without problems.
Mike Sherwin
Posts: 860
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: Most baffling bug EVER

Post by Mike Sherwin »

Dumbzie (dumb zombie) code example.
bb = (wPawnMoves[fs] & empty) | (wPawnCapts[fs] & enemy);
if (bb & king[otm]) return ILLEGAL;

Smartzie (smart zombie) code example.
bb = wPawnCapts[fs] & enemy;
if (bb & king[otm]) return ILLEGAL;
bb |= wPawnMoves[fs] & empty;
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Most baffling bug EVER

Post by Ras »

Jakob Progsch wrote: Mon Apr 19, 2021 1:59 amThe ultimate reason was that on a null move I only flipped the white to move bit in the board but didn't clear the en passant bit allowing a "phantom" en passant capture for the wrong side.
Interestingly, my engine has a similar issue, but since the capture works to the square behind e.p. square which is empty (i.e. the start square of the pawn that had moved two squares up before), that's not registered as capture, but as quiet move. Taking that back hence doesn't generate a spurious pawn. I tried to fix the issue, only to find out that this cost 2 Elo, consistent with the loss in NPS, so I left it in.
Rasmus Althoff
https://www.ct800.net