Javascript 数独代码有时会挂起

发布于 2024-12-24 19:52:21 字数 316 浏览 6 评论 0原文

我有一种感觉,我已经不知所措了。我正在尝试编写一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄司 2024-12-31 19:52:21

由于您只是随机放置数字,因此您的谜题可能会陷入没有新数字可以满足您已有数字的状态。例如:

123|   |
456|   |
78 |9  |
---+---+---
   |   |
   |   |
   |   |
---+---+---
   |   |
   |   |
   |   |

您可能需要添加回溯,以便您的算法可以在检测到这种情况时逆转它所做的更改。

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:

123|   |
456|   |
78 |9  |
---+---+---
   |   |
   |   |
   |   |
---+---+---
   |   |
   |   |
   |   |

You will probably need to add backtracking so your algorithm can reverse changes it's made when you detect this kind of situation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文