*That* sounds weird ... You need to fix your perft function first to be able to verify that your movegen changes work well.leanchess wrote: ↑Tue Dec 07, 2021 6:59 pmThank you, that must be it; cannot verify right now due to a bug in the move generator.Ras wrote: ↑Tue Dec 07, 2021 11:14 am So if you make an illegal move that leads to a king capture, you cancel not only the result from that move, but the whole node? That doesn't look right. I'd guess it could work like this:
Code: Select all
for (pCurr = moves; pCurr != pEnd; ++pCurr) { make(*pCurr); n = perft(pEnd, depth - 1); unmake(*pCurr); if (n > 0) count += n; }
Weird perft logic
Moderator: Ras
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Weird perft logic
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
-
- Posts: 181
- Joined: Sun Dec 08, 2019 8:16 pm
- Full name: Dmitry Shechtman
Re: Weird perft logic
Code: Select all
uint64_t perft(move_t* moves, uint8_t depth) {
move_t *pCurr, *pEnd;
uint64_t count = 0;
if (!depth)
return 1;
if (!(pEnd = gen_all(moves)))
return 0;
for (pCurr = moves; pCurr != pEnd; ++pCurr) {
make(*pCurr);
count += perft(pEnd, depth - 1);
unmake(*pCurr);
}
return count;
}
As for "quazi-legal", is that something new? Perhaps it deserves a mention on the wiki?
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Weird perft logic
Did you notice any of my replies on this topic? The code above still has the same problem that I already mentioned:leanchess wrote: ↑Wed Dec 08, 2021 9:35 amThanks again, Ras!Code: Select all
uint64_t perft(move_t* moves, uint8_t depth) { move_t *pCurr, *pEnd; uint64_t count = 0; if (!depth) return 1; if (!(pEnd = gen_all(moves))) return 0; for (pCurr = moves; pCurr != pEnd; ++pCurr) { make(*pCurr); count += perft(pEnd, depth - 1); unmake(*pCurr); } return count; }
As for "quazi-legal", is that something new? Perhaps it deserves a mention on the wiki?
Code: Select all
if (!depth)
return 1;
if (!(pEnd = gen_all(moves)))
return 0;
Reversing the order:
Code: Select all
if (!(pEnd = gen_all(moves)))
return 0;
if (!depth)
return 1;
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
-
- Posts: 181
- Joined: Sun Dec 08, 2019 8:16 pm
- Full name: Dmitry Shechtman
Re: Weird perft logic
You are correct, of course.Sven wrote: ↑Wed Dec 08, 2021 11:08 am Did you notice any of my replies on this topic? The code above still has the same problem that I already mentioned:does also count leaves resulting from an illegal move. Reversing the order:Code: Select all
if (!depth) return 1; if (!(pEnd = gen_all(moves))) return 0;
would not. It is slower but you can't get around that with a king-capture algorithm ...Code: Select all
if (!(pEnd = gen_all(moves))) return 0; if (!depth) return 1;
Code: Select all
uint64_t perft(move_t* moves, uint8_t depth) {
move_t *pCurr, *pEnd;
uint64_t count = 0;
if ((pEnd = gen_all(moves))) {
if (!depth)
return 1;
for (pCurr = moves; pCurr != pEnd; ++pCurr) {
make(*pCurr);
count += perft(pEnd, depth - 1);
unmake(*pCurr);
}
}
return count;
}
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Weird perft logic
After that change, what does your perft return now for depth=2, 3, 4 from startpos?
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Weird perft logic
Watch out for bishop captures 
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
-
- Posts: 181
- Joined: Sun Dec 08, 2019 8:16 pm
- Full name: Dmitry Shechtman
-
- Posts: 1062
- Joined: Tue Apr 28, 2020 10:03 pm
- Full name: Daniel Infuehr
Re: Weird perft logic
Enpassant not working? its mostly something to do with the edges of the board.
Are you using Juddperft Test-External?
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Daniel Inführ - Software Developer
-
- Posts: 181
- Joined: Sun Dec 08, 2019 8:16 pm
- Full name: Dmitry Shechtman
Re: Weird perft logic
So as not to completely lose my sanity, I started over using C# (and even got it to look not too ugly):
That works, but is obviously very slow.
However, as soon as I try to do it by the book (see? I even named the function the same!):
I am again getting perft(3) = 8890.
Code: Select all
ulong Perft(Move* start, int depth)
{
Move* end = start;
if (!AddMoves(ref end))
return 0;
if (depth == 0)
return 1;
ulong count = 0;
for (Move* curr = start; curr != end; ++curr)
{
Make(*curr);
count += Perft(end, depth - 1);
Unmake(*curr);
}
return count;
}
However, as soon as I try to do it by the book (see? I even named the function the same!):
Code: Select all
ulong Perft(Move* start, int depth)
{
Move* end = start;
if (depth == 0)
return 1;
AddMoves(ref end);
ulong count = 0;
for (Move* curr = start; curr != end; ++curr)
{
Make(*curr);
if (!IsInCheck())
count += Perft(end, depth - 1);
Unmake(*curr);
}
return count;
}
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Weird perft logic
I do not understand why perft(3) now returns a bigger number than before. The correction in perft() should only have affected perft(4) and higher since there are no pseudo-legal but illegal moves within the first three plies. So probably you made more changes?
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)