defTreeSearch(State):
globalParameters= ... # Dictionary accessible from all functionsFrontier= ... # LIFO / FIFO / Priority QueueRoot=Node(State)
whilenotShouldTerminate(Root):
# Choose node for expansion using either tree traversal or the frontierNode=Select(Root, Frontier)
# Generate new state with applicable action# If Node is fully expanded, Leaf = NodeLeaf=Expand(Node)
# Some agents (e.g. MiniMax) do not need to evaluate all statesifShouldEvaluate(Leaf):
Value=Evaluate(Leaf.State)
# Backprop w/o evaluation is useful for proactive pruningifShouldBackPropagate(Leaf, Value):
Backpropagate(Leaf, Value)
# For removing nodes from the tree, i.e. retroactive pruningifShouldTrim(Root):
Trim(Root, Frontier)
# Decide best move based on root and its children, or values# stored in ParametersreturnGetBestMove(Root)
Example usage
Instantiating a MiniMax agent and searching a state