This commit is contained in:
narawat lamaiin
2025-03-02 17:10:01 +07:00
parent 84d73e742c
commit 6920be2334
3 changed files with 17 additions and 7 deletions

View File

@@ -52,7 +52,8 @@ function runMCTS(
earlystop::Union{Function,Nothing}=nothing
)::NamedTuple{(:bestNextState, :bestFinalState),Tuple{T,T}} where {T<:Any}
root = MCTSNode("root", initialstate, 0, 0, 0, 0, false, nothing, Dict{String,MCTSNode}())
root = MCTSNode("root", initialstate, 0, 0, 0, 0, false, nothing, Dict{String,MCTSNode}(),
Dict{Symbol,Any}())
for nth in 1:maxiterations
node = root
@@ -67,7 +68,7 @@ function runMCTS(
# do nothing then go directly to backpropagation. It means the end of this iteration
backpropagate(node, node.reward)
else
expand(node, transition, transitionargs;
_ = expand(node, transition, transitionargs;
totalsample=totalsample)
leafNode = selectChildNode(node)
simTrajectoryReward, terminalstate = simulate(leafNode, transition, transitionargs;
@@ -82,6 +83,9 @@ function runMCTS(
# end
backpropagate(leafNode, simTrajectoryReward)
# delete all child node, no need for child node that was created during simulation
leafNode.children = Dict{String,MCTSNode}()
end
# stop if the early stop condition is met