Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. def UCT_search(game_state, num_reads,net,temp):
  2. root = UCTNode(game_state, move=None, parent=DummyNode())
  3. for i in range(num_reads):
  4. leaf = root.select_leaf()
  5. encoded_s = ed.encode_board(leaf.game); encoded_s = encoded_s.transpose(2,0,1)
  6. encoded_s = torch.from_numpy(encoded_s).float().cuda()
  7. child_priors, value_estimate = net(encoded_s)
  8. child_priors = child_priors.detach().cpu().numpy().reshape(-1); value_estimate = value_estimate.item()
  9. if leaf.game.check_winner() == True or leaf.game.actions() == []: # if somebody won or draw
  10. leaf.backup(value_estimate); continue
  11. leaf.expand(child_priors) # need to make sure valid moves
  12. leaf.backup(value_estimate)
  13. return root
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement