Javascript 数独代码有时会挂起
我有一种感觉,我已经不知所措了。我正在尝试编写一个 javascript 数独游戏。这里没有发布我的所有代码,而是一个指向我的游戏的链接。我的来源是这里现在,它只是(试图)吐出解决方案网格。我的问题是,代码有时会无限期地挂起。其他时候,它会在 Firefox 中在一秒内成功创建网格。感谢您的帮助!
I have a feeling that I'm in over my head. I'm trying to write a javascript sudoku game. Instead of posting all of my code, here's a link to my game. My source is here Right now, it just (attempts to) spits out the solution grid. My problem is, the code will hang indefinitely sometimes. Other times it will successfully create a grid in under a second in Firefox. Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您只是随机放置数字,因此您的谜题可能会陷入没有新数字可以满足您已有数字的状态。例如:
您可能需要添加回溯,以便您的算法可以在检测到这种情况时逆转它所做的更改。
Since you're just randomly placing numbers, it's possible for your puzzle to get into a state where no new number can satisfy what you've already got. For example:
You will probably need to add backtracking so your algorithm can reverse changes it's made when you detect this kind of situation.