QSearch perft

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Henk
Posts: 5618
Joined: Mon May 27, 2013 8:31 am

QSearch perft

Post by Henk » Fri May 24, 2019 10:36 am

I try to find out if my quiescence search does not accidentally skip moves.
So I extracted a perft out of that code. It does only promotions, captures and en passant moves.

Result for kiwiPete: "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1"

depth 4: 3980
depth 5: 25800

Don't know if these figures are correct.

Are there any other perft figures published/posted for quiescence search ?

User avatar
xr_a_y
Posts: 586
Joined: Sat Nov 25, 2017 1:28 pm
Location: France

Re: QSearch perft

Post by xr_a_y » Fri May 24, 2019 11:04 am

You dont generate check evasion so are you stoping when King is captured ?

Henk
Posts: 5618
Joined: Mon May 27, 2013 8:31 am

Re: QSearch perft

Post by Henk » Fri May 24, 2019 11:13 am

If king is captured it was an illegal move so it returns 0. Just like a normal perft definition but limited to performing only legal captures, promotions and en passant moves.

Joost Buijs
Posts: 880
Joined: Thu Jul 16, 2009 8:47 am
Location: Almere, The Netherlands

Re: QSearch perft

Post by Joost Buijs » Fri May 24, 2019 12:03 pm

Henk,

With only captures and promotions (and check evasions) I get on kiwipete:

Depth 4 = 3690
Depth 5 = 25347

So my numbers are different, maybe something wrong with your enpassant captures?

Of course there is a possibility that my perft() is in error, but I doubt it.

Henk
Posts: 5618
Joined: Mon May 27, 2013 8:31 am

Re: QSearch perft

Post by Henk » Fri May 24, 2019 12:27 pm

Strange my code does ep moves. Can't find it. Or maybe minor promotions. Don't know yet.

I created an extra QPerft with code that collects captures, promotions and ep moves similar to code used in my normal perft test giving standard values for kiwi pete 4 and 5 so that code must be correct. But QPerft getting same figures as posted.

Simpel QPerft:

Code: Select all

        public static ulong Perft2(IChessPosition position, int depth, bool epMoves = true)
        {

            var moves = new List<IMoveBase>();
            position.CollectCaptures(moves, depth, epMoves); // collects captures, epmoves, promotions
            if (depth == 1) return (ulong)moves.Count;
            ulong count = 0;
            var board = position.Board;

            var other = board.Other;
            foreach (MoveBase mv in moves)
            {
                var field = mv.GetCaptureLocation(position);
                var capture = field == 0 ? none : board.PieceSort(field);
                mv.Apply(position);
                count += Perft2(position, depth - 1, true);  //board.PieceKind(mv.End) == Pawn_Kind);
                mv.TakeBack(position, capture, field, other);
            }
            return count;
        }
  
Last edited by Henk on Fri May 24, 2019 12:43 pm, edited 1 time in total.

Joost Buijs
Posts: 880
Joined: Thu Jul 16, 2009 8:47 am
Location: Almere, The Netherlands

Re: QSearch perft

Post by Joost Buijs » Fri May 24, 2019 12:43 pm

These are the counts I get per move at depth 4, maybe it helps.

g2h3: 381
d5e6: 436
e5g6: 495
e5d7: 642
e5f7: 475
e2a6: 343
f3h3: 397
f3f6: 521

Maybe somebody else can verify these numbers.

I think the difference is due to the fact that you don't generate check-evasions, because check-evasions will contain non captures too. So you have to generate evasions when the king is in check. You have to do this in quiescence too, otherwise your quiescence will make very big errors.
Last edited by Joost Buijs on Fri May 24, 2019 1:05 pm, edited 3 times in total.

Henk
Posts: 5618
Joined: Mon May 27, 2013 8:31 am

Re: QSearch perft

Post by Henk » Fri May 24, 2019 12:59 pm

Henk wrote:
Fri May 24, 2019 12:27 pm
Strange my code does ep moves. Can't find it. Or maybe minor promotions. Don't know yet.

I created an extra QPerft with code that collects captures, promotions and ep moves similar to code used in my normal perft test giving standard values for kiwi pete 4 and 5 so that code must be correct. But QPerft getting same figures as posted.

Simpel QPerft:

Code: Select all

        public static ulong Perft2(IChessPosition position, int depth, bool epMoves = true)
        {

            var moves = new List<IMoveBase>();
            position.CollectCaptures(moves, depth, epMoves); // collects captures, epmoves, promotions
            if (depth == 1) return (ulong)moves.Count;
            ulong count = 0;
            var board = position.Board;

            var other = board.Other;
            foreach (MoveBase mv in moves)
            {
                var field = mv.GetCaptureLocation(position);
                var capture = field == 0 ? none : board.PieceSort(field);
                mv.Apply(position);
                count += Perft2(position, depth - 1, true);  //board.PieceKind(mv.End) == Pawn_Kind);
                mv.TakeBack(position, capture, field, other);
            }
            return count;
        }
  
Wait this code can't be correct for CollectCaptures does not check whether move is legal (it may place king in check)
I first have to change that. But then I expect the figures to be even lower then I posted before.

Henk
Posts: 5618
Joined: Mon May 27, 2013 8:31 am

Re: QSearch perft

Post by Henk » Fri May 24, 2019 1:12 pm

Joost Buijs wrote:
Fri May 24, 2019 12:03 pm
Henk,

With only captures and promotions (and check evasions) I get on kiwipete:

Depth 4 = 3690
Depth 5 = 25347

So my numbers are different, maybe something wrong with your enpassant captures?

Of course there is a possibility that my perft() is in error, but I doubt it.
Now I get:

Depth 4 = 3622
Depth 5 = 24467

Joost Buijs
Posts: 880
Joined: Thu Jul 16, 2009 8:47 am
Location: Almere, The Netherlands

Re: QSearch perft

Post by Joost Buijs » Fri May 24, 2019 1:20 pm

You really have to generate check-evasions when the king is in check (blocking moves and king moves to get out of check) if you want to be correct.

Unfortunately I have to modify my code if I want to do it your way (to check if the king is captured), so it is not straightforward to compare our numbers.

abulmo2
Posts: 166
Joined: Fri Dec 16, 2016 10:04 am
Contact:

Re: QSearch perft

Post by abulmo2 » Fri May 24, 2019 1:24 pm

Joost Buijs wrote:
Fri May 24, 2019 12:43 pm
These are the counts I get per move at depth 4, maybe it helps.

g2h3: 381
d5e6: 436
e5g6: 495
e5d7: 642
e5f7: 475
e2a6: 343
f3h3: 397
f3f6: 521

Maybe somebody else can verify these numbers.

I think the difference is due to the fact that you don't generate check-evasions, because check-evasions will contain non captures too. So you have to generate evasions when the king is in check. You have to do this in quiescence too, otherwise your quiescence will make very big errors.
I get the same number as you :

Code: Select all

 g2h3              381
 d5e6              436
 e5g6              495
 e5d7              642
 e5f7              475
 e2a6              343
 f3h3              397
 f3f6              521
total   :            3690 leaves

and at depth 5:

Code: Select all

 g2h3             2617
 d5e6             3202
 e5g6             3482
 e5d7             4086
 e5f7             2908
 e2a6             2285
 f3h3             2768
 f3f6             3999
total   :           25347 leaves

Richard Delorme

Post Reply