Run deterministic neural-guided MCTS on a supplied two-player tree, starting at root_state. Inputs are Python dictionaries keyed by state names:
The root starts expanded; all edge visit counts and total values start at zero. Priors are softmax probabilities of the supplied logits. Run exactly simulations traversals. Selection maximizes
S(s,a)=Q(s,a)+cpuctP(s,a)1+N(s,a)∑bN(s,b).Here s is a state, a and b are legal actions, S is the score, cpuct is cpuct, P is the prior, N is the visit count, and Q is the mean value from the parent player's perspective, initially zero. Exact ties choose the lowest action.
Each traversal ends at the first terminal or unexpanded state. Use its supplied value, expanding it only if nonterminal. Each traversed edge gains one visit and the leaf value signed for its parent player; its mean is accumulated value divided by visits. At the root and positive temperature,
πa=∑bNb1/τNa1/τ.Here Na is a root visit count, τ is temperature, and πa is the final policy. At zero temperature, assign probability one to the most-visited action, breaking ties by lowest action.
Return a three-item tuple of NumPy arrays in the root's legal-action order: int64 visit counts, float64 mean values, and float64 policy. Each has shape (A,), where A is the root's legal-action count.
Input: root_state="r", transitions={"r": {"0": "a", "1": "b"}}, legal_actions={"r": [0, 1]}, players={"r": 1, "a": -1, "b": -1}, policy_logits={"r": [0, 0]}, value_predictions={"r": 0}, terminal_values={"a": 1, "b": -1}, simulations=3, cpuct=1, temperature=1
Output: ([1, 2], [-1.0, 1.0], [0.333333, 0.666667])
Explanation: The first tie visits action 0, then the backed-up values make action 1 preferable for the remaining simulations.
Input: root_state="r", transitions={"r": {"2": "m", "5": "t5"}, "m": {"0": "t20", "1": "t21"}}, legal_actions={"r": [2, 5], "m": [0, 1]}, players={"r": 1, "m": -1, "t5": -1, "t20": 1, "t21": 1}, policy_logits={"r": [0, 0], "m": [0, 0]}, value_predictions={"r": 0.2, "m": 0.4}, terminal_values={"t5": -0.5, "t20": 1, "t21": -1}, simulations=5, cpuct=4, temperature=2
Output: ([2, 3], [0.3, 0.5], [0.44949, 0.55051])
Input: root_state="r", transitions={"r": {"3": "a", "7": "b"}}, legal_actions={"r": [3, 7]}, players={"r": -1, "a": 1, "b": 1}, policy_logits={"r": [0, 0]}, value_predictions={"r": 0}, terminal_values={"a": 0, "b": 0}, simulations=2, cpuct=1, temperature=0
Output: ([1, 1], [0.0, 0.0], [1.0, 0.0])
np.argmax returns the first maximum in legal-action order.
Comparing the parent and leaf player signs determines the backed-up value.
Logarithms can stabilize visit-count weights at small positive temperatures.
Accepts: string
Accepts: object
Accepts: object
Accepts: object
Accepts: object
Accepts: object
Accepts: object
Accepts: number
Accepts: number
Accepts: number
Run deterministic neural-guided MCTS on a supplied two-player tree, starting at root_state. Inputs are Python dictionaries keyed by state names:
The root starts expanded; all edge visit counts and total values start at zero. Priors are softmax probabilities of the supplied logits. Run exactly simulations traversals. Selection maximizes
S(s,a)=Q(s,a)+cpuctP(s,a)1+N(s,a)∑bN(s,b).Here s is a state, a and b are legal actions, S is the score, cpuct is cpuct, P is the prior, N is the visit count, and Q is the mean value from the parent player's perspective, initially zero. Exact ties choose the lowest action.
Each traversal ends at the first terminal or unexpanded state. Use its supplied value, expanding it only if nonterminal. Each traversed edge gains one visit and the leaf value signed for its parent player; its mean is accumulated value divided by visits. At the root and positive temperature,
πa=∑bNb1/τNa1/τ.Here Na is a root visit count, τ is temperature, and πa is the final policy. At zero temperature, assign probability one to the most-visited action, breaking ties by lowest action.
Return a three-item tuple of NumPy arrays in the root's legal-action order: int64 visit counts, float64 mean values, and float64 policy. Each has shape (A,), where A is the root's legal-action count.
Input: root_state="r", transitions={"r": {"0": "a", "1": "b"}}, legal_actions={"r": [0, 1]}, players={"r": 1, "a": -1, "b": -1}, policy_logits={"r": [0, 0]}, value_predictions={"r": 0}, terminal_values={"a": 1, "b": -1}, simulations=3, cpuct=1, temperature=1
Output: ([1, 2], [-1.0, 1.0], [0.333333, 0.666667])
Explanation: The first tie visits action 0, then the backed-up values make action 1 preferable for the remaining simulations.
Input: root_state="r", transitions={"r": {"2": "m", "5": "t5"}, "m": {"0": "t20", "1": "t21"}}, legal_actions={"r": [2, 5], "m": [0, 1]}, players={"r": 1, "m": -1, "t5": -1, "t20": 1, "t21": 1}, policy_logits={"r": [0, 0], "m": [0, 0]}, value_predictions={"r": 0.2, "m": 0.4}, terminal_values={"t5": -0.5, "t20": 1, "t21": -1}, simulations=5, cpuct=4, temperature=2
Output: ([2, 3], [0.3, 0.5], [0.44949, 0.55051])
Input: root_state="r", transitions={"r": {"3": "a", "7": "b"}}, legal_actions={"r": [3, 7]}, players={"r": -1, "a": 1, "b": 1}, policy_logits={"r": [0, 0]}, value_predictions={"r": 0}, terminal_values={"a": 0, "b": 0}, simulations=2, cpuct=1, temperature=0
Output: ([1, 1], [0.0, 0.0], [1.0, 0.0])
np.argmax returns the first maximum in legal-action order.
Comparing the parent and leaf player signs determines the backed-up value.
Logarithms can stabilize visit-count weights at small positive temperatures.
Accepts: string
Accepts: object
Accepts: object
Accepts: object
Accepts: object
Accepts: object
Accepts: object
Accepts: number
Accepts: number
Accepts: number