< Dice‎ | AST‎ | DiceAST
Revision as of 21:45, 14 August 2017 by Skizzerz (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

DiceAST.Reroll Method (RollData, DiceAST, Int32)

From DiceRoller Documentation

Re-do the roll without re-evaluating the entire subtree again.

  • Namespace: Dice.AST
  • Assembly: DiceRoller (in DiceRoller.dll)

Syntax

protected internal long Reroll(
    RollData data,
    DiceAST root,
    int depth
)

Parameters

data
Type: Dice.RollData
Configuration of the roller and roll-specific data.
root
Type: Dice.AST.DiceAST
Root of the AST.
depth
Type: System.Int32
Current recursion depth.

Return Value

Type: System.Int64

Total number of rolls taken to reroll this subtree.

Remarks

This method is responsible for re-rolling and AST without re-evaluating every node, and tracks things like recursion depth and total number of rolls (throwing DiceException if they get too high). It calls RerollInternal to actually perform the evaluation logic (as this method is not virtual). If Evaluated is false, this will call Evaluate instead.

Rerolls should re-perform the main evaluation logic without doing extra work. For example, in the dice expression (1d6)d4, first 1d6 is evaluated and then that many d4s are rolled. When rerolling that expression, the 1d6 is not re-evaluated; instead the prior value is kept and that many d4s are re-rolled.

When a subclass is inside of RerollInternal, it should call Reroll on any child nodes it has before executing its own logic. These calls should typically increase the depth by 1.

See Also

The Evaluate method has an example of a subclass of DiceAST implementing RerollInternal.