/// <summary> /// Evaluates this node in the decision tree. /// If the return value is true then move will contain the desired move (if any). /// </summary> /// <param name="state">The current state of the game.</param> /// <param name="move">If this node wants to make a move then it will be placed in this parameter.</param> /// <returns>Returns true if this node is satisfied and false otherwise.</returns> /// <remarks>Although move must be initialized, that does not mean it is not null.</remarks> protected internal override bool Evaluate(GameState <M> state, ref M move) { IEnumerable <Node <M> > chldrn = Children; InnerNode.RemoveAllChildren(); InnerNode.AddChildren(chldrn); return(InnerNode.Evaluate(state, ref move)); }
/// <summary> /// Adds all the nodes given as children of this node. /// </summary> /// <param name="nodes">The nodes to add.</param> /// <returns>The number of nodes actually added.</returns> /// <exception cref="ArgumentException">Thrown if called on a terminal node.</exception> public virtual int AddChildren(IEnumerable <Node <M> > nodes) { if (InnerNode != null) { return(InnerNode.AddChildren(nodes)); } if (Terminal) { throw new ArgumentException("Terminal nodes have no children."); } int ret = 0; foreach (Node <M> n in nodes) { if (AddChild(n)) { ret++; } } return(ret); }