算法生成字谜字谜、算法

2023-09-10 22:32:07 作者:西城痞子

给出的单词的列表,你会怎么去安排他们到一个填字格?

Given a list of words, how would you go about arranging them into a crossword grid?

它也不会像一个正确的填字游戏是对称的或类似的东西。基本上只是输出每一个单词的起始位置和方向

It wouldn't have to be like a "proper" crossword puzzle which is symmetrical or anything like that: basically just output a starting position and direction for each word.

会不会有任何Java实例可用?

Would there be any Java examples available?

推荐答案

我想出了一个解决方案,它可能不是最有效的,但它的作品不够好。基本上是:

I came up with a solution which probably isn't the most efficient, but it works well enough. Basically:

排序所有长度的话,降。 在第一个字,并将其放置在黑板上。 乘坐下一个字。 在通过所有那些已经在黑板上,看看是否有任何可能的交叉点(任何普通字母)这个词的词搜索。 如果没有通过所有的都在船上,并检查是否新词干扰词的可能的位置这个词,循环。 如果这个词不破板,然后将它放在那里,转到第3步,否则,继续搜索的地方(第4步)。 在继续循环下去,直到所有的话都无论是放置或无法放置。

这使得工作,但往往字谜相当差。有上面的一些改变我的基本配方进行拿出了较好的效果。

This makes a working, yet often quite poor crossword. There were a number of alterations I made to the basic recipe above to come up with a better result.

在生成纵横年底的基础上,有多少的话被放置(越多越好),给它一个分数,如何大板(越小越好),以及高度和宽度之间的比例(越接近1越好)。产生了一批填字游戏,然后比较他们的分数,并选择最好的一个。 运行迭代任意数量的相反,我已经决定要在时间的任意数量创造尽可能多的填字游戏的可能。如果你只有一个小的单词列表,那么你会得到几十个可能的填字游戏在5秒。较大的填字可能只有5-6可能性进行选择。 At the end of generating a crossword, give it a score based on how many of the words were placed (the more the better), how large the board is (the smaller the better), and the ratio between height and width (the closer to 1 the better). Generate a number of crosswords and then compare their scores and choose the best one. Instead of running an arbitrary number of iterations, I've decided to create as many crosswords as possible in an arbitrary amount of time. If you only have a small word list, then you'll get dozens of possible crosswords in 5 seconds. A larger crossword might only be chosen from 5-6 possibilities.