Monte Carlo Tree Search: A Guide | Built In (2024)

In computer science, Monte Carlo tree search (MCTS) is a heuristic search algorithm for decision processes, most notably those employed in software that plays board games. It’s a probabilistic and search algorithm that combines classic tree search implementations alongside machine learning principles of reinforcement learning.

Monte Carlo Tree Search Definition

Monte Carlo tree search is a heuristic search algorithm that relies on intelligent tree search to make decisions. It’s most often used to perform game simulations, but it can also be utilized in cybersecurity, robotics and text generation.

Before we dive into the Monte Carlo tree search algorithm, we need to understand a few basics. So, let’s discuss a few terms first that will help us understand the problem space.

What Is Monte Carlo Tree Search?

Monte Carlo tree search is a method that relies on intelligent tree search that balances exploration and exploitation. It performs random sampling in the form of simulations and stores the statistics of actions to make more educated choices in each subsequent iteration.

Monte Carlo tree search only searches a few layers deep into the tree and prioritizes which parts of the tree to explore. It then simulates the outcome rather than exhaustively expanding the search space. In doing so, it limits how many evaluations it has to make.

The individual evaluation relies on the playout/simulation in which the algorithm effectively plays the game from a given starting point all the way to the leaf state by making completely random decisions, and then it records the results which is then used to update all the nodes in the random path all the way to the root. When it completes the simulation, it then selects the state that has the best rollout score.

To better understand how it works, you need to understand combinatorial games and game trees.

More on Machine LearningRandom Forest Regression in Python Explained

What Is a Combinatorial Game?

Monte Carlo tree search is used in combinatorial games. These are sequential games with perfect information. The preconditions for a combinatorial game include:

  • It must be a two-player game
  • It must be a sequential game in which players take turns to play their move.
  • It must have a finite set of well-defined moves.

Examples of a combinatorial game include, chess, checkers, Go and tic-tac-toe.

What Is a Game Tree?

A game tree is a graph representing all possible game states within a combinatorial game. A game tree is a directed graph whose nodes represent a particular state of the game, and the edges represent possible next states from the given state. The leaf states of the tree represent either a win, lose or tie for the game.

This can be used to measure the complexity of a game, as it represents all the possible ways a game can pan out.

For example, following is the game tree of Tic-Tac-Toe:

Monte Carlo Tree Search: A Guide | Built In (1)

If we want to replace one player with a computer program (AI), we need to pick the move that leads to the winning leaf node path.

There are various algorithms we can use to solve this problem, including:

  • Minimax.
  • Minimax with alpha, beta pruning.
  • A* search.

These algorithms traverse the complete game tree (in various fashions) to pick the optimal move. But what if the game tree size is very large?

When the game has a high branching factor it’s not always computationally possible to traverse the entire game tree to pick the best move. This is when Monte Carlo tree search is very effective. Monte Carlo tree search (MCTS) utilizes a heuristic search algorithm method to solve the game tree.

How Monte Carlo Tree Search Works

The Monte Carlo tree search algorithm has four phases. We assign state values and number of interactions for each node.

1. Selection

In this phase, the algorithm uses the following formula to calculate the state value of all the possible next moves and pick the one which gives the maximum value.

Monte Carlo Tree Search: A Guide | Built In (2)

The first term vi is the exploitation term. The second term, which is the square-root of lg N/ni is the exploration term.The algorithm considers both nodes, one with a high state value, and one that is relatively unexplored, to make a selection. This contact defines the weightage between exploitation and exploration.

At the beginning when no node is explored, it makes a random selection because there is no data available to make a more educated selection.

When a node is unexplored, i.e. when n1=0, the second term becomesand thus obtains a maximum possible value and automatically becomes a candidate for selection. Thus, the equation makes sure all children get selected at least once.

2. Expansion

In this phase, we expand from one node and start looking one level deeper. The node we expanded from becomes the parent (current state), and its children become the possible next moves.

3.Simulation

