Class: MCTS::Root
Instance Attribute Summary
Attributes inherited from Node
#children, #game_state, #move, #parent, #visits, #wins
Instance Method Summary
collapse
Methods inherited from Node
#backpropagate, #expand, #leaf?, #lost, #rollout, #uct_select_child, #uct_value, #untried_moves?, #win_percentage, #won
Constructor Details
#initialize(game_state) ⇒ Root
Returns a new instance of Root.
3
4
5
|
# File 'lib/mcts/root.rb', line 3
def initialize(game_state)
super game_state, nil, nil
end
|
Instance Method Details
#best_child ⇒ Object
11
12
13
|
# File 'lib/mcts/root.rb', line 11
def best_child
children.max_by &:win_percentage
end
|
#best_move ⇒ Object
15
16
17
|
# File 'lib/mcts/root.rb', line 15
def best_move
best_child.move
end
|
#explore_tree ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/mcts/root.rb', line 19
def explore_tree
selected_node = select
playout_node = if selected_node.leaf?
selected_node
else
selected_node.expand
end
won = playout_node.rollout
playout_node.backpropagate(won)
end
|
#root? ⇒ Boolean
7
8
9
|
# File 'lib/mcts/root.rb', line 7
def root?
true
end
|
#update_won(won) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/mcts/root.rb', line 30
def update_won(won)
if won
self.lost
else
self.won
end
end
|