public class DiceUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int[][] |
choose
Result of choose function indexed by n, k.
|
static int |
MAX_DICE
Maximum number of dice modeled
|
static int |
MAX_RANK
Maximum die rank
|
static int |
MIN_RANK
Minimum die rank
|
static int |
NUM_RANKS
Number of die ranks.
|
Constructor and Description |
---|
DiceUtil() |
Modifier and Type | Method and Description |
---|---|
static int |
choose(int n,
int k)
Combinatorial choose function
|
static int |
getNumSortedRolls(int numDice)
Return the number of unique sorted rolls given the number of dice.
|
static void |
intToRankCounts(int rollId,
int numDice,
int[] rankCounts)
Convert an integer roll ID number to the corresponding dice rank counts representation
|
static void |
intToRoll(int i,
int[] roll)
Convert an integer roll ID to the corresponding roll (sorted ascending)
|
static void |
main(java.lang.String[] args)
A test of conversion from roll number to rank counts to roll back to rank counts and back to roll number
to check consistency of conversions for all possible rolls where dice order does not matter.
|
static int |
rankCountsToInt(int[] rankCounts)
Given the rank counts, return the unique integer ID representing that roll from an enumeration of all possible rolls.
|
static int |
rankCountsToInt(int numDice,
int[] rankCounts)
Given the number of dice and the rank counts, return a unique integer roll ID from an enumeration of all possible rolls
|
static void |
rankCountsToRoll(int[] rankCounts,
int[] roll)
Convert a rank count representation of a roll to a sorted roll representation.
|
static int |
rollToInt(int[] roll)
Return roll ID number associated with given ascending sorted roll array.
|
static void |
rollToRankCounts(int[] roll,
int[] rankCounts)
Convert an unsorted roll representation to a rank count representation.
|
public static final int MIN_RANK
public static final int MAX_RANK
public static final int NUM_RANKS
public static final int MAX_DICE
public static final int[][] choose
public static int choose(int n, int k)
n
- number of itemsk
- number of items chosen without replacementpublic static void intToRankCounts(int rollId, int numDice, int[] rankCounts)
rollId
- ID number of dice rollnumDice
- number of dice rolledrankCounts
- mutable "return" parameter where rankCount[i] contains the number of dice rolled of rank i + MIN_RANK. Supplied as a parameter to allow an arbitrary array to be reused for this purpose.public static int rankCountsToInt(int numDice, int[] rankCounts)
numDice
- number of dicerankCounts
- rankCounts[i] gives the number of dice rolled with rank (i + 1)public static int rankCountsToInt(int[] rankCounts)
rankCounts
- rankCounts[i] gives the number of dice rolled with rank (i + 1)public static void rankCountsToRoll(int[] rankCounts, int[] roll)
rankCounts
- input representation of a roll as rank countsroll
- mutable "return" array parameter to contain corresponding sorted rollpublic static void rollToRankCounts(int[] roll, int[] rankCounts)
roll
- input unsorted roll representationrankCounts
- mutable output array to contain the corresponding rank count representationpublic static void intToRoll(int i, int[] roll)
i
- roll IDroll
- mutable "return" parameter where roll contains the ascending sorted roll for the given roll ID. Supplied as a parameter to allow an arbitrary array to be reused for this purpose.public static int rollToInt(int[] roll)
roll
- array containing the ascending sorted roll.public static int getNumSortedRolls(int numDice)
numDice
- the number of dice rolledpublic static void main(java.lang.String[] args)
args
- (unused)