World Chess Move Generation Speed Competition 2015

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

World Chess Move Generation Speed Competition 2015

Post by Henk »

[d] r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1

How much time does your engine need to compute KiwiPete perft(4) = 4085603 ?

Skipper needs 18 seconds.

Use a method like this otherwise the result is dependent on the perft implementation.

Code: Select all

 public int Perft(int depth)
 {            
      var moves = ListLegalMoves(this);
      if (depth == 1) return moves.Count;

      int count = 0;
      foreach (mv in moves)
      {             
            var capture = mv.GetCapture(this);               
            mv.Apply(this);
            count += Perft(depth - 1);
            mv.TakeBack(this, capture);              
       }
       return count;
}
Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: World Chess Move Generation Speed Competition 2015

Post by Henk »

Perhaps this is more readable:

Code: Select all

public int Perft(int depth) 
{            
      var moves = LegalMoves(this); 
      if (depth == 1) return moves.Count; 

      int count = 0; 
      foreach (move in moves) 
      {                              
            do(move); 
            count += Perft(depth - 1); 
            undo(move);              
       } 
       return count; 
} 
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: World Chess Move Generation Speed Competition 2015

Post by cdani »

The results should be using the the same cpu, or pondered somehow.

Code: Select all

Andscacs 0.84016 by Daniel Jose
pf r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1
perft 4
4085603
ms: 52  n/s: 78569288
User avatar
Ajedrecista
Posts: 1971
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Re: World Chess Move Generation Speed Competition 2015.

Post by Ajedrecista »

Hello Henk:
Henk wrote:[d] r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1

How much time does your engine need to compute KiwiPete perft(4) = 4085603 ?

Skipper needs 18 seconds.

Use a method like this otherwise the result is dependent on the perft implementation.

Code: Select all

 public int Perft(int depth)
 {            
      var moves = ListLegalMoves(this);
      if (depth == 1) return moves.Count;

      int count = 0;
      foreach (mv in moves)
      {             
            var capture = mv.GetCapture(this);               
            mv.Apply(this);
            count += Perft(depth - 1);
            mv.TakeBack(this, capture);              
       }
       return count;
}
JetChess is not a chess engine but a perft counter.

I guess that times are somewhat misleading because different computers will bring different times for the same engine.

Anyway, here I go with some runs by JetChess in an Intel Pentium D930 (3 GHz) of year 2006. JetChess is single core, 32-bit and hash will vary. One run per ply:

Code: Select all

r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1

------------------------

perft(1) = 48
Time: 0 ms (0:00:00.000).
Hash = 64 MB.

------------------------

perft(2) = 2,039
Time: 0 ms (0:00:00.000).
Hash = 64 MB.

------------------------

perft(3) = 97,862
Time: 1 ms (0:00:00.001).
Hash = 64 MB.

------------------------

perft(4) = 4,085,603
Time: 55 ms (0:00:00.055).
Hash = 128 MB.

------------------------

perft(5) = 193,690,690
Time: 1.493 s (0:00:01.493).
Hash = 256 MB.

------------------------

perft(6) = 8,031,647,685
Time: 41.698 s (0:00:41.698).
Hash = 512 MB.

------------------------

perft(7) = 374,190,009,323
Time: 796.203 s (0:13:16.203).
Hash = 1024 MB.
Regards from Spain.

Ajedrecista.
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: World Chess Move Generation Speed Competition 2015.

Post by hgm »

Well, the code Henk shows actually is a bulk-counting perft. So I guess dedicated perft counters are allowed. Qperft is basically Joker's move generator.

Reposting a qperft run from the time when Skipper still got the wrong count:

Code: Select all

C:\cygwin\home\perft>perft 6 "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/
R3K2R w KQkq - 0 1"
 - - - - - - - - - - - -
 - - - - - - - - - - - -
 - - r . . . k . . r - -
 - - p . p p q p b . - -
 - - b n . . p n p . - -
 - - . . . P N . . . - -
 - - . p . . P . . . - -
 - - . . N . . Q . p - -
 - - P P P B B P P P - -
 - - R . . . K . . R - -
 - - - - - - - - - - - -
 - - - - - - - - - - - -

Quick Perft by H.G. Muller
Perft mode: No hashing, bulk counting in horizon nodes

perft( 1)=           48 ( 0.000 sec)
perft( 2)=         2039 ( 0.000 sec)
perft( 3)=        97862 ( 0.000 sec)
perft( 4)=      4085603 ( 0.047 sec)
perft( 5)=    193690690 ( 1.719 sec)
perft( 6)=   8031647685 (78.644 sec)
So 47 msec. Don't remember which machine this was, BTW.
Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: World Chess Move Generation Speed Competition 2015

Post by Henk »

What a huge difference with 18 seconds. Perhaps my KingInCheck routine is much too slow. Also it calls my normal move generator which sorts the moves etcetera which makes no sense.
Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: World Chess Move Generation Speed Competition 2015

Post by Henk »

I used a slimmer move generator and now I get 4 seconds. Still too much. Perhaps you use the last move information in your KingInCheck routine.
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: World Chess Move Generation Speed Competition 2015

Post by hgm »

Well, qperft does not do fully legal move generation. It doesn't generate illegal moves with pinned pieces (which saves it some time), so the only moves that would have to be tested to see if it puts itself in check are King moves and e.p. capture. So it makes those at the 1-ply level. And it then tests for check using the 0x88 attack test for all non-Pawns in the piece list, and testing the two board squares from which it could be checked by a Pawn.
op12no2
Posts: 490
Joined: Tue Feb 04, 2014 12:25 pm
Full name: Colin Jenkins

Re: World Chess Move Generation Speed Competition 2015

Post by op12no2 »

Henk wrote:Also it calls my normal move generator which sorts the moves...
In a chess (not perft) context, have you tried sorting on demand in the main loop - getNextBestMove() kinda thing - that way you haven't done all that sorting for nothing in nodes that return >= beta early.
Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: World Chess Move Generation Speed Competition 2015

Post by Henk »

I sort all non captures. I remember extracting the move with maximum value instead of sorting was not a performance gain. Maybe for captures for there are less but I did not test that.