Hi,
I'm fiddling a bit with perft and move generation.
Somehow what I wrote is not correct:
20/1
400/2
8902/3
197702/4 <--- should be: 197281
4894128/5 <--- should be: 4865609
My question now is: can one tell me what "happens" at depth 4 what doesn't happen in 1, 2 and 3?
Any idea is welcome.
strange perft results
Moderator: Ras
-
Greg Strong
- Posts: 388
- Joined: Sun Dec 21, 2008 6:57 pm
- Location: Washington, DC
Re: strange perft results
You might be permitting moves into check - that could account for the extra nodes.
-
Ferdy
- Posts: 4853
- Joined: Sun Aug 10, 2008 3:15 pm
- Location: Philippines
Re: strange perft results
Magnify it a bit like below.flok wrote:Hi,
I'm fiddling a bit with perft and move generation.
Somehow what I wrote is not correct:
20/1
400/2
8902/3
197702/4 <--- should be: 197281
4894128/5 <--- should be: 4865609
My question now is: can one tell me what "happens" at depth 4 what doesn't happen in 1, 2 and 3?
Any idea is welcome.
Code: Select all
perft 3
8 r n b q k b n r
7 o o o o o o o o
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 P P P P P P P P
1 R N B Q K B N R
a b c d e f g h
a2a3 - 380
a2a4 - 420
b2b3 - 420
b2b4 - 421
c2c3 - 420
c2c4 - 441
d2d3 - 539
d2d4 - 560
e2e3 - 599
e2e4 - 600
f2f3 - 380
f2f4 - 401
g2g3 - 420
g2g4 - 421
h2h3 - 380
h2h4 - 420
b1a3 - 400
b1c3 - 440
g1f3 - 440
g1h3 - 400
Perft 3 Summary
Count: 8902Code: Select all
perft 4
8 r n b q k b n r
7 o o o o o o o o
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 P P P P P P P P
1 R N B Q K B N R
a b c d e f g h
a2a3 - 8457
a2a4 - 9329
b2b3 - 9345
b2b4 - 9332
c2c3 - 9272
c2c4 - 9744
d2d3 - 11959
d2d4 - 12435
e2e3 - 13134
e2e4 - 13160
f2f3 - 8457
f2f4 - 8929
g2g3 - 9345
g2g4 - 9328
h2h3 - 8457
h2h4 - 9329
b1a3 - 8885
b1c3 - 9755
g1f3 - 9748
g1h3 - 8881
Perft 4 Summary
Count: 197281
Code: Select all
perft 5
8 r n b q k b n r
7 o o o o o o o o
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 P P P P P P P P
1 R N B Q K B N R
a b c d e f g h
a2a3 - 181046
a2a4 - 217832
b2b3 - 215255
b2b4 - 216145
c2c3 - 222861
c2c4 - 240082
d2d3 - 328511
d2d4 - 361790
e2e3 - 402988
e2e4 - 405385
f2f3 - 178889
f2f4 - 198473
g2g3 - 217210
g2g4 - 214048
h2h3 - 181044
h2h4 - 218829
b1a3 - 198572
b1c3 - 234656
g1f3 - 233491
g1h3 - 198502
Perft 5 Summary
Count: 4865609-
elcabesa
- Posts: 860
- Joined: Sun May 23, 2010 1:32 pm
Re: strange perft results
what ferdinand shown you is called DIVIDE 
with divide you can trace what move has the wrong perftcount and finally trace the problem..
I show you an example:
perft 4 is wrong.
you try divide 4 and see that e2e4 is wrong
you then setup the position after the move 2e4 and do DIVIDE 3 and see what move is wrong (e7e6)
you setup position startpos moves e2e4 e7e6 and do divide 2 and so on until you see where your move gen is wrong
with divide you can trace what move has the wrong perftcount and finally trace the problem..
I show you an example:
perft 4 is wrong.
you try divide 4 and see that e2e4 is wrong
you then setup the position after the move 2e4 and do DIVIDE 3 and see what move is wrong (e7e6)
you setup position startpos moves e2e4 e7e6 and do divide 2 and so on until you see where your move gen is wrong
-
syzygy
- Posts: 5956
- Joined: Tue Feb 28, 2012 11:56 pm
Re: strange perft results
To add a divide command to Stockfish, just insert this code into UCI::loop in uci.cpp:
(The last two lines are already present.)
Now you can do:
Code: Select all
else if (token == "divide" && (is >> token))
{
stringstream ss;
uint64_t total = 0;
int depth = atoi(token.c_str()) - 1;
StateInfo st;
for (MoveList<LEGAL> it(pos); *it; ++it)
{
pos.do_move(*it, st);
uint64_t cnt = depth == 0 ? 1 : Search::perft(pos, depth * ONE_PLY
);
pos.undo_move(*it);
sync_cout << move_to_uci(*it, pos.is_chess960())
<< ": " << cnt << sync_endl;
total += cnt;
}
sync_cout << "total: " << total << sync_endl;
}
else
sync_cout << "Unknown command: " << cmd << sync_endl;Now you can do:
Code: Select all
$ ./stockfish
position startpos moves e2e4 e7e5
divide 4
a2a3: 24064
b2b3: 25651
c2c3: 25661
d2d3: 26685
f2f3: 20660
g2g3: 25744
h2h3: 23929
a2a4: 25725
b2b4: 24237
c2c4: 23994
d2d4: 33576
f2f4: 26233
g2g4: 23900
h2h4: 25747
b1a3: 24774
b1c3: 26521
g1e2: 19080
g1f3: 23193
g1h3: 23927
f1e2: 23080
f1d3: 23990
f1c4: 27505
f1b5: 22748
f1a6: 24532
d1e2: 23946
d1f3: 31615
d1g4: 31502
d1h5: 26724
e1e2: 19944
total: 728887-
JVMerlino
- Posts: 1411
- Joined: Wed Mar 08, 2006 10:15 pm
- Location: San Francisco, California
Re: strange perft results
En Passant is the only thing I can think of that can happen at depth 4 and regularly causes make/unmake problems.flok wrote:Hi,
I'm fiddling a bit with perft and move generation.
Somehow what I wrote is not correct:
20/1
400/2
8902/3
197702/4 <--- should be: 197281
4894128/5 <--- should be: 4865609
My question now is: can one tell me what "happens" at depth 4 what doesn't happen in 1, 2 and 3?
Any idea is welcome.
jm
-
AlvaroBegue
- Posts: 932
- Joined: Tue Mar 09, 2010 3:46 pm
- Location: New York
- Full name: Álvaro Begué (RuyDos)
Re: strange perft results
En-passant captures aren't possible until the fifth move. I think leaving your king in check is more likely, although when I break my program in that particular way I get 197742/4 and 4897256/5, so it's probably not exactly that.JVMerlino wrote:En Passant is the only thing I can think of that can happen at depth 4 and regularly causes make/unmake problems.flok wrote:Hi,
I'm fiddling a bit with perft and move generation.
Somehow what I wrote is not correct:
20/1
400/2
8902/3
197702/4 <--- should be: 197281
4894128/5 <--- should be: 4865609
My question now is: can one tell me what "happens" at depth 4 what doesn't happen in 1, 2 and 3?
Any idea is welcome.
jm
-
sedicla
- Posts: 182
- Joined: Sat Jan 08, 2011 12:51 am
- Location: USA
- Full name: Alcides Schulz
Re: strange perft results
I fixed a lot of problems using the positions and numbers from here http://chessprogramming.wikispaces.com/Perft+Results
I implemented a function in my engine called perftx to validate those numbers.
Hope this helps, good luck.
I implemented a function in my engine called perftx to validate those numbers.
Hope this helps, good luck.
-
Sven
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: strange perft results
Hi Folkert,
ply 4, counted from initial chess position, is the first ply where illegal check evasions might occur since ply 3 is the first ply where giving check is possible. En passant is not involved yet, as well as castling and promotion. So it is very likely a check evasion problem, and that would definitely be related to defending against a diagonal check given by 2.Qa4, 2.Bb5 or 2.Qh5 since these are the only possible checks at ply 3.
For each of these three moves there are four ways how it can become a legal move, e.g. for 2.Qa4: 1.c4 (or c3) 1... d5 (or d6). Is it possible that you somehow count all pseudo-legal check evasions if they occur at the horizon (here at ply 4)? The perft(1) values in these 12 cases when ignoring the check are, very roughly estimated, 8x30 + 4x20 (the 20 for the Qh5 case) which sums up to 320. All legal evasions must be subtracted, which is 5+6+1 = 12, so that would explain a difference of roughly 320-12 = 308. But 197702 - 197281 = 421, so either I have overlooked something essential or you have a second problem.
EDIT: The second problem could be moving into check or ignoring a pin. That can happen as 2.Qa4 d6 (or d5), 2.Qg4 Kd7, 2.Ba3 Ke7, 2.Bg5 Ke7, 2.Qh5 f6 (or f5), or 2.Bc4 Kf7, and this would already explain the missing nodes in my calculation above.
As others stated, "divide" will solve it for you, of course.
Sven
ply 4, counted from initial chess position, is the first ply where illegal check evasions might occur since ply 3 is the first ply where giving check is possible. En passant is not involved yet, as well as castling and promotion. So it is very likely a check evasion problem, and that would definitely be related to defending against a diagonal check given by 2.Qa4, 2.Bb5 or 2.Qh5 since these are the only possible checks at ply 3.
For each of these three moves there are four ways how it can become a legal move, e.g. for 2.Qa4: 1.c4 (or c3) 1... d5 (or d6). Is it possible that you somehow count all pseudo-legal check evasions if they occur at the horizon (here at ply 4)? The perft(1) values in these 12 cases when ignoring the check are, very roughly estimated, 8x30 + 4x20 (the 20 for the Qh5 case) which sums up to 320. All legal evasions must be subtracted, which is 5+6+1 = 12, so that would explain a difference of roughly 320-12 = 308. But 197702 - 197281 = 421, so either I have overlooked something essential or you have a second problem.
EDIT: The second problem could be moving into check or ignoring a pin. That can happen as 2.Qa4 d6 (or d5), 2.Qg4 Kd7, 2.Ba3 Ke7, 2.Bg5 Ke7, 2.Qh5 f6 (or f5), or 2.Bc4 Kf7, and this would already explain the missing nodes in my calculation above.
As others stated, "divide" will solve it for you, of course.
Sven
-
xmas79
- Posts: 286
- Joined: Mon Jun 03, 2013 7:05 pm
- Location: Italy
Re: strange perft results
+1Sven Schüle wrote:Is it possible that you somehow count all pseudo-legal check evasions if they occur at the horizon (here at ply 4)?