# MCTS how to prevent Selecting a TERMINAL state in TRAVERSAL Phase?

Hello I am currently working on an implementation of MCTS and I ran into the problem that my tree traversal policy selects nodes with terminal game states. Furthermore how do I prevent selecting a Node that only has children Nodes with terminal game states ( and so on and so on )?

What you can do is to add a counter $$t$$ to each node, initially 0, indicating how many of its children are terminal.
When $$t = c$$ where $$c$$ is the number of children of a node, the node itself becomes terminal and increments the $$t$$ counter of its parent. Note that with this definition leaf nodes are automatically terminal, as they have no children, giving $$0 = 0$$.