Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MonteCarloHitDice {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int[] hpTotal = new int[14];
- int[] avgHpTotal = new int[14];
- for (int h=0; h<14; h++){
- hpTotal[h] = 0;
- avgHpTotal[h] = 0;
- }
- for (int i=0; i<1000; i++){
- //clean out the hpTotal array
- for (int ii=0; ii<14; ii++){
- hpTotal[ii] = 0;
- }
- //roll hp for first level
- hpTotal[0] = (int) ((Math.random()*8)+1);
- //fill out the hp table for levels 1 through 14
- for (int j=1; j<14; j++){
- int tempTotal = 0;
- //are we at maximum hit dice?
- if (j<9){
- //roll jd6 and store it
- for (int k=0; k<j; k++){
- tempTotal += (int) ((Math.random()*8)+1);
- }
- }
- else{//okay, we're at maximum hit dice
- for (int k=0; k<9; k++){
- tempTotal += (int) ((Math.random()*8)+1);
- }
- tempTotal += 3*(j-8);
- }
- //is what we rolled bigger than the last level?
- if (tempTotal > hpTotal[j-1]){
- hpTotal[j] = tempTotal;
- }
- else{
- hpTotal[j] = hpTotal[j-1]+1;
- }
- }
- //add the hp values to the avHpTotal
- for (int l=0; l<14; l++){
- avgHpTotal[l] += hpTotal[l];
- }
- }
- for (int m=0; m<14; m++){
- avgHpTotal[m] = avgHpTotal[m]/1000;
- }
- for (int n=0; n<14; n++){
- System.out.println(avgHpTotal[n]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement