Henk wrote: ↑Mon Apr 12, 2021 11:01 pm
I think I fixed the bug in movecount.
Now it is back to normal. That is less than 80kn/sec.
Perft in my C# chess engine runs at about 80M nodes per second on a single core of a mid-range Intel i7-7700 CPU running at 3.6 GHz. So shurely shome mishtake?
Test which computes these four perfts take about 8 seconds. So maybe I get hardly 1M nodes per second.
But for each perft it first builds the hashtables per square needed for magic bitboard movegeneration. While they should be only computed once.
private static long Perft(Board board, int depth)
{
var moves = new LegalMoves(board);
if (depth == 1) //no need to apply the moves before counting them
return moves.Count;
long sum = 0;
Board next = new Board(board);
foreach (var move in moves)
{
next.Copy(board);
next.Play(move);
sum += Perft(next, depth - 1);
}
return sum;
}
LegalMoves is derived from an actual List<Piece> with a custom constructor that takes in a board and collects all the moves like this:
public LegalMoves(Board reference) : base(40)
{
_reference = reference;
_reference.CollectMoves(Consider);
_reference = null;
}
public void Consider(Move move)
{
//only add if the move doesn't result in a check for active color
_tempBoard.Copy(_reference);
_tempBoard.Play(move);
if (_tempBoard.IsChecked(_reference.ActiveColor))
return;
Add(move);
}
public void CollectMoves(Action<Move> moveHandler)
{
for (int square = 0; square < 64; square++)
CollectMoves(moveHandler, square);
}
As you can see that's a very straight forward (wasteful) implementation and not optimized for speed and so I would expect that any bitboard based engine should be much faster than the 20s it took me to compute the perft on my machine. (Ryzen 3600)
Minimal Chess (simple, open source, C#) - Youtube & Github Leorik (competitive, in active development, C#) - Github & Lichess
Could it be the way how you deal with objects in general? E.g. passing them by value, making copies, temporary instances, maintaining many small instances, ...
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)