-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
Hi, i've had a play around with this and I find a way to search moves quicky.
I just tried the following to enumerate moves:
static void Main(string[] args)
{
var game = new ChessGame();
Console.WriteLine("Beginning Search...");
var depth = 4;
var expectedMoveCount = 206603;
var start = DateTime.Now;
var count = Search(game, 0, depth);
Console.WriteLine("Moves found: " + count.Count() + " - Depth: " + depth + " Expected: " + expectedMoveCount);
Console.WriteLine("Seconds Taken: " + (DateTime.Now - start).TotalSeconds);
}
static IEnumerable<Move> Search(ChessGame game, Move move, int currentDepth, int targetDepth)
{
game.MakeMove(move, true);
yield return move;
if (currentDepth < targetDepth)
foreach (var item in (Search(game, currentDepth + 1, targetDepth)))
yield return item;
game.Undo();
}
static IEnumerable<Move> Search(ChessGame game, int currentDepth, int targetDepth)
{
foreach (var move in game.GetValidMoves(game.WhoseTurn))
{
if (currentDepth < targetDepth)
{
game.MakeMove(move,true);
yield return move;
foreach (var item in (Search(game, currentDepth + 1, targetDepth)))
yield return item;
game.Undo();
}
}
}
But for a depth of 4, it enumerated the right number of moves, but took 198 seconds. That's only about 1000 moves a second.
Is this a major performance issue, or is this me using the search methods incorrectly?
Metadata
Metadata
Assignees
Labels
No labels