mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
Former-commit-id: 890f8a703f9f9f5a6b6a7c26b2f5d9928d63cf40 Former-commit-id: 9b9d5afd32871cc791d525ff2aafe693205d8c54
59 lines
1.3 KiB
Java
59 lines
1.3 KiB
Java
package com.Torvald.Rand;
|
||
|
||
import java.util.Random;
|
||
|
||
/**
|
||
* Created by minjaesong on 16-02-03.
|
||
*/
|
||
public class FudgeDice {
|
||
|
||
private Random randfunc;
|
||
private int diceCounts;
|
||
|
||
/**
|
||
* Define new set of fudge dice with given counts.
|
||
* @param randfunc java.util.Random or its extension
|
||
* @param counts amount of die
|
||
*/
|
||
public FudgeDice(Random randfunc, int counts) {
|
||
this.randfunc = randfunc;
|
||
diceCounts = counts;
|
||
}
|
||
|
||
/**
|
||
* Roll dice and get result.
|
||
* @return Normal distributed integer [-N , N] for diceCount of N. 0 is the most frequent return.
|
||
*/
|
||
public int roll() {
|
||
int diceResult = 0;
|
||
for (int c = 0; c < diceCounts; c++) {
|
||
diceResult += rollSingleDie();
|
||
}
|
||
|
||
return diceResult;
|
||
}
|
||
|
||
/**
|
||
* Roll dice and get result, for array index
|
||
* @return Normal distributed integer [0 , N] for N = 2 × DiceCounts + 1. 0 is the most frequent return.
|
||
*/
|
||
public int rollForArray() {
|
||
return roll() + diceCounts;
|
||
}
|
||
|
||
public int getDiceCounts() {
|
||
return diceCounts;
|
||
}
|
||
|
||
public int getSizeOfProbabilityRange() {
|
||
return 2 * diceCounts + 1;
|
||
}
|
||
|
||
/**
|
||
* @return integer randomly picked from {-1, 0, 1}
|
||
*/
|
||
private int rollSingleDie() {
|
||
return (randfunc.nextInt(3)) - 1;
|
||
}
|
||
}
|