zeristor
zeristor

Reputation: 429

Failure to recurse

I have written a recursive function. For some reason it just won't call itself after it has run through for the first time. It just takes the next item from the loop without going down deeper. I am using Visual Studio 10, and am lacking sleep.

public IEnumerable<string> GeneratePath(int depth)
{
    int presentDepth = depth;
    char currentPosition = this.workingPath[presentDepth];
    presentDepth++;

    foreach (char nextPosition in this.moveTable.GetPossibleNextPositions(currentPosition))
    {
        this.workingPath[presentDepth] = nextPosition;

        if (presentDepth < (ChessPiece.targetDepth - 1))
        {
            Console.WriteLine("At least this wasn't ignored:{0}", new string(this.workingPath));
            this.GeneratePath(presentDepth);
        }
        else
            yield return new string(this.workingPath);
    }
}

Upvotes: 0

Views: 119

Answers (1)

leppie
leppie

Reputation: 117270

this.GeneratePath(presentDepth);

should be

foreach (var i in this.GeneratePath(presentDepth))
{
  yield return ...
}

Upvotes: 8

Related Questions