gpt4 book ai didi

c# - 递归失败

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:30:20 24 4
gpt4 key购买 nike

我写了一个递归函数。由于某种原因,它在第一次运行后不会调用自己。它只是从循环中取出下一个项目,而不深入。我正在使用 Visual Studio 10,而且 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);
}
}

最佳答案

this.GeneratePath(presentDepth);

应该是

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

关于c# - 递归失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1524619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com