In this phase, we simulate the game from the selected child node in phase one and continue the game by making random choices until we reach an end state, i.e. a win, lose or draw. Let’s assign following values to these results/outcomes:

  • Win = +1
  • Loose = -1
  • Draw = 0

4. Backpropagation

In this phase, we backpropagate and update the result we found in the simulation phase to all the nodes in the random path we traversed and up till the root node. This sets the value v(i)which is then used in the selection phase of the formula.

Advantages of the Monte Carlo Tree Search

There are several advantages to using a Monte Carlo tree search, including:

  1. Domain agnostic.
  2. The ability to halt it at any time.
  3. Asymmetric tree growth.

1. Domain Agnostic

Monte Carlo tree search doesn’t require any strategic or tactical knowledge about the given domain to make reasonable decisions. The algorithm can function effectively with no knowledge of a game, apart from its legal moves and end conditions. This means that a single Monte Carlo tree search implementation can be reused for a number of games with little modification.

However, in more complex games, such as those with high branching factor or real-time ones, as well as in various practical domains, like transportation, scheduling or security, an efficient Monte Carlo tree search application often requires a problem-dependent modification or integration with other techniques.

2. Anytime Algorithm

The algorithm can be halted at any time to return the current best estimate. The search tree built thus far may be discarded or preserved for future reusability.

3. Asymmetric

Monte Carlo tree search performs asymmetric tree growth that adapts to the topology of the search space. The algorithm visits more interesting nodes more often and focuses its search time in more relevant parts of the tree.

This makes the Monte Carlo tree search suitable for games with large branching factors, such as 19x19 Go. Such large combinatorial spaces typically cause problems for standard depth- or breadth-based search methods, but the adaptive nature of Monte Carlo tree search means that it will eventually find optimal moves and focus its search effort there.

More on Machine LearningWhat We Can Learn From 4 Game-Playing AIs

Disadvantages of Monte Carlo Tree Search

There are a few disadvantages to Monte Carlo tree search, including:

1. Memory Requirement

As the tree growth becomes rapid after a few iterations, it requires a huge amount of memory.

2. Reliability

There is a reliability issue with Monte Carlo tree search. In certain scenarios, there might be a single branch or path that might lead to loss against the opposition when implemented for those turn-based games. This is mainly due to the vast amount of combinations and each of the nodes might not be visited enough number of times to understand its result or outcome in the long run.

3. Iterations

Monte Carlo tree search algorithm needs a huge number of iterations to be able to effectively decide the most efficient path. So, there is a bit of a speed issue there.

Monte Carlo Tree Search Applications

Monte Carlo tree search has various use cases, including:

1. Game simulation

It’s used in two-player board games like tic-tac-toe, Chess and Go.

2. Security

Malware is one of the biggest threats in IT security, with millions of malicious applications released every year at an ever growing rate. For this reason, automated techniques based on machine learning are fundamental tools for helping security experts in analyzing and classifying dangerous software. Active malware analysis is one that focuses on acquiring knowledge about dangerous software by executing actions that trigger a response in the malware. It uses Monte Carlo tree search.

3. Robotics

Mobile robots hold great promise in reducing the need for humans to perform jobs such as vacuuming, seeding, harvesting, painting, search and rescue and inspection. In practice, these tasks must often be done without an exact map of the area and could be completed more quickly through the use of multiple robots working together. Many multi-robots on-line coverage path planning algorithms have been developed and Monte Carlo tree search planner is now being used because of its efficient completion time.

4. Text Generation

Monte Carlo Tree search is used in simulation-based natural language generation that accounts for both building a correct syntactic structure and reflecting the given situational information as input for the generated sentence. The Monte Carlo tree search for this nontrivial search problem in simulation, uses context-free grammar rules as search operators.

Monte Carlo Tree Search Example

To run through an example, we need a simple game from which we can draw a game tree. So let’s invent a hypothetical game.

  • The Game: Pair
  • Number of players: 2
  • Number of Boxes in the board: 4

To win, a player has to play two adjacent boxes.

