fponticelli / diceroller Goto Github PK
View Code? Open in Web Editor NEWDice parsing and rolling
Home Page: https://dice.run
Dice parsing and rolling
Home Page: https://dice.run
add function that validates against rerolling all combos, or exploding all combos or above/below boundaries
My friends and I are developing a game system that involves both exploding dice, and keeping a certain number of the result. There's not really anything I've found that's capable of doing both at once, and it would be nice to calculate the probabilities of certain rolls with both things in place. For instance, based on the syntax you use, a standard accuracy check from my character would currently be: 11d10e10k6. In that it rolls 11d10, explodes 10s, and keeps the 6 highest among the total result, after exploding.
The functionality could also be installed to work on the keep highest after the exploding; these would result in two possibilities. If the exploding occurs before the keeping of highest/lowest total, then if you explode and get a bunch of max dice, you'd still only keep the number specified. However, if the syntax is swapped and the keep highest/lowest happens before the explode, then exploded dice are not counted among the total dice kept and are added in addition to the original kept highest/lowest. So, 2d6e6k2, would roll 1d6, and if it lands on two 6es, it would explode and roll 2 additional dice, which get a 2 and a 4; but then still only keep the 2 highest, so the original two 6s, resulting in a roll of 12. Whereas 2d6k2e6, in the same scenario, would keep the original two 6es, but then they would explode, and the additional 2 and 4 that are rolled are added to the total for a total of 18.
For rolling D&D stats I used the following dice expression. I would appreciate it if there was a better way of doing multiples of expressions.
(4d6 drop 1, 4d6 drop 1, 4d6 drop 1, 4d6 drop 1, 4d6 drop 1, 4d6 drop 1)
PLUS = "+";
MINUS = "-";
ZERO = "0";
UNSIGNED_DIGIT = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
DIGIT = ZERO | UNSIGNED_DIGIT;
UNSIGNED_NUMBER = UNSIGNED_DIGIT, { DIGIT };
POSITIVE = [ PLUS ], UNSIGNED_NUMBER;
NEGATIVE = MINUS, UNSIGNED_NUMBER;
WHOLE = NEGATIVE | ZERO | POSITIVE | (PLUS, ZERO) | (MINUS, ZERO);
D = "d" | "D";
OPEN_SET_BRACKET = "{";
OPEN_PAREN = "(";
CLOSE_SET_BRACKET = "}";
CLOSE_PAREN = ")";
COMMA = ",";
WS = " " | "\n" | "\r" | "\t";
MULTIPLICATION = "*" | "โ
" | "ร" | "x";
DIVISION = "/" | "รท" | ":";
KEEP_OR_DROP = "keep" | "drop";
LOW_HIGH = ("low" | "lowest") | ("high" | "highest");
MORE_LESS = "more" | "less";
OR_MORE_LESS = "or", { WS }, MORE_LESS;
TIMES = "once" | "twice" | "thrice" | (POSITIVE, { WS }, "times");
POSITIVE_SEQUENCE = OPEN_PAREN, { WS }, POSITIVE, { WS }, {COMMA, { WS }, POSITIVE, { WS } }, CLOSE_PAREN;
MATCH =
POSITIVE, [ OR_MORE_LESS ] |
(POSITIVE, { WS }, "...", { WS }, POSITIVE) |
POSITIVE_SEQUENCE;
MAP_KEY_VALUE_PAIR = MATCH, { WS }, ":", { WS }, NUMBER;
MAP_SEQUENCE = OPEN_PAREN, { WS }, MAP_KEY_VALUE_PAIR, { WS }, {COMMA, { WS }, MAP_KEY_VALUE_PAIR, { WS } }, CLOSE_PAREN;
(* final tokens *)
LITERAL = POSITIVE; (* number 2 *)
DIE = D, POSITIVE; (* d6 for one die with 6 sides *)
DICE = POSITIVE, D, POSITIVE; (* 3d6 for the sum of 3 dice with six sides *)
BASIC_ROLL = LITERAL | DIE | DICE;
SET_ELEMENT = { WS }, DIE, { WS };
(* Dice Set. Comma separated list of dice. Can only contain Basic Rolls. *)
SET = OPEN_SET_BRACKET, [ SET_ELEMENT, { COMMA, SET_ELEMENT } ], CLOSE_SET_BRACKET;
DICE_SET = DICE | SET_ELEMENT | DICE_SET_EXPR_OP;
ESET_ELEMENT = { WS }, EXPRESSION, { WS };
(* Expression Set. Can contain any kind of expression. *)
ESET = OPEN_SET_BRACKET, [ ESET_ELEMENT, { COMMA, SET_ELEMENT } ], CLOSE_SET_BRACKET;
ANY_SET = SET | ESET | ANY_SET_EACH;
ANY_SET_SUM = ANY_SET, { WS }, "sum";
ANY_SET_AVERAGE = ANY_SET, { WS }, "avg" | "average";
ANY_SET_KEEP_OR_DROP = ANY_SET, { WS }, KEEP_OR_DROP, { WS }, (
([LOW_HIGH], { WS }, WHOLE) |
LOW_HIGH
);
ANY_SET_COUNT = ANY_SET, { WS }, "count", { WS }, WHOLE, [{ WS }, OR_MORE_LESS];
ANY_SET_COUNT_EACH = ANY_SET, { WS }, "count", { WS }, "each", { WS }, "on", { WS }, MATCH;
ANY_SET_MAP = ANY_SET, { WS }, "map", { WS }, (POSITIVE_SEQUENCE | MAP_SEQUENCE);
ANY_SET_EACH = ANY_SET_COUNT_EACH | ANY_SET_MAP; (* lazy *)
ANY_SET_OP = ANY_SET_SUM | ANY_SET_AVERAGE | ANY_SET_KEEP_OR_DROP | ANY_SET_COUNT;
DICE_SET_EXPLODE = DICE_SET, { WS }, "explode", { WS }, [ TIMES ], { WS }, "on", { WS }, MATCH;
DICE_SET_REROLL = DICE_SET, { WS }, "reroll", { WS }, "times", { WS }, "on", { WS };
DICE_SET_EXPR_OP = DICE_SET_EXPLODE | DICE_SET_REROLL; (* lazy *)
SUM = EXPRESSION, { WS }, PLUS, { WS }, EXPRESSION;
SUBTRACT = EXPRESSION, { WS }, MINUS, { WS }, EXPRESSION;
DIVIDE = EXPRESSION, { WS }, DIVISION, { WS }, EXPRESSION; (* integer division *)
MULTIPLY = EXPRESSION, { WS }, MULTIPLICATION, { WS }, EXPRESSION;
NEGATE = MINUS, EXPRESSION;
OPERATIONS = SUM | SUBTRACT | DIVIDE | MULTIPLY | NEGATE;
EXPRESSION = BASIC_ROLL | ANY_SET | ANY_SET_OP | OPERATIONS; (* lazy *)
GRAMMAR = { WS }, EXPRESSION, { WS };
times
range
times
range
or more
/or less
on
drop
/keep
explode
/reroll
In certain games (World of Darkness/Exalted is notable) what's important is counting how many dice meet a certain criterion. For example, in Exalted, you roll a large number of d10s, but you count each die as having the faces 0,0,0,0,0,0,1,1,1,2 (Count up how many are 7+, 10's count double). The option to count the results on each die would be really handy -- or at least to be able to set the faces on each die.
doesn't work as expected
always should be implied
Systems such as L5R 4e use the Roll and Keep system but with exploding dice for very dynamic rolls and notoriously deadly attacks.
Would be nice to be able to roll with explodes and keep the highest dice but this doesn't seem to be supported.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.