This commit is contained in:
narawat lamaiin
2024-06-20 16:54:57 +07:00
parent e9268ce500
commit 202981d287
2 changed files with 12 additions and 12 deletions

View File

@@ -244,13 +244,13 @@ julia>
# Signature
"""
function expand(node::MCTSNode,transition::Function, args...; totalsample::Integer=3)
function expand(node::MCTSNode,transition::Function, args::NamedTuple; totalsample::Integer=3)
nthSample = 0
while true
nthSample += 1
if nthSample <= totalsample
newNodeKey, newstate, progressvalue = transition(node.state, args...)
newNodeKey, newstate, progressvalue = transition(node.state, args)
if newNodeKey keys(node.children)
node.children[newNodeKey] =
MCTSNode(newNodeKey, newstate, 0, progressvalue, 0, newstate[:reward],
@@ -287,19 +287,19 @@ julia>
# Signature
"""
function simulate(node::MCTSNode, transition::Function, args...;
maxDepth::Integer=3, totalsample::Integer=3
maxdepth::Integer=3, totalsample::Integer=3
)::Union{Tuple{Number, Dict{Symbol, <:Any}}, Tuple{Number, Nothing}}
simTrajectoryReward = 0.0
terminalstate = nothing
for depth in 1:maxDepth
for depth in 1:maxdepth
simTrajectoryReward += node.reward
if node.isterminal
terminalstate = node.state
break
else
expand(node, transition, args...;
expand(node, transition, args;
totalsample=totalsample)
node = selectChildNode(node)
end