/// <summary> /// Propagate an evaluation value of the argument state starting from the argument node back up to the root node. /// </summary> /// <param name="context">The context of the search.</param> /// <param name="evaluation">The strategy used to evaluate the state.</param> /// <param name="node">The node from which the backpropagation starts.</param> /// <param name="state">The state that should be evaluated.</param> public void BackPropagate(SearchContext <D, P, A, S, Sol> context, IStateEvaluation <D, P, A, S, Sol, TreeSearchNode <P, A> > evaluation, TreeSearchNode <P, A> node, P state) { do { // Evaluate state with respect to the node. var value = evaluation.Evaluate(context, node, state); // Visit the node with that evaluation. node.Visit(value); // Keep moving up the tree while there is a valid parent. } while ((node = node.Parent) != null); }
/// <summary> /// Propagate an evaluation value of the argument state starting from the argument node back up to the root node. /// </summary> /// <param name="context">The context of the search.</param> /// <param name="evaluation">The strategy used to evaluate the state.</param> /// <param name="node">The node from which the backpropagation starts.</param> /// <param name="state">The state that should be evaluated.</param> public void BackPropagate(SearchContext <D, P, A, S, Sol> context, IStateEvaluation <D, P, A, S, Sol, TreeSearchNode <P, A> > evaluation, TreeSearchNode <P, A> node, P state) { // Evaluate the state with respect to the argument node. var value = evaluation.Evaluate(context, node, state); // The root player is the current player in the search's source state. var rootPlayer = context.Source.CurrentPlayer(); do { // Check whether or not this node is a root player's node. var targetPlayer = node.IsRoot() || rootPlayer == node.Payload.Player(); // Visits the node with a coloured evaluation value. node.Visit(targetPlayer ? value : -value); // Keep moving up the tree while there is a valid parent. } while ((node = node.Parent) != null); }