填字游戏的逻辑

发布于 2024-09-06 08:05:01 字数 471 浏览 7 评论 0原文

我的任务是创建一个填字游戏,一个特定的填字游戏。所有的答案都已给出,但它们的位置却未知。程序必须读取具有如下板方案的文件:

0 1 0 0 0 0 0 0 1 0 0
0 1 0 1 1 1 1 1 1 1 1
0 1 0 1 0 0 1 0 1 0 1
0 S 1 1 0 1 1 1 1 0 1
0 1 0 0 1 0 1 0 1 0 0
1 1 1 1 1 1 1 S 1 1 0
0 0 0 0 1 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0

将每一列/行视为一个可能的答案。有没有办法解析这个文件并标记答案,而无需对每个字段使用 gazilion if's ? 其余逻辑如下:
- 在解析文件的基础上创建填字游戏。
- 用户从可能性列表中选择答案
- 用户单击答案的第一个块,如果所选答案的长度和字母与答案匹配 - 字段已更新

游戏板应该存储在二维数组中我猜,每个答案应该有字段索引?

I have a task to create a crossword, a specific one. All the answers are given, but their places are unknown. Program must read a file with board scheme like this :

0 1 0 0 0 0 0 0 1 0 0
0 1 0 1 1 1 1 1 1 1 1
0 1 0 1 0 0 1 0 1 0 1
0 S 1 1 0 1 1 1 1 0 1
0 1 0 0 1 0 1 0 1 0 0
1 1 1 1 1 1 1 S 1 1 0
0 0 0 0 1 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0

treating each column/row of ones as one possible answer. Is there any way to parse through this file and marking answers without using gazilion if's for each field ?
Rest of the logics is as follows :
- on the base of the parsed file crossword is created.
- user selects answers from lists of possibilities
- user clicks on the first block of Answer and if length and letters of selected answer and Answer match - fields are updated

Game board should be stored in 2d array I guess, and each Answer should have indexes of fields in it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

似最初 2024-09-13 08:05:01

填字游戏的构造一般来说是 NP 完全的(即 nxn 个 1 和 0 板以及从中选择答案的给定集合)。看看:http://en.wikipedia.org/wiki/List_of_NP-complete_problems其中只提到了这一点。 Garey和Johnson的经典著作也提到了这一点,说Exact cover by 3 set can be returned to it。

因此,您可能必须使用一些回溯/启发式方法来填充网格。

也许达特茅斯学院两名学生的项目报告会有所帮助:填字游戏生成器。它包含一些您可能可以使用的启发式方法。

当然,您似乎暗示有人参与其中,但尚不清楚您是否可以利用该人来填充网格,以及您的问题是否基本上是帮助用户解决问题的 UI 编程问题。

Crossword puzzle construction is NP-Complete in general (i.e nxn board of 1s and 0s and a given set from which to pick answers). Look at: http://en.wikipedia.org/wiki/List_of_NP-complete_problems which just mentions this. Garey and Johnson's classic book also has a mention of this, saying Exact cover by 3 sets can be reduced to it.

So, you probably will have to use some backtracking/heuristic to fill the grid.

Perhaps this project report of two students from Dartmouth college will be of some help: Crossword Puzzle Generator. It contains some heuristics which you might be able to use.

Of course, you seem to imply there is a human involved, but it is not clear if you can leverage that person to fill the grid and whether your problem is basically some UI programming problem in helping the user out.

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