request assistance or advice on an obscure bug

Discussion of chess software programming and technical issues.

Moderator: Ras

Fguy64
Posts: 814
Joined: Sat May 09, 2009 4:51 pm
Location: Toronto

request assistance or advice on an obscure bug

Post by Fguy64 »

OK, I have been experimenting (gasp!) with my engine and I think I have introduced an obscure bug that I can't pin down. Unfortunately I haven't yet been able to introduce proper diagnostic tools like perftt, I'm a ways away from that still. My diagnostic skills are not great, I usually have to rely on brute force.

First of all, let me set the stage. In order to simplify the situation, I have disabled features, and demonstrated that the problem occurs under the following conditions...

1. Fixed depth search, no iterativive deepening, no hash or transposition table
2. No qSearch
3. Strictly material evaluation (positional eval has been disabled).

Now under these conditions, the following should hold true.

Starting with a position and a search depth, you get back an evaluation and a principal variation. Now you can have the engine play one move at a time, each time reducing the depth by 1, and the engine should play both sides of the original PV, and at each ply the sign of the score will be reversed.

But now I have this problem I can't resolve. I have played through the first sixty or so WAC positions, and all but one observe the above rules.

here is a link to the current version of my engine. http://fchess.uuuq.com/test1/dchess.htm You will see there is an option in the drop down list for pasting a fen. The test3 option provides fixed depth abp with no qsearch and material eval only.

The problem position is r1b1kb1r/3q1ppp/pBp1pn2/8/Np3P2/5B2/PPP3PP/R2Q1RK1 w kq - 0 1 You can see that there are problems with searches of depth 6 or greater. garbage shows up in the PV. I am thinking maybe it is some kind of moveGen problem with black castling, but I just can't see it. And I can't replicate the problem with any other position.

I guess I am hoping that someone here might be familiar with this kind of issue and will spot the pattern, or maybe can demonstrate the issue with some other position. I can make the source available is someone wants to see it. In the meantime, I'll keep trying, I'll let you know if I find the bug, or see this problem with any other position.

regards.
brianr
Posts: 540
Joined: Thu Mar 09, 2006 3:01 pm
Full name: Brian Richardson

Re: request assistance or advice on an obscure bug

Post by brianr »

Does your move ordering not vary with initialization (for example, are killers cleared)?

Do you generate check evasions (perhaps turn this off and see if it matters)?

How do you handle repetition and 50 move draws (especially with no hash--a separate table)?

Do you have a perpetual check test?
Fguy64
Posts: 814
Joined: Sat May 09, 2009 4:51 pm
Location: Toronto

Re: request assistance or advice on an obscure bug

Post by Fguy64 »

brianr wrote:Does your move ordering not vary with initialization (for example, are killers cleared)?

Do you generate check evasions (perhaps turn this off and see if it matters)?

How do you handle repetition and 50 move draws (especially with no hash--a separate table)?

Do you have a perpetual check test?
None of the above, I'm testing with just straight up fixed depth negamax alphabeta with material eval only, No Qsearch, no hashing, no killers, no perp test, no repetition test, no 50 move rule. nothing. Till I can find the bug.
Fguy64
Posts: 814
Joined: Sat May 09, 2009 4:51 pm
Location: Toronto

Re: request assistance or advice on an obscure bug

Post by Fguy64 »

OK I found the problem, twas a typo in my unmakeMove function that mishandled the restoration of the previous ply's queenside castling rights...

state.canCastleQS = bu.canCastleKS;

:oops:
Aaron Becker
Posts: 292
Joined: Tue Jul 07, 2009 4:56 am

Re: request assistance or advice on an obscure bug

Post by Aaron Becker »

In my experience, the easiest way to find bugs like this is by using perft. If your engine passes perft tests in a variety of positions, you can be much more confident that things like castling rights and en passant are handled correctly in your move generator.

If you're not familiar with perft, more information is available at http://chessprogramming.wikispaces.com/Perft
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: request assistance or advice on an obscure bug

Post by michiguel »

Aaron Becker wrote:In my experience, the easiest way to find bugs like this is by using perft. If your engine passes perft tests in a variety of positions, you can be much more confident that things like castling rights and en passant are handled correctly in your move generator.

