其中算法将最为合适的解决像&QUOT一个词搜索游戏;惊奇"与Python [英] Which algorithm would fit best to solve a word-search game like "Boggle" with Python

查看:222
本文介绍了其中算法将最为合适的解决像&QUOT一个词搜索游戏;惊奇"与Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编码类似惊奇那里的玩家应该发现里面一个大词游戏随机字母串制成。

I'm coding a game similar to Boggle where the gamer should find words inside a big string made of random letters.

例如,有五个阵列字符串中是这样的。五排,由六个字母每一个:

For example, there are five arrays with strings inside like this. Five rows, made of six letters each one :

AMSDNS
MASDOM
ASDAAS
DSMMMS
OAKSDO

所以,游戏的用户应该使用提供了下列限制和规则记的字母组成单词:

So, the users of the game should make words using the letters available with the following restrictions and rules in mind:

  • 在它不可能重复相同的字母,使单词。 IM谈论的物理的信,在游戏中是一个骰子。其不可能使用相同的骰子两次或更多次以使字。
  • 在它不可能跳任何字母,使单词。这使单词的字母必须是连续的。
  • 的用户能够在任何方向她想要进一步移动而没有任何限制比上面提到的两个。因此其可能要到顶部,然后底部,然后在右边,然后再次顶部,等等。因此,运动去找的话可能会莫名其妙地不稳定。

我想知道如何去通过所有的字符串,使字。要知道,我也会用文字txt文件的话。

I want to know how to go through all the strings to make words. To know the words Im gonna use a txt file with words.

我不知道如何设计一个算法,它能够执行搜索,特别是在思考,需要找到的话,该走势飘忽,尊重的限制了。

I don't know how to design an algorithm that is able to perform the search, specially thinking about the erratic movements that are needed to find the words and respecting the restrictions, too.

我已经实现了UX,扔骰子,并填补了桌上游戏逻辑,以及所有为六字母骰子的逻辑。

I already implemented the UX, the logic to throw the dice and fill the boardgame, and all the logic for the six-letters dice.

但是这部分的不容易,我想读你的建议,这一有趣的挑战。

But this part its not easy, and I would like to read your suggestions to this interesting challenge.

即时通讯使用的Python这个游戏,因为是我用code语言,而我最喜欢的语言。但是,一个算法本身的解释或建议,应该是语言的环境也不错,独立的。

Im using Python for this game because is the language I use to code and the language that I like the most. But an explanation or suggestion of an algorithm itself, should be nice too, independently of the language.

推荐答案

基本算法很简单。

  • 对于每个瓦片,做到以下几点。
    • 在开始一个空的候选词,然后访问当前瓦片。
    • 访问瓷砖按照以下步骤。
      • 瓷砖的位置的信添加到候选词。
      • 是候选字一个字已知?如果是这样,将其添加到发现单词列表。
      • 是候选字preFIX任何已知的字?
        • 如果是这样,对于尚未访问过,形成候选词,参观各相邻片(即,递归)。
        • 如果没有,原路返回(停止审批新的瓷砖这个候选词)。
        • For each tile, do the following.
          • Start with an empty candidate word, then visit the current tile.
          • Visit a tile by following these steps.
            • Add the tile's position's letter to the candidate word.
            • Is the candidate word a known word? If so, add it to the found word list.
            • Is the candidate word a prefix to any known word?
              • If so, for each adjacent tile that has not been visited to form the candidate word, visit it (i.e., recurse).
              • If not, backtrack (stop considering new tiles for this candidate word).

              为了让事情顺利问这个问题的时候是这个词的任何字在我的字典一个preFIX,考虑重新presenting你的字典作为的线索。正为这两个词和prefixes提供快速的查找时间。

              To make things run smoothly when asking the question "is this word a prefix of any word in my dictionary", consider representing your dictionary as a trie. Tries offer fast lookup times for both words and prefixes.

              这篇关于其中算法将最为合适的解决像&QUOT一个词搜索游戏;惊奇"与Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