MCTS Tic Tac Toe Playground


The goal of this playground is show how the Monte Carlo Tree Search (MCTS) algorithm works, applied to a simple two player game. It is oriented towards people who are acquainted with the theory of MCTS but experience difficulties implementing it. Below is a basic and (hopefully) easy to follow implementation demonstrating the game play of Tic Tac Toe. For ease of reading the four main steps of the algorithm are indicated as comments in the code.


The code below does not use best practices in programming or MCTS implementation. This playground is to be perceived as a proof of concept example of how the algorithm works. If you want you can contribute by making it more accessible by restructuring it or by translating the code to other languages.


Create your playground on
This playground was created on, our hands-on, knowledge-sharing platform for developers.
Go to