If you're not familiar with perft, more information is available at http://chessprogramming.wikispaces.com/Perft
Yes, and perftdiv to find them.

Miguel
Fguy64
Posts: 814
Joined: Sat May 09, 2009 4:51 pm
Location: Toronto

Re: request assistance or advice on an obscure bug

Post by Fguy64 »

Aaron Becker wrote:In my experience, the easiest way to find bugs like this is by using perft. If your engine passes perft tests in a variety of positions, you can be much more confident that things like castling rights and en passant are handled correctly in your move generator.

If you're not familiar with perft, more information is available at http://chessprogramming.wikispaces.com/Perft
Thanks, I've tried to figure perftt out a few times. It's on my list. Personally I find the chessprogramming wiki a little too advanced for my needs. I'm just an amateur in this crowd. recursion tends to make my head spin.

Anyways. I knew early on my program wasn't passing the test and I was pretty sure it was castling related, I also thought of unmake move early on, because a move was being made by a non-existent piece. I just didn't spot the typo, even thought I passed over it a few times.
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: request assistance or advice on an obscure bug

Post by michiguel »

Fguy64 wrote:
Aaron Becker wrote:In my experience, the easiest way to find bugs like this is by using perft. If your engine passes perft tests in a variety of positions, you can be much more confident that things like castling rights and en passant are handled correctly in your move generator.

If you're not familiar with perft, more information is available at http://chessprogramming.wikispaces.com/Perft
Thanks, I've tried to figure perftt out a few times. It's on my list. Personally I find the chessprogramming wiki a little too advanced for my needs. I'm just an amateur in this crowd. recursion tends to make my head spin.

Anyways. I knew early on my program wasn't passing the test and I was pretty sure it was castling related, I also thought of unmake move early on, because a move was being made by a non-existent piece. I just didn't spot the typo, even thought I passed over it a few times.
It is refreshing to see someone to attack CC from the ground up. We are cheering for you Fred. Trust me, perft should not be just in your list, perft should be your priority #1. Perftdiv your priority #2.

Miguel
Fguy64
Posts: 814
Joined: Sat May 09, 2009 4:51 pm
Location: Toronto

Re: request assistance or advice on an obscure bug

Post by Fguy64 »

michiguel wrote:
Fguy64 wrote:
Aaron Becker wrote:In my experience, the easiest way to find bugs like this is by using perft. If your engine passes perft tests in a variety of positions, you can be much more confident that things like castling rights and en passant are handled correctly in your move generator.

If you're not familiar with perft, more information is available at http://chessprogramming.wikispaces.com/Perft
Thanks, I've tried to figure perftt out a few times. It's on my list. Personally I find the chessprogramming wiki a little too advanced for my needs. I'm just an amateur in this crowd. recursion tends to make my head spin.

Anyways. I knew early on my program wasn't passing the test and I was pretty sure it was castling related, I also thought of unmake move early on, because a move was being made by a non-existent piece. I just didn't spot the typo, even thought I passed over it a few times.
It is refreshing to see someone to attack CC from the ground up. We are cheering for you Fred. Trust me, perft should not be just in your list, perft should be your priority #1. Perftdiv your priority #2.

Miguel
Thanks for the support, duly noted on the perftt. I've certainly heard it often enough. I'll have to give it another go soon.

The program has come a long way in the last year or two, thanks in large part to the help I've received here. I have a ton of ideas for moving ahead, a lot of it is GUI related, database stuff, chess server client, UCI or xBoard standard. gaming website stuff . It's supposed to be a vehicle for learning to program, I have to make sure the chess aspect doesn't take priority.
MattieShoes
Posts: 718
Joined: Fri Mar 20, 2009 8:59 pm

Re: request assistance or advice on an obscure bug

Post by MattieShoes »

perft simply walks a search tree with a fixed depth, so it's far simpler than even alpha beta with fixed depth and no qsearch :-)


Off the top of my head, here's some pseudocode of the entire perft function.

Code: Select all

//perft calculates the number of leaf nodes in a search tree at a given depth
int perft(int depth)
{
  if(depth==0)
    return 1;
  int leaves = 0;
  genMoves();
  foreach move m in movelist
  {
    makeMove(m);
    leaves += perft(depth-1);
    undoMove();
  }
  return leaves;
}

I don't know what perftdiv is, can somebody enlighten me?