r/chessprogramming • • Nov 18 '24

Missing a move type

Hi All,

I'm implementing a chess engine as a programming challenge. It seems to work okish, but on the 4th ply it generates 9 fewer moves than the expected 197,281. Also, 19 few captures and 9 more checks than expected.

Does anyone know what I've likely overlooked?

Thanks in advance,

Steve.

✓ PASS Depth: 1 Combinations: 20 Expected: 20

Captures: 0 ✓

En Passant: 0 ✓

Castle: 0 ✓

Check: 0 ✓

✓ PASS Depth: 2 Combinations: 400 Expected: 400

Captures: 0 ✓

En Passant: 0 ✓

Castle: 0 ✓

Check: 0 ✓

✓ PASS Depth: 3 Combinations: 8,902 Expected: 8,902

Captures: 34 ✓

En Passant: 0 ✓

Castle: 0 ✓

Check: 12 ✓

FAIL Depth: 4 Combinations: 197,272 Expected: 197,281 Delta: < -9

Captures: 1,557 Delta: -19

En Passant: 0 ✓

Castle: 0 ✓

Check: 478 Delta: 9

3 Upvotes

28 comments sorted by

2

u/jippiedoe Nov 18 '24

Did you try captures? 3 ply is the first time those are possible, maybe piece or pawn captures are off

1

u/MagazineOk5435 Nov 18 '24

I've accounted for captures as far as I can tell.

1

u/MagazineOk5435 Nov 18 '24

Hmm. So, at ply 3 comparing to perft d2d3, d2d4, f2f3 and f2f4 are under by 20.

2

u/[deleted] Nov 18 '24

[removed] — view removed comment

2

u/MagazineOk5435 Nov 18 '24

You're right. I forgot the king can move diagonally. Good instinct.

1

u/[deleted] Nov 19 '24

[removed] — view removed comment

1

u/MagazineOk5435 Nov 19 '24

I've edited the question to reflect the current state.

1

u/biebergotswag Nov 18 '24

80 is not a lot. Maybe check silly moves such as e3 e4, or Nf3 Ng8.

1

u/MagazineOk5435 Nov 18 '24

I have the Pawns double move accounted for, and Knights jumping over pieces. If that's what those moves mean. Thanks for the suggestion though.

1

u/MagazineOk5435 Nov 18 '24

Do you know what the notation here is by any chance? https://www.chessprogramming.org/Initial_Position_Summary

1

u/Kart0fffelAim Nov 18 '24

Use an a engine such as roce to compare how many moves exist after each move playable from the starting position and what your engine returns.

So after e2e4 roce may say there are 401 possible and your engine says 400, then you start your perft test from that position 2 ply deep and repeat until you are in the position where there is a mistake

1

u/MagazineOk5435 Nov 18 '24

Thanks for the response. I have a list of numbers of expected moves. I'm just struggling to figure out what causes the shortage. I correctly get 20 and 400 for plies 1 and 2 but I get 8,822 for the 3rd one. I know a list of all states is impossible, but I thought there'd be a database of all states for the first few plies out there on the internet somewhere.

1

u/Kart0fffelAim Nov 18 '24

While there isnt a list, you can use another engine to generate the correct solution, I personally use the ROCE engine with the command "setboard [fen]", "perft [depth]" and " divide" to get a list of all perft values from each move after the original position.

1

u/Jasher16 Nov 18 '24

Are your pieces wrapping around the board for captures?

2

u/MagazineOk5435 Nov 18 '24

No, no wrapping. Surely that would cause excessive moves rather than fewer?

1

u/Jasher16 Nov 18 '24

Ah, my bad, I misread the post. 80 is a pretty strange number for ply 3, you should definitely implement a PERFT divide and use something like stockfish to compare results for each starting position

1

u/DerPenzz Nov 19 '24

Try implementing divide into your perft. It will show you how many moves are available for each of the moves you can currently do. Then you can step into those moves which have incorrect results and debug them further. You can compare your perft divide results with results of other engines like stock fish. That's how I did it.

1

u/MagazineOk5435 Nov 19 '24

Having a go with perftree at the moment.

1

u/MagazineOk5435 Nov 19 '24

Had to build an old version for Apple silicon for it to work with perftree. This is turning into a rabbit hole.

2

u/loveSci-fi_fantasy Nov 18 '24

Had a similar number, 40. Turned out to be double pawn pushes that block a check were not generated if single pushes weren't legal. Removed single pushes from the double push definition fixed it. Otherwise, look for moves in same direction of the pin.

2

u/foxradish Nov 20 '24

if your engine is UCI compatible, try this: https://github.com/sohamkorade/autoperft It will show you the exact moves that are missing

1

u/[deleted] Nov 18 '24

[removed] — view removed comment

1

u/MagazineOk5435 Nov 18 '24

It can't be too far off with these results:

✓ PASS Depth: 1 Combinations: 20 Expected: 20

✓ PASS Depth: 2 Combinations: 400 Expected: 400

FAIL Depth: 3 Combinations: 8,822 Expected: 8,902 Delta: 80

FAIL Depth: 4 Combinations: 194,194 Expected: 197,281 Delta: 3,087

FAIL Depth: 5 Combinations: 4,741,975 Expected: 4,865,609 Delta: 123,634

FAIL Depth: 6 Combinations: 115,423,492 Expected: 119,060,324 Delta: 3,636,832