Skip to content

Instantly share code, notes, and snippets.

@doom369
Created January 21, 2018 07:53
Show Gist options
  • Save doom369/cf2255c53360b5083b9872d6de059311 to your computer and use it in GitHub Desktop.
Save doom369/cf2255c53360b5083b9872d6de059311 to your computer and use it in GitHub Desktop.
точка
public static void main(String[] args) {
double average = 0;
int count = 0;
for (int i = 0; i < 1_000_000; i++) {
average += enhance(10, 15, Scroll.REGULAR);
count++;
}
System.out.println("Average : " + average / count);
average = 0;
count = 0;
for (int i = 0; i < 1_000_000; i++) {
average += enhance(10, 15, Scroll.BLESSED);
count++;
}
System.out.println("Average for blessed : " + average / count);
}
private static int enhance(int from, int to, Scroll scroll) {
int attempts = 0;
int currentLevel = from;
while (currentLevel < to) {
currentLevel += tryWith(currentLevel, scroll);
attempts++;
}
return attempts;
}
static int tryWith(int currentLevel, Scroll scroll) {
double random = ThreadLocalRandom.current().nextDouble();
//45% chance of success
if (currentLevel == 10) {
return random >= 0.45 ? 0 : scroll.levelUp();
}
//45% chance of success
if (currentLevel == 11 || currentLevel == 12) {
return random >= 0.45 ? -1 : scroll.levelUp();
}
//40% chance of success
if (currentLevel == 13 || currentLevel == 14) {
return random >= 0.40 ? -1 : scroll.levelUp();
}
throw new RuntimeException("not supported");
}
private enum Scroll {
REGULAR,
BLESSED;
public int levelUp() {
switch (this) {
case BLESSED:
return ThreadLocalRandom.current().nextInt(1, 4);
default:
return 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment