Skip to content

Instantly share code, notes, and snippets.

@mohsenheydari
Created February 4, 2019 15:22
Show Gist options
  • Save mohsenheydari/852431848b4c32631c15ca1e54a4d693 to your computer and use it in GitHub Desktop.
Save mohsenheydari/852431848b4c32631c15ca1e54a4d693 to your computer and use it in GitHub Desktop.
MCTS - backpropagate method of TreeSearch class
backpropagate(node, result) {
let tmpNode = node;
while(tmpNode !== null) {
tmpNode.state.visits++;
if (result != tmpNode.state.board.DRAW) {
if (tmpNode.state.player === result) {
tmpNode.state.wins++;
}
else {
tmpNode.state.wins--;
}
}
tmpNode = tmpNode.parent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment