Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create an AI for tic tac toe in Python using ANN and genetic algorithm?

I'm very interested in the field of machine learning and recently I got the idea for a project for the next few weeks.
Basically I want to create an AI that can beat every human at Tic Tac Toe. The algorithm must be scalable for every n*n board size, and maybe even for other dimensions (for a 3D analogue of the game, for example).
Also I don't want the algorithm to know anything of the game in advance: it must learn on its own. So no hardcoded ifs, and no supervisioned learning.
My idea is to use an Artificial Neural Network for the main algorithm itself, and to train it through the use of a genetic algorithm. So I have to code only the rules of the game, and then each population, battling with itself, should learn from scratch.
It's a big project, and I'm not an expert on this field, but I hope, with such an objective, to learn lots of things.

  • First of all, is that possible? I mean, is it possible to reach a good result within a reasonable amount of time?
  • Are there good libraries in Python that I can use for this project? And is Python a suitable language for this kind of project?
like image 802
Einlar Avatar asked May 05 '16 17:05

Einlar


People also ask

Which algorithm is used for Tic Tac Toe in Python?

Minimax Algorithm is a decision rule formulated for 2 player zero-sum games (Tic-Tac-Toe, Chess, Go, etc.). This algorithm sees a few steps ahead and puts itself in the shoes of its opponent.

Can I create an AI with Python?

Python is commonly used to develop AI applications, such as improving human to computer interactions, identifying trends, and making predictions. One way that Python is used for human to computer interactions is through chatbots.


1 Answers

Yes, this is possible. But you have to tell your AI the rules of the game, beforehand (well, that's debatable, but it's ostensibly better if you do so - it'll define your search space a little better).

Now, the vanilla tic-tac-toe game is far too simple - a minmax search will more than suffice. Scaling up the dimensionality or the size of the board does make the case for more advanced algorithms, but even so, the search space is quite simple (the algebraic nature of the dimensionality increase leads to a slight transformation of the search space, which should still be tractable by simpler methods).

If you really want to throw a heavy machine learning technique at a problem, take a second look at chess (Deep Blue really just brute forced the sucker). Arimaa is interesting for this application as well. You might also consider looking at Go (perhaps start with some of the work done on AlphaGo)

That's my two cents' worth

like image 121
inspectorG4dget Avatar answered Sep 20 '22 09:09

inspectorG4dget