Created
May 14, 2015 23:33
-
-
Save aadnk/4e2064d17f54970c1d4c to your computer and use it in GitHub Desktop.
Amaz Boombot Simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.comphenix.testing; | |
import java.util.Random; | |
public class Test { | |
private static final int SIMULATION_COUNT = 1_000_000_000; | |
public static void main(String[] args) throws Exception { | |
Random rnd = new Random(); | |
int amazWin = 0; | |
for (int i = 0; i < SIMULATION_COUNT; i++) { | |
double opponentHealth = 4; | |
// See if we hit the opponent | |
opponentHealth -= getBoomFaceDamage(rnd, 3); | |
// Nishino's boom bot - does it kill Amaz' other boom bot? | |
if (rnd.nextInt(6) == 0) { | |
opponentHealth -= getBoomFaceDamage(rnd, 3); | |
} | |
if (opponentHealth <= 0) { | |
amazWin++; | |
} | |
} | |
double winProbability = amazWin / (double)SIMULATION_COUNT; | |
System.out.println("Wins: " + amazWin); | |
System.out.println("Losses: " + (SIMULATION_COUNT - amazWin)); | |
System.out.println("Win probability: " + (winProbability * 100) + "%"); | |
} | |
private static int getBoomFaceDamage(Random rnd, int enemyCount) { | |
if (rnd.nextInt(enemyCount) == 0) { | |
return 1 + rnd.nextInt(4); | |
} | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment