简单的tic-tac-toe AI [英] Simple tic-tac-toe AI

查看:164
本文介绍了简单的tic-tac-toe 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)使用minimax进行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和启发式时,最简单的任务可能会很快变得复杂。 minimax方法将为您提供最佳结果,考虑到您正在实施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.

查看这个网站...它提供了一些很好的洞察tic-tac-toe AI和minimax实施。

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中涉及的启发式的低效方式。基于其他玩家最后一次移动的每一个可能移动的迭代只是实现启发式的另一种方式..除了在我看来似乎更多的工作。 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.

Edit2:

更简单的实现有点相对。 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.

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

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