using HeuristicLab.Algorithms.Bandits; using System.Collections.Generic; using System.Linq; namespace HeuristicLab.Algorithms.MonteCarloTreeSearch.Base { public class TreeNode { public string phrase; public TreeNode parent; public TreeNode[] children; public IBanditPolicyActionInfo actionInfo; public ushort level; public TreeNode(TreeNode parent, string phrase, IBanditPolicyActionInfo actionInfo, ushort level) { this.parent = parent; this.phrase = phrase; this.actionInfo = actionInfo; this.level = level; } public bool IsLeaf() { return children == null || !children.Any(); } internal IEnumerable GetChildActionInfos() { return children.Select(n => n.actionInfo); } internal void RemoveChildren(TreeNode currentNode) { TreeNode[] newChildren = new TreeNode[children.Length-1]; int counter = 0; for (int i = 0; i < children.Length; i++) { if (children[i] != currentNode) { newChildren[counter] = children[i]; counter++; } } children = newChildren; } } }