The internal plugin DiceArithmeticPlugin allows you to specify complex dice arithmetic expressions and comparisons.
You can plus a Number to a dice rolling command and vice-versa:
5.d10 + 50 50 + 5.d10
Both scripts shown above does the same thing: rolls five ten-sided dice and appends 50 to the results. Let's say that five ten-sided dice returned [1,10,3,5,9]. Then, the result of those expressions will be [1,10,3,5,9,50].
You can also plus two dice rolling commands:
2.d6 + 2.d10
This script rolls two six-sided dice and two ten-sided dice, joining the results of both rolls. Let's say that two six-sided dice returned [5,3] and the two ten-sided dice returned [7,9]. Then, the result will be [5,3,7,9].
All these scripts returns dice rolling commands.
This operator works similarly to the + operator. For example:
5.d10 - 50 -50 + 5.d10
Both scripts shown above does the same thing: rolls five ten-sided dice and appends -50 to the results. Let's say that ten-sided dice returned [1,10,3,5,9]. Then, the result of those expressions will be [1,10,3,5,9,-50]
You can use two dice rolling commands as operands as well:
2.d6 - 2.d10
This script rolls two six-sided dice and two ten-sided dice, joining the results of both rolls, but multiplying all dice of second roll by -1. Let's say that two six-sided dice returned [5,3] and two ten-sided dice returned [7,9]. Then, the result will be [5,3,-7,-9].
All these scripts returns dice rolling commands.
You can multiply a dice rolling command by a Number and vice-versa:
5.d12 * 50 50 * 5.d12
Both scripts shown above does the same thing: rolls five twelve-sided dice, sums them, and multiplies the sum by 50. Let's say that the sum of five twelve-sided dice is 49. Then, the result will be 2450, or 49*50.
You can also multiply two dice rolling commands:
5.d6 * 2.d10
This script multiplies the sum of five six-sided dice by the sum of two ten-sided dice. Let's say that the sum of five six-sided dice is 23 and the sum of two ten-sided dice is 7. Then, the result will be 161, or 23*7.
All these scripts returns Numbers.
You can to perform an exponentiation using a dice rolling command as base and a Number as exponent:
5.d12 ** 2
This script rolls five twelve-sided dice and returns the square of the sum. Let's say that the sum of five twelve-sided dice is 45. Then, the result will be 2025, or 45^2.
If you want, you can also use a Number as base and a dice rolling command as exponent:
10 ** 2.d4
This script raises 10 to the power equals to the sum of two four-sided dice. Let's say that the sum of two four-sided dice is 6. Then, the result will be 1000000, or 10^6.
It's possible to use a dice rolling command in both base and exponent:
5.d10 ** 2.d4
This script raises the sum of five ten-sided dice to the power equals to the sum of two four-sided dice. Let's say that the sum of five ten-sided dice is 25 and the sum of two four-sided dice is 6. Then, the result will be 244140625, or 25^6.
All these scripts returns Numbers.
You can to divide a dice rolling command by a Number:
5.d12 / 2
This script rolls five twelve-sided dice, sums them, and then divides the sum by 2. Let's say that the sum of five twelve-sided dice is 30. Then, the result will be 15, or 30/2.
You can also divide a Number by a dice rolling command:
10 / 2.d4
This script divides 10 by the sum of two four-sided dice. Let's say that that sum of two four-sided dice is 4. Then, the result will be 2.5, or 10/4.
It's possible to divide a dice rolling command by another:
5.d10 / 2.d4
This script divides the sum of five ten-sided dice by the sum of two four-sided dice. Let's say that the sum of five ten-sided dice is 40 and the sum of two four-sided dice is 8. Then, the result will be 5, or 40/8.
All these scripts returns Numbers.
You can get the reminder of the division of a dice rolling command by a Number:
5.d12 % 2
This script rolls five twelve-sided dice, sums them, and then get the reminder of the division of the sum by 2. Let's say that the sum of five twelve-sided dice is 43. Then, the result will be 1, or 43%2.
You can also get the reminder of the division of a Number by a dice rolling command:
10 % 2.d4
This script gets the reminder of the division of 10 by the sum of two four-sided dice. Let's say that the sum of two four-sided dice is 6. Then, the result will be 4, or 10%6.
It's also possible to get the reminder of the division of a dice rolling command by another:
5.d10 % 2.d4
This script gets the reminder of the division of the sum of five ten-sided dice by the sum of two four-sided dice. Let's say that the sum of five ten-sided dice is 38 and the sum of two four-sided dice is 5. Then, the result will be 3, or 38%5.
All these scripts returns Numbers.
Groovy Dice allows you to evaluate boolean expressions using dice rolling commands. Here goes a simple example where we test whether the sum of seven ten-sided dice is greater than the sum of five twelve-sided dice:
7.d10 > 5.d12
Other boolean operators are also available for use:
7.d10 >= 5.d12 7.d10 == 5.d12 7.d10 != 5.d12 7.d10 <= 5.d12 7.d10 < 5.d12
You can also compare dice rolling commands with Numbers, but the inverse is not true. To illustrate this, both scripts below tests whether the sum of ten six-sided dice is greater or equals to 45:
10.d6 >= 45 // valid 10.d6.sum >= 45 // valid 45 < 10.d6 // not valid! 45 < 10.d6.sum // valid
But, what if you want to check whether two dice contains the same results regardless its order? In this case, you can use the same_as() method to compare every die of both rolls and get a boolean that indicates whether these rolls contains the same results:
7.d10.same_as(7.d12)
It's possible to check against other objects, like Numbers, Arrays or Ranges:
1.d6.same_as(2) 7.d10.same_as([1,5,1,7,6,4,2]) 4.d12.same_as(1..4)