3

I am a university student (1st year) and I have an assignment to make a Tic Tac Toe console game using the ACM Library. I managed to make it working Player VS Player. Another part of this assignment requires me to make it work like Player VS Computer. The teacher told us not to create an AI but to make the computer ALWAYS win or tie. How can I implement this? I don't think that it is possible to implement that using a lot of if's and else's. Is there any smarter way?

I've created one constructor called Board which has all the methods needed to create, display, update the game board, to check if X's or O's win (or tie), and to check the string that the user inputs (In order to play user must type something like (row_space_column ---> example: "3 1")). I also created another file ("TicTacToe.java") which is the game itself.

So, what are your opinions? (The language i use is JAVA) (Sorry for my English, i am Greek) Thanks!

4

2 回答 2

1

Tic-Tac-Toe 是 AI 编程的一个很好的例子,因为只有相对少量的可能动作。

此外,如果你打得很好(你的 AI 希望能做到),你总是会赢或打成平手。

您可以很容易地测试每一个可能的动作,直到有人获胜 - 然后您采取最佳动作。

也许你应该看看MinMax 算法

还有很多井字游戏算法的示例实现。(如果你想要我可以给你一个帕斯卡:D)

编辑:我发现了一个关于制作井字游戏 AI 的非常好的教程。

于 2014-02-04T11:49:52.687 回答
1

前提:每个算法通过调整其行为以适应问题的特定实例以最大化成功机会来解决一般问题,即使它是由一个单独的 if 语句组成的,也被认为是智能代理。

鉴于此,您的任务定义不明确,无论如何,我尝试给您一些提示:

于 2014-02-04T12:35:54.937 回答