public class Roller {
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int t=0;t<20;t++) {
dice.initRoll();
do {
dice.roll();
} while (dice.eos<100100 && dice.eos>0);
System.out.println ("num Rolls"+dice.numRolls);
System.out.println ("eos "+dice.eos);
}
}
import java.util.Random;
public class dice {
public static int roll,numRolls,losses [],totalRounds,lossStage;
public static float eos,currentBet,betValue[];
public static Random randomizer;
public static boolean started=false;
public static void initRoll () {
if (!started) randomizer = new Random(System.currentTimeMillis());
started=true;
eos=100000;
losses = new int [10000];
betValue = new float [1000];
betValue [0]=1.0f;
for (int p=1;p<1000;p++) betValue[p] = betValue[p-1]*1.2f;
totalRounds=0;
numRolls=0;
currentBet=1.0f;
lossStage=0;
}
public static void roll () {
roll = getRandomInt (1,100);
eos=eos-currentBet;
numRolls++;
if (roll < 50) {
eos=eos+currentBet*1.9f;
losses[lossStage]--;
if (losses[lossStage]<=0) {
losses[lossStage]=0;
if (losses[lossStage+1]==0)
retraceLossStage(); else lossStage++;
if (lossStage<0) lossStage=0;
currentBet=betValue[lossStage];
}
} else {
losses [lossStage+1]++;
}
}
public static int getRandomInt(int min,int max)
{
return randomizer.nextInt(max-min+1)+min;
}
public static void retraceLossStage () {
do {
lossStage--;
if (lossStage<0) lossStage=0;
if (lossStage==0) break;
} while (losses[lossStage]==0);
}
}
Category Archives: unlisted
Dice Roller Program
Posted in unlisted