1 of 50

NAIL122 AI for Games�Monte Carlo Tree Search�Peter Guba, Jakub Gemrot

Faculty of Mathematics and Physics

Charles University

2 of 50

Motivation

3 of 50

Motivation�Why should you care?

4 of 50

Motivation�Why should you care?

5 of 50

Motivation�Why should you care?

6 of 50

Motivation�Why should you care?

7 of 50

Motivation�Why should you care?

8 of 50

An intuitive explanation

9 of 50

MCTS – High-level description

10 of 50

MCTS�High-level description

MCTS iteration

Image adapted from: Santos, A., Santos, P. A., & Melo, F. S. (2017, August). Monte carlo tree search experiments in hearthstone. In 2017 IEEE Conference on Computational Intelligence and Games (CIG) (pp. 272-279). IEEE.

 

 

 

 

 

 

 

11 of 50

MCTS�High-level description

MCTS iteration

Image adapted from: Santos, A., Santos, P. A., & Melo, F. S. (2017, August). Monte carlo tree search experiments in hearthstone. In 2017 IEEE Conference on Computational Intelligence and Games (CIG) (pp. 272-279). IEEE.

 

 

 

 

 

 

 

Evaluation

12 of 50

MCTS�High-level description

MCTS iteration

Image adapted from: Santos, A., Santos, P. A., & Melo, F. S. (2017, August). Monte carlo tree search experiments in hearthstone. In 2017 IEEE Conference on Computational Intelligence and Games (CIG) (pp. 272-279). IEEE.

 

 

 

 

 

 

 

Evaluation

 

13 of 50

What have you learned so far?�

Go to this link and try to write down your current understanding of MCTS.

14 of 50

Monte Carlo Tree Search Roots�Monte Carlo Method

15 of 50

Monte Carlo Method�Approximating values

 

Source: https://en.wikipedia.org/wiki/Monte_Carlo_integration

int i, throws = 99999, insideCircle = 0;

double randX, randY, pi;

srand(time(NULL));

for (i = 0; i < throws; ++i) {

randX = rand() / (double) RAND_MAX;

randY = rand() / (double) RAND_MAX;

if (randX * randX + randY * randY < 1)

++insideCircle;

}

pi = 4.0 * insideCircle / throws;

 

16 of 50

17 of 50

Monte Carlo Integration�Approximating values

 

Source: https://en.wikipedia.org/wiki/Monte_Carlo_integration

Integral we want to estimate.

Random variable following some distribution, e.g., uniform.

Integral estimation using N points.

18 of 50

Monte Carlo Tree Search Roots�Multi-armed bandit problem

19 of 50

Multi-armed Bandit�How to gamble properly

 

We kinda expect to have a simulator we can interact with in order to solve the problem before we pull an arm in real-life.

20 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

21 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

Auer, P., Cesa-Bianchi, N., & Fischer, P. (2002). Finite-time analysis of the multiarmed bandit problem. Machine learning47(2), 235-256.

 

22 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

Auer, P., Cesa-Bianchi, N., & Fischer, P. (2002). Finite-time analysis of the multiarmed bandit problem. Machine learning47(2), 235-256.

In MCTS, this will correspond to the number of pulls in the parent node, not the overall total number of pulls!!!

23 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

Auer, P., Cesa-Bianchi, N., & Fischer, P. (2002). Finite-time analysis of the multiarmed bandit problem. Machine learning47(2), 235-256.

Exploitation part

 

 

24 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

Where does this part come from?

25 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

26 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

27 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

 

28 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

29 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

30 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

 

31 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

32 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

33 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

34 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

This shrinks rapidly with increasing number of pulls, so the UCB formula provides an upper bound on the true mean value with a high degree of confidence (hence the name).

35 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

Auer, P., Cesa-Bianchi, N., & Fischer, P. (2002). Finite-time analysis of the multiarmed bandit problem. Machine learning47(2), 235-256.

36 of 50

How to select which arm to pull?�Upper Confidence Bounds

 

37 of 50

Monte Carlo Tree Search�Going step by step

38 of 50

MCTS�High-level description

MCTS iteration

Image adapted from: Santos, A., Santos, P. A., & Melo, F. S. (2017, August). Monte carlo tree search experiments in hearthstone. In 2017 IEEE Conference on Computational Intelligence and Games (CIG) (pp. 272-279). IEEE.

 

 

 

 

 

 

 

Evaluation

 

39 of 50

MCTS�Step 1: Selection

MCTS iteration

Image adapted from: Santos, A., Santos, P. A., & Melo, F. S. (2017, August). Monte carlo tree search experiments in hearthstone. In 2017 IEEE Conference on Computational Intelligence and Games (CIG) (pp. 272-279). IEEE.

 

 

 

 

 

 

 

Evaluation

 

 

40 of 50

MCTS�Step 2: Expansion

MCTS iteration

Image adapted from: Santos, A., Santos, P. A., & Melo, F. S. (2017, August). Monte carlo tree search experiments in hearthstone. In 2017 IEEE Conference on Computational Intelligence and Games (CIG) (pp. 272-279). IEEE.

 

 

 

 

 

 

 

Evaluation

 

Expansion:�If we are using UCB, we must try all available moves before building the next ply. ��Unless we have some game-specific knowledge available, we cannot discriminate between the moves without trying them first.

