Skip to content

Instantly share code, notes, and snippets.

@mohsenheydari
Created February 4, 2019 15:09
Show Gist options
  • Save mohsenheydari/d19bfa2597674f317b54f96e16db2aa7 to your computer and use it in GitHub Desktop.
Save mohsenheydari/d19bfa2597674f317b54f96e16db2aa7 to your computer and use it in GitHub Desktop.
MCTS - simulate method of TreeSearch class
simulate(node) {
let state = node.state.clone(); //Temp state
state.board = node.state.board.clone();
//Play randomly until one player wins or game result in draw
while (!state.isTerminal) {
state.switchToNextPlayer();
let action = state.getRandomAction(state.player);
state.applyAction(action);
}
return state.board.status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment