哪种算法将是最适合词搜索游戏类似与BOGGLE将是、最适合、哪种、算法

2023-09-11 07:24:50 作者:把星星揣进兜里

你们有些人可能熟悉被称为BOGGLE的游戏。

Some of you may be familiar with the game called "BOGGLE".

基本上游戏会显示混乱的信件是这样的:

Basically the game will display jumbled letters like this:

asdf  
wcrq  
nwoa  
erdf  

然后,你需要寻找在板上所有可能的答案。 不过我想开发手机游戏。 所以,这里是我计划:

Then you need to look for all the possible answer in the board. However I'm trying to develop a MOBILE GAME. So here is what I'm planning:

我会要求玩家去寻找一个字在给定的混乱的字母。

I will ask the player to look for a SINGLE word in the given jumbled letters.

例:寻找在这些信件字 CROWN

Example: look for the word CROWN in these letters:

asdf  
wcrq  
nwoa  
erdf  

然后,我需要跟踪的答案 CROWN 出这混乱的字母

但我不知道我应该如何实现这一点。

But I don't know how I should implement that.

我的问题是:

如何将自身混乱的字母,然后同时游戏中可以保持正确的答案? 在每次玩家痕迹正确的答案,接下来的查找单词将显示,然后一组新的杂乱字母必须是present 如果玩家跟踪正确的答案,接下来的查找应该立即出现这样的时候一定要遵守。 在该系统中必须检测的天气球员追查正确的答案与否。

注: 玩家可以追溯到他想,只要他不会跳到了一封信,以获得任意方向查找单词。

NOTE: The player can trace to any direction he wants as long he won't jump to a letter to get the "look for the word."

您能否提供算法和方法或数据结构来实现这一点?

Can you suggest algorithm and method or data structure to implement this?

我在寻找使用HTML5,JavaScript和CSS的解决方案。

I'm looking for a solution using HTML5, JavaScript and CSS.

样图:

推荐答案

嗯,我会做迭代深化与分支切断。例如:

Well, I would do iterative deepening with branch cutoff. For example:

1 2 3 4
5 6 7 8
9 0 A B
C D E F

有16深度为1的节点 [1,2,3,4,5,6,7,8,9,0,A,B,C,D,E,F] ,并从其中任何一个可以访问的邻居。例如,如果你选择1:

There are 16 depth 1 nodes [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, A, B, C, D, E, F] and from any of them you can visit neighbor. For example If you choose 1:

* 2 3 4
5 6 7 8
9 0 A B
C D E F

深度2个节点的名单将 [1,2],[1,6],[1,5]] ,那么你检查你的字典包含一个字开头的任何人。如果他们不这样做,那么你可以减少分支!这一点很重要,因为否则会有太多的工作要做。让我们假设 [1,2] 不存在,你选 [1,6]

List of depth 2 nodes would be [[1, 2], [1, 6], [1, 5]], then you check if your dictionary contains a word starting with any of them. If they do not then you can cut the branch! This is important, because otherwise there will be too much work to do. Lets assume [1, 2] did not exist and you picked [1, 6] :

* 2 3 4
5 * 7 8
9 0 A B
C D E F

深度2节点的清单将是 [[1,6,2],[1,6,3],[1,6,7],[1,6,A],[ 1,6,0],[1,6,9],[1,6,5] 。像以前一样,你继续下去,直到你到达一个节点,在没有下一步的行动。让我们假设它是 [1,6,2,5] 。现在你有最长的单词4个字母。之后,你检查,如果你得到一个更长的词。

List of depth 2 nodes would be [[1, 6, 2], [1, 6, 3], [1, 6, 7], [1, 6, A], [1, 6, 0], [1, 6, 9], [1, 6, 5]]. Like before you continue until you get to a node where there is no next move. Lets assume it is [1, 6, 2, 5]. Now you have longest word 4 letters long. After that you check if you get a longer word.

根据版本,你在玩,你可能要调整你采取什么样的结果。例如,在一些版本中,你没有得到加分,如果你得到一个字不再那么8个字母 - 例如:如果你发现你并不需要看得更远,前8个字母的单词。

Depending on version you are playing you might want to adjust what result you take. For example in some versions you do not get extra points if you get a word longer then 8 letters - ex: if you find first 8 letter word you do not need to look further.

我希望这将让你开始。

 
精彩推荐