The strategy here is then either to choose uniformly at random or have the actions taken in some predetermined order.

41 of 50

MCTS�Step 3: Simulation

MCTS iteration

Image adapted from: Santos, A., Santos, P. A., & Melo, F. S. (2017, August). Monte carlo tree search experiments in hearthstone. In 2017 IEEE Conference on Computational Intelligence and Games (CIG) (pp. 272-279). IEEE.

 

 

 

 

 

 

 

Evaluation

 

Simulation:�Again, without game-specific knowledge, we can’t discriminate between the available moves, so we pick the moves at random.

42 of 50

MCTS�Step 3.5: Evaluation

MCTS iteration

Image adapted from: Santos, A., Santos, P. A., & Melo, F. S. (2017, August). Monte carlo tree search experiments in hearthstone. In 2017 IEEE Conference on Computational Intelligence and Games (CIG) (pp. 272-279). IEEE.

 

 

 

 

 

 

 

Evaluation

 

Evaluation:�Simplest way: 1 = win, 0 = loss (optionally 0.5 = draw)

  • May not give good results if the game is too long
  • May bee too coarse for games where winning isn’t all that matters

It is common to use some game score we are maximizing or some heuristic as the reward (in which case, they UCB formula may need to be adjusted).

43 of 50

MCTS�Step 4: Backpropagation

MCTS iteration

Image adapted from: Santos, A., Santos, P. A., & Melo, F. S. (2017, August). Monte carlo tree search experiments in hearthstone. In 2017 IEEE Conference on Computational Intelligence and Games (CIG) (pp. 272-279). IEEE.

 

 

 

 

 

 

 

Evaluation

 

Back-propagation:�The back-propagation is then about updating values we track for nodes in order to compute their UCB values. Just take care to correctly recognize, which player is to play in order to correctly interpret values for wins and losses.

44 of 50

MCTS�Choosing a move

MCTS iteration

Image adapted from: Santos, A., Santos, P. A., & Melo, F. S. (2017, August). Monte carlo tree search experiments in hearthstone. In 2017 IEEE Conference on Computational Intelligence and Games (CIG) (pp. 272-279). IEEE.

 

 

 

 

 

 

 

Evaluation

 

BestChild:�Finally, selecting a best root child may follow different strategies.

Max – highest reward

Robust – the most visited

Max-Robust – Max+Robust, if none exist continue the search (violating any-time principle)

Secure – maximizes lower confidence bound

45 of 50

Monte Carlo Tree Search�End Notes

46 of 50

MCTS�Pros and Cons

Pros:

  • Simple, anytime and asymmetric
  • Doesn’t require game-specific knowledge but can easily be augmented to take advantage of it
  • Proved to converge to perfect play in infinity

Cons:

  • Doesn’t deal too well with large branching factors
  • It may need to run for a large number of iterations which can be costly both in terms of memory and time
  • Problem identifying trap states and making sacrifices

47 of 50

MCTS�Observations

 

48 of 50

MCTS�History till 2009

1990 Abramson demonstrates that Monte Carlo simulations can be used to evaluate value of state [1].

1993 Brugmann [31] applies Monte Carlo methods to the field of computer Go.

1998 Ginsberg’s GIB program competes with expert Bridge players.

1998 MAVEN defeats the world scrabble champion [199].

2002 Auer et al. [13] propose UCB1 for multi-armed bandit, laying the theoretical foundation for UCT.

2006 Coulom [70] describes Monte Carlo evaluations for tree-based search, coining the term Monte� Carlo tree search.

2006 Kocsis and Szepesvari [119] associate UCB with tree-based search to give the UCT algorithm.

2006 Gelly et al. [96] apply UCT to computer Go with remarkable success, with their program MOGO.

2006 Chaslot et al. describe MCTS as a broader framework for game AI [52] and general domains [54].

2007 CADIAPLAYER becomes world champion General Game Player [83].

2008 MOGO achieves dan (master) level at 9 9 Go [128].

2009 FUEGO beats top human professional at 9 9 Go [81].

2009 MOHEX becomes world champion Hex player [7].

Taken from: Browne, C. B., Powley, E., Whitehouse, D., Lucas, S. M., Cowling, P. I., Rohlfshagen, P., ... & Colton, S. (2012). A survey of monte carlo tree search methods. IEEE Transactions on Computational Intelligence and AI in games4(1), 1-43.

49 of 50

MCTS�Literature and other resources

Browne, C. B., Powley, E., Whitehouse, D., Lucas, S. M., Cowling, P. I., Rohlfshagen, P., ... & Colton, S. (2012). A survey of monte carlo tree search methods. IEEE Transactions on Computational Intelligence and AI in games4(1), 1-43.

Świechowski, M., Godlewski, K., Sawicki, B., & Mańdziuk, J. (2021). Monte Carlo Tree Search: A Review of Recent Modifications and Applications. arXiv preprint arXiv:2103.04931.

Bandit algorithm and various strategies:

https://towardsdatascience.com/bandit-algorithms-34fd7890cb18#b390

UCB:

https://towardsdatascience.com/the-upper-confidence-bound-ucb-bandit-algorithm-c05c2bf4c13f

50 of 50

That’s it for today!