Created
February 4, 2019 14:33
-
-
Save mohsenheydari/55a65083fec995ad21978fbe30a5e367 to your computer and use it in GitHub Desktop.
MCTS - function to find best next action for current state and player
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
findNextAction(board, player, iterations) { | |
let root = new Node(); | |
root.state = new NodeState(); | |
root.state.board = board; | |
root.state.player = 3 - player;//Opponent player is owner of root node | |
for (let i=0; i < iterations; i++) { | |
//1.Selection | |
let node = this.selectPromisingChild(root); | |
//2.Expansion | |
if(!node.state.isTerminal && !node.isFullyExpanded) { | |
//Single node expansion | |
node = node.expand(); | |
} | |
//3.Simulation | |
let result = this.simulate(node); | |
//4.Update | |
this.backpropagate(node, result); | |
} | |
let winnerNode = root.childWithMostVisits; | |
return winnerNode.state.action; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment