Skip to content

Impossibly bad search performance #29

@JamesLear92

Description

@JamesLear92

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions