How I taught sklearn algorithm to play Tic-Tac-Toe.

What is Tic-Tac-Toe?

Tic-Tac-Toe or X & O is a game that is played by 2 players (X and O) that are placing their marks on a 3x3 game board. The first player that places his marks (X or O) on a diagonal, vertical or horizontal axes is the winner.

Used Logic

During this project, there where tested 8 algorithms at playing Tic-Tac-Toe. They were playing in a virtual environment created in Python 3 programming language, that apply the rules of this game on a 3x3 matrix, that is supposed to be the game board. The algorithms learned to play this game using a database of randomly generated gemes. The generator algorithm generated 5000 games, which was split based on the winner of the game (X or O), these games were split on turns, that represent the samples in the project’s databese, 9279 turns per every dataset.

  • This feature very well virtualizes an average statistical player, being how practically each of us is starting the Tic-Tac-Toe game.

Chosen algorithms

For this project I chosen 8 algorithms. Each algorithm must fulfill the next criteria:

  • It must have the possibility to return the probabilities as an output.

The research process

The algorithms played with each other 100 games, the winner was the algorithm that won the majority of games. If the scores were between 40 or 60 the result is a tie.

The interpetation of results

From all used algorithms in this research the most victories are taken by TreeDecisionClassifier. The next place in the rankings were also taken by CARTs (Classification and Regression Trees) — Random Forest, SVC (exception, it’s not a CART), Ada Boost and Gradient Boosting.

A young and passionate student about Data Science and Machine Learning, dreaming of becoming one day an AI Engineer.