import math


def selection_policy(node, c_uct):
    """ 
    Given a tree node, determine which 
    child to move to when performing MCTS;
    c_uct: constant for UCT algorithm
    """

    if node.is_leaf():
        return node

    max_child = None
    max_val = float('-inf')
    total_visit = 1

    for edge in node.child_edges:
        total_visit += edge.visit_count

    # Determine best child to move to according to UCT
    for edge in node.child_edges:
        if edge.visit_count == 0:
            edge_val = 0
        else:
            edge_val = edge.total_reward / edge.visit_count
        edge_val += c_uct * math.sqrt(2 * math.log(total_visit) / (1 + edge.visit_count))

        if edge_val > max_val:
            max_val = edge_val
            max_child = edge.child

    return max_child