Last active
November 4, 2020 23:58
-
-
Save carlos-aguayo/681bcbc123c0de0417331521b326b0df to your computer and use it in GitHub Desktop.
Run a Monte Carlo Tree Search (MCTS) Simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/suragnair/alpha-zero-general/blob/5156c7fd1d2f3e5fefe732a4b2e0ffc5b272f819/MCTS.py#L37-L48 | |
for i in range(self.args.numMCTSSims): # self.args.numMCTSSims, the number of MCTS simulations to compute | |
self.search(canonicalBoard) # "search" is a MCTS simulations | |
s = self.game.stringRepresentation(canonicalBoard) | |
# Count how many times we have visited each node | |
counts = [self.Nsa[(s, a)] if (s, a) in self.Nsa else 0 for a in range(self.game.getActionSize())] | |
if temp == 0: | |
# Pick the node that was visited the most | |
bestAs = np.array(np.argwhere(counts == np.max(counts))).flatten() | |
bestA = np.random.choice(bestAs) | |
probs = [0] * len(counts) | |
probs[bestA] = 1 | |
return probs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment