调试深度递归的实用技巧? [英] Practical tips debugging deep recursion?

查看:63
本文介绍了调试深度递归的实用技巧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一种棋盘游戏算法,其中使用递归遍历一棵大树,但是,它的表现不符合预期.我该如何处理?您在这些情况下有何经验?

I'm working on a board game algorithm where a large tree is traversed using recursion, however, it's not behaving as expected. How do I handle this and what are you experiences with these situations?

更糟的是,它使用alpha-beta修剪,这意味着从不访问树的整个部分,并且只要满足某些条件,它就会停止递归.我也不能将搜索深度更改为一个较小的数字,因为尽管它是确定性的,但结果的确随搜索深度的不同而有所不同,并且在较低的搜索深度下它的表现可能与预期的一样(并且确实如此).

To make things worse, it's using alpha-beta pruning which means entire parts of the tree are never visited, as well that it simply stops recursion when certain conditions are met. I can't change the search-depth to a lower number either, because while it's deterministic, the outcome does vary by how deep is searched and it may behave as expected at a lower search-depth (and it does).

现在,我不会问你我的代码中的问题在哪里?"但是我正在寻找常规技巧,工具,可视化效果,以及用于调试此类代码的任何内容.就个人而言,我正在使用C#进行开发,但是欢迎使用所有工具.尽管我认为这可能最适用于命令式语言.

Now, I'm not gonna ask you "where is the problem in my code?" but I am looking for general tips, tools, visualizations, anything to debug code like this. Personally, I'm developing in C#, but any and all tools are welcome. Although I think that this may be most applicable to imperative languages.

推荐答案

记录.广泛登录您的代码.以我的经验,日志记录是解决此类问题的解决方案.当很难弄清楚代码在做什么时,将其广泛记录是一个很好的解决方案,因为它使您可以从代码内部输出内部状态;这确实不是一个完美的解决方案,但据我所知,它比使用任何其他方法都更好.

Logging. Log in your code extensively. In my experience, logging is THE solution for these types of problems. when it's hard to figure out what your code is doing, logging it extensively is a very good solution, as it lets you output from within your code what the internal state is; it's really not a perfect solution, but as far as I've seen, it works better than using any other method.

这篇关于调试深度递归的实用技巧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