views:

73

answers:

1

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);
    }
}
+7  A: 
this.GeneratePath(presentDepth);

should be

foreach (var i in this.GeneratePath(presentDepth))
{
  yield return ...
}
leppie
Doh! Thanks. Here's to more sleep.
Geoff Hogg