PHP 令人困惑的游戏
对于一个项目,我正在考虑用 PHP 构建一个 Boggle 类型的游戏。 我在网上看到的所有解决方案都使用了某种基于树或哈希的方法。
PHP 中是否内置了类似的数据结构? 关于如何处理当前字母板上出现的单词有什么建议吗?
For a project I am considering building a Boggle type game in PHP. All of the solutions I have seen online have used some sort of tree or hash based approach.
Are there any similar data structures built into PHP? Any advice on how to handle figuring out what words are present on a current board of letters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
PHP 确实在该语言中内置了哈希数据结构。 不过,它们通常称为关联数组。
这个网站对它们有一个非常简短的解释。
PHP does have hash data structures built into the language. They are generally called associative arrays, though.
This website has a very brief explanation of them.
您真的需要弄清楚这些字母可以包含哪些单词吗?
一种简单的方法是简单地让用户猜测一个单词,检查黑板上是否存在正确的字母,然后检查该单词是否是真实的单词。
这很简单,但是您无法告诉用户还剩下多少单词。
Do you really need to figure out what words are available with the letters?
A simple method would be to simply let the user guess a word, check that the correct letters exist on the board, then check that the word is a real word.
This would be simple, however you would not be able to tell the user how many words are remaining.
您可能想查看 这个问题。 它提供了许多关于如何对令人难以置信的求解器进行编程的解决方案。 大多数都是用 Python 编写的,但我也在那里发布了一个 PHP 解决方案。 它有点慢(大约 2 秒来计算所有内容),但它应该是一个很好的起点。
You might want to check out this question. It provides a lot of solutions on how to program a boggle solver. Most are in Python, but I also posted there a PHP solution. It is kind of slow (~2 seconds to calculate everything) but it should be a good starting point.