/// <summary> /// Grounds the PDDL term. /// </summary> /// <param name="term">Input data term.</param> /// <param name="substitution">Variables substitution.</param> /// <param name="referenceState">Reference state.</param> /// <returns>Grounded term, i.e. constant name ID.</returns> public int Ground(IExpressionTerm term, ISubstitution substitution, State referenceState) { Debug.Assert(TermStack.Count == 0); TermStack.Clear(); Substitution = substitution; ReferenceState = referenceState; term.Accept(this); Substitution = null; ReferenceState = null; Debug.Assert(TermStack.Count == 1); return(TermStack.Pop()); }
public static int GroundTerm(IExpressionTerm term, ISubstitution substitution, State referenceState) { return(TermGrounder.Ground(term, substitution, referenceState)); }
/// <summary> /// Evaluate the term and save the value and results, and updates the token list to /// reflect the completion of the operation. /// </summary> /// <param name="results">List of term results</param> /// <param name="tokens">String expression to parse</param> /// <param name="dieRoller">Die roller to use</param> /// <param name="opPosition">Current operator position in tokens list</param> /// <param name="length">length of tokens that were affected</param> /// <param name="term">Dice term to evaluate</param> private void EvaluateDiceTerm(List <TermResult> results, List <string> tokens, IDieRoller dieRoller, int opPosition, int length, IExpressionTerm term) { IReadOnlyList <TermResult> t = term.CalculateResults(dieRoller); int value = t.Sum(r => (int)Math.Round(r.AppliesToResultCalculation ? r.Value * r.Scalar : 0)); results.AddRange(t); // put the evaluation result in the first entry and remove // the remaining processed tokens tokens[opPosition - 1] = value.ToString(); tokens.RemoveRange(opPosition, length); }