This is my homework and I have been working on it for a long time. Honestly, I myself do not understand why 1d20 is 10.5 (in the examples below) and I hope to get them from you.
I myself tried to do calculations using a DataTable, but I just don't understand how to calculate an example of the mDn type.
I'm trying to implement a standard calculator with special D&D
operation.
A string is a valid mathematical expression consisting of unary (+ -)
and binary (+ - * /)
operators, brackets and operands - numbers and random variables. Numbers can be written both in integer form (2) and as a decimal fraction (1.5). Any number should be considered as a fractional (double), i.e. the expression 3/2 should result in 1.5, not 1.
Random values will be written in standard D&D notation: XdY
(for example: 1d20, 2d6, 1d3
), where X
and Y
are positive integers. XdY
actually means
Take X Y-sided dice, roll them, and take the sum.
Examples:
2+2*2 == 6
1d20 == 10.5
2d6+(-1d12/5) == 5.7