Monte Carlo Tree Search: A Guide | Built In (3)
Monte Carlo Tree Search: A Guide | Built In (4)
  • Green leaves are the winning positions, i.e +1 (Total 6 Nodes).
  • Yellow leaves are a draw, i.e 0 (Total 4 Nodes)
  • Red leaves are losing positions, i.e -1 (Total 2 Nodes).

Iteration 1

1. Selection, Expansion

  • S0 is the initial state from which we need to pick the next move between m1 and m2, which will result in either state S1 or S2.
  • Here we calculate the upper confidence bound (UCB) value for both S1 and S2, since both are leaf node the value will be infinity for both and hence we randomly pick S1 and simulate S1.
Monte Carlo Tree Search: A Guide | Built In (5)

2. Simulation S1

  • Since S1 is leaf node and not visited, we simulated the game with random moves till the leaf node.
  • For simplicity we only simulate once and make m3 and m4 moves which results in a draw.
  • As per the game Draw = 0, we assign S4=0 and increase the count of visit N4=1.

3. Backpropagation

  • Now we backpropagate this result all the way to the root.
Monte Carlo Tree Search: A Guide | Built In (6)

Iteration 2

1. Selection

  • Now, we again need to calculate the UCB values for S1 and S2. After one interaction:

Monte Carlo Tree Search: A Guide | Built In (7)
Since N is 0 for S2, we pick S2 this time.

Monte Carlo Tree Search: A Guide | Built In (8)

2. Simulation S1

  • Since S1 is a leaf node and wasn’t visited, we simulated the game with random moves until we reach the leaf node.
  • For simplicity, we’ll only simulate once and make m5 and m6 moves, which results in a win.
  • As per the game Win = 1, we assign S6=1 and increase the count of visit N4=1.

3. Backpropagation

  • Now, we backpropagate this result all the way to the root.
Monte Carlo Tree Search: A Guide | Built In (9)

Iteration 3

1. Selection

  • Now, we again need to calculate the UCB values for S1 and S2. After the second interaction:

Monte Carlo Tree Search: A Guide | Built In (10)

As N = 1 both and for S2UCB = 1, which is higher. So, we pick S2 again this time.

Iteration 4

  • Now, S2 has already been visited and we again select it. So now, we expand S2.
  • S2 will become the parent, and we’ll run the selection on its children.
Monte Carlo Tree Search: A Guide | Built In (11)
  • Here, we calculate the UCB Value for S7, S8 and S9. Since all are leaf nodes, the value will be infinity. So we will randomly pick S7 and Simulate S7.
Monte Carlo Tree Search: A Guide | Built In (12)

2. Simulation S7

  • Since S7 is a leaf node and wasn’t visited, we simulated the game with random moves until we reached the leaf node.
  • For simplicity, we only simulate once and make m10 moves, which results in a win.
  • As per the game, Win = 1, so, we assign S10=1 and increase the count of visit N4=1.

Backpropagation

  • Now, we backpropagate this result all the way to the root.

More on Machine LearningAn Introduction to Prompt Engineering

Monte Carlo Tree Search Example Results

Because this is an anytime algorithm, if we stop it here, UCB value for S2 > S1, m2 will be a favorable move. So the algorithm chooses move M2 (second place) over move M1 (corner place) because it was part of more iterations and had a higher score.

The more the algorithm plays the game, the more data it gathers about the different possible moves and makes better decisions.

Monte Carlo Tree Search: A Guide | Built In (2024)

FAQs

What are the disadvantages of Monte-Carlo Tree Search? ›

Disadvantages of Monte Carlo Tree Search:

This is mainly due to the vast amount of combinations and each of the nodes might not be visited enough number of times to understand its result or outcome in the long run.

Is Monte-Carlo Tree Search model free? ›

From what I understand, Monte Carlo Tree Search Algorithm is a solution algorithm for model free reinforcement learning (RL). Monte Carlo Tree Search is a planning algorithm. It can be considered part of RL, in a similar way to e.g. Dyna-Q.

What are the 4 steps of the Monte-Carlo Tree Search? ›

The four steps of the Monte Carlo tree search (MCTS) process: selection, expansion, simulation, and backup.

