mcts.py

mcts.py contains our implementation of Monte Carlo tree search. Our first class is RootNode, which is meant to represent the root node of the MCTS tree at the start of a simulation. By definition, the root node does not have a parent. Having a separate class for the root node is not absolutely necessary, but it does keep the code cleaner:

import collectionsimport mathimport numpy as npimport utilsfrom config import MCTSPARAMETERS, GOPARAMETERSclass RootNode(object):    def __init__(self):        self.parent_node = None        self.child_visit_counts = collections.defaultdict(float)        self.child_cumulative_rewards = collections.defaultdict(float)

Next, we implement the MCTreeSearchNode class. This class has several attributes, the most important ones ...

Get Python Reinforcement Learning Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.