< Dice‎ | AST‎ | DiceAST
Revision as of 23:06, 15 May 2017 by Skizzerz (talk | contribs) (Created page with "{{APIdoc|DiceAST.Reroll Method (RollerConfig, DiceAST, Int32)}} Re-do the roll without re-evaluating the entire subtree again. {{ns}} == Syntax == <syntaxhighlight lang="C#"...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

DiceAST.Reroll Method (RollerConfig, 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(
    RollerConfig conf,
    DiceAST root,
    int depth
)

Parameters

conf
Type: Dice.RollerConfig
Configuration of the roller.
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.