What is Monte-Carlo Tree Search reinforcement learning? ›

Monte Carlo Tree Search (MCTS) is an anytime search algorithm, especially good for stochastic domains, such as MDPs. It can be used for model-based or simulation-based problems. Smart selection strategies are crucial for good performance.

What are the flaws of the Monte Carlo simulation? ›

Monte Carlo methods also have some limitations and challenges, such as the trade-off between accuracy and computational cost, the curse of dimensionality, the reliability of random number generators, and the verification and validation of the results.

Why use Monte Carlo tree search? ›

Monte Carlo tree search is a heuristic search algorithm that relies on intelligent tree search to make decisions. It's most often used to perform game simulations, but it can also be utilized in cybersecurity, robotics and text generation.

What is tree search in Monte Carlo for dummies? ›

The main concept of monte carlo tree search is a search. Search is a set of traversals down the game tree. Single traversal is a path from a root node (current game state) to a node that is not fully expanded. Node being not-fully expanded means at least one of its children is unvisited, not explored.

Is Monte Carlo simulation worth it? ›

A Monte Carlo simulation can help an investor see the possible effects of many different rates of return, rather than just looking at the average or any other fixed value. The Monte Carlo Method can do the same for other sorts of analysis, including those with a large number of variables.

Which chess engines use MCTS? ›

What makes the Princhess engine different is its use of the MCTS (Monte-Carlo Tree Search) algorithm. 99% of chess engines use the Alpha-Beta algorithm, but there are exceptions. The most recognized is Lc0, which can play beautiful and extremely powerful chess.

What games use Monte Carlo tree search? ›

MCTS was combined with neural networks in 2016 and has been used in multiple board games like Chess, Shogi, Checkers, Backgammon, Contract Bridge, Go, Scrabble, and Clobber as well as in turn-based-strategy video games (such as Total War: Rome II's implementation in the high level campaign AI) and applications outside ...

Who invented MCTS? ›

MCTS has been originally proposed in the work by Kocsis and Szepesvári (2006) and by Coulom (2006), as an algorithm for making computer players in Go.

How many simulations are there in Monte Carlo tree search? ›

Save this question. In the mcts algorithm described in Wikipedia, it performs exactly one playout(simulation) in each node selection.

What are the disadvantages of Monte Carlo search? ›

The three most significant drawbacks of Monte Carlo analysis are its reliance on high-quality input data, the computational intensity of the method, and the challenge of accurately interpreting results. Each of these aspects fundamentally influences the effectiveness and reliability of the technique.

When was Monte-Carlo Tree Search invented? ›

Monte Carlo Tree Search, invented in 2007, provides a possible solution. Selecting good child nodes, starting from the root node R, that represent states leading to better overall outcome (win).

What is Monte-Carlo Tree Search decision-making? ›

Monte Carlo Tree Search (MCTS) is a heuristic algorithm used in AI decision-making processes, particularly in complex situations. It employs intelligent tree search techniques to assist AI in making informed choices. MCTS is widely applied in various domains such as game simulation, robotics, and security.

What are the disadvantages of Monte Carlo simulation CFA? ›

Limitations of Monte Carlo Simulations

It is fairly complex and can only be carried out using specially designed software that may be expensive. The complexity of the process may cause errors, leading to wrong results that can be potentially misleading.

Which of the following are disadvantages Monte Carlo simulation? ›

The disadvantages of the Monte Carlo method are that the error term is probabilistic and it can be computationally burdensome to achieve a high level of accuracy. The disadvantages of the Monte Carlo method include slow convergence and inefficiency in handling multi-modal distributions.

What are the disadvantages of Markov chain Monte Carlo? ›

Disadvantages Of MCMC:
  • Computational Cost: MCMC simulations can be computationally expensive, especially when dealing with high-dimensional distributions or requiring high accuracy. ...
  • Convergence Issues: Ensuring proper convergence of the Markov chain to the target distribution is crucial.
Mar 1, 2024

Top Articles
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6407

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.