The following project is an implement of a tic-tac-toe algoritm that never takes a lose.
If you think you can beat it, try it out:
The algoritm was taken in the book of Pedro Domingos, "The Master Algorithm" and it's the following on
- If you or your opponent has two in a row, play on the remaining square.
- Otherwise, if there’s a move that creates two lines of two in a row, play that.
- Otherwise, if the center square is free, play there.
- Otherwise, if your opponent has played in a corner, play in the opposite corner.
- Otherwise, if there’s an empty corner, play there.
- Otherwise, play on any empty square.
If you don't know anything about artificial intelligence and want to know a litle beat I really recommend you the book.
This implement is build on top of a tic-tac-toe project made by Borna Šepić. That means the mecanism of the game is built by him, and was forked by his Tic-Tac-Toe repo
I have costumized the Borna aproach and gave it a little of my taste. So the user can choose being the first or second to play.