简单的AI井字游戏 [英] Simple tic-tac-toe AI

查看:43
本文介绍了简单的AI井字游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这已经被问了很多,我已经搜索了其他代码,但我所看到的大部分内容似乎并不完美(永远不会丢失),而且简单、优雅和高效.而且我无法决定哪种类型的解决方案适合该描述.

I know this has been asked a lot and I've searched other code but most of what I've seen doesn't seem flawless (never loses) and simple, elegant and efficient. And I'm unable to decide which type of solution would fit that description.

我见过的解决方案是:

(1) 使用极小极大值和 alpha-beta 剪枝.这对我来说似乎很复杂,对于这样一个简单的游戏来说可能没有必要?是不是太复杂了?如果没有,我是否需要进行大量硬编码,还是我误解了算法?

(1) Using minimax with alpha-beta pruning. This seems complicated to me and possibly unnecessary for such a simple game? Is it probably too complicated? If not, would I need to do a lot of hard coding or am I misunderstanding the algorithm?

(2) 使用来自维基百科的伪代码策略编写您的代码......我不确定如何实现这一点.例如,它只是说检查叉子".这些检查中的大多数是否会通过拥有一组 winsLines 并检查它们是否被填充或类似的东西来完成?如果没有,有人可以给我提示什么数据结构或有关如何实现伪代码中提出的检查的任何基本技巧:http://en.wikipedia.org/wiki/Tic-tac-toe#Strategy.我还看到一些算法为X"方格和O"方格提供数值,然后使用总和来决定获胜者,但我不明白为什么这特别有用.

(2) Write your code using the pseudocode strategy from Wikipedia... I'm not exactly sure how to implement this. For example, it just says "check for forks". Would most of these checks be done by having an array of winningLines and checking if they'd be filled in or something like that? If not, can someone give me hints on what data structures or any basic tips on how to implement the checks posed in the pseudocode here: http://en.wikipedia.org/wiki/Tic-tac-toe#Strategy . I've also seen algorithms that give a numerical value to an 'X' square and an 'O' square and then use the sum to decide the winner but I don't see why this is particularly useful.

还有其他合理的解决方案吗?

推荐答案

老实说,在处理 AI 和启发式算法时,最简单的任务会很快变得复杂.极小极大方法将为您提供最佳结果,考虑到您正在实施人工智能,这应该不会太难.这是基于 2 人回合的游戏逻辑的既定标准.

To be honest, when dealing with AI and heuristics, the most simple tasks can become complicated very quickly. The minimax approach is going to give you the best results and it shouldn't be too difficult considering the fact that you are implementing AI. It is an established standard with 2 player turn based gaming logic.

查看此网站...它对井字棋 AI 和极小极大实现提供了一些很好的见解.

Check out this website... it gives some good insight into tic-tac-toe AI and the minimax implementation.

http://www.ntu.edu.sg/home/ehchua/programming/java/JavaGame_TicTacToe_AI.html

注意到有人写了蛮力"……这最终将成为实现极小极大启发式的一种低效方式.基于其他玩家的最后一步迭代每一个可能的移动只是实现启发式的另一种方式......除了在我看来,它似乎需要更多的工作.Minimax 的实现将简单而有效.

Noticing that someone wrote "Brute Force"... this is going to end up being an inefficient way of the implementation of the heuristics involved in minimax. Iteration through every possible move based on the other players last move is just another way to implement a heuristic.. except it seems to be, in my opinion, more work. Minimax implementation will be simple and effective.

编辑 2:

更简单的实现"是相对的.Minimax 是标准,正如我在评论中所说,您可以操纵启发式以适应您正在寻找的情况......

"Simpler implementation" is somewhat relative. Minimax is the standard and as I said in the comment you can manipulate the heuristic to suit the cases you are looking for...

我希望我能告诉你最简单的方法,但有很多变量取决于你的游戏在代码中的植入.

I wish I could tell you the simplest way but there are so many variables dependent on the implantation of your game in code.

接受建议,看看你的游戏实现,然后看看什么最适合你!

Take the suggestions, look at you game implementation, and then see what suits you best!

对一个人来说简单的事情对另一个人来说可能很复杂.我只是想为您提供选择,而 minimax 非常可靠.也许尝试调整它以满足您的需求.

What is simple to one person might be complicated to another. I'm just trying to give you options and minimax is pretty solid. Maybe try adjusting it to fit your needs.

编辑 3:

如果您需要更多指导,请告诉我.我很乐意提供帮助.

Let me know if you need more direction. I'm happy to help.

这篇关于简单的AI井字游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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