Last active
January 25, 2019 10:29
-
-
Save inoryy/7e96f252e2924ddbcc976b458db9814c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Node* mcts(Node* root) { | |
save(); | |
while (true) { | |
if (TIME >= TIME_LIMIT) break; | |
// select | |
Node* node = root; | |
while (!isTerminal() && node->isExpanded()) { | |
node = node->uctChild(); | |
apply(node->action); | |
} | |
// expand | |
if (!isTerminal() && !node->isExpanded()) { | |
node = node->children[node->explored++]; | |
apply(node->action); | |
node->init(); | |
} | |
// simulate | |
while (!isTerminal()) { | |
auto acts = getActions(); | |
apply(acts[rnd(acts.size())]); | |
} | |
// backprop | |
double score = getScore(); | |
while (node) { | |
node->update(score); | |
node = node->parent; | |
} | |
load(); | |
} | |
return root->bestChild(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment