Question

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!

Was it helpful?

Solution

Tic-Tac-Toe is a nice example for AI programming because there are only a relative small number of possible moves.

Also if you play perfectly (what your AI hopefully does) you will always win or make a tie.

You can quite easily test every possible move until someone wins - and then you take the optimal move.

Perhaps you should take a look at the MinMax Algorithm

There are also a lot of example Implementations of Tic-Tac-Toe Algorithms. (If you want i could give you one in Pascal :D )

Edit: I found a really nice tutorial on making a Tic-Tac-Toe AI.

OTHER TIPS

Premise: each algorithm that solves a generic problem by adapting its behavior to the specific instance of the problem in order to maximizes the chances of success is considered an intelligent agent, even if it's composed by one single if statement.

Given this, your assignment is not well defined, anyway, I try to give you some hints:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top