Last active
April 5, 2018 00:08
-
-
Save rmcdouga/0cc4e340bdb477dd0d64f06140c9ef7b to your computer and use it in GitHub Desktop.
Combat Results Test
This file contains hidden or 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.github.rmcdouga.cow.combat_simulator; | |
import java.util.Random; | |
import java.util.StringJoiner; | |
import com.github.rmcdouga.cow.CombatResultsTable; | |
import com.github.rmcdouga.cow.units.UnitType; | |
import com.github.rmcdouga.cow.units.UnitTypes; | |
public class BrianTest { | |
final static UnitType unit1 = UnitTypes.Dragon; | |
final static UnitType unit2 = UnitTypes.Destroyer; | |
final static int NUM_SAMPLES = 1000000; | |
public static void main(String[] args) { | |
Random random = new Random(); | |
int numHits[] = new int[unit1.getPower() + 1]; | |
System.out.println(unit1.getMnemonic() + " vs " + unit2.getMnemonic() + ", target #=" + 59); | |
for (int i = 0; i < NUM_SAMPLES; i++) { | |
int results = performRoundOfAttacks(unit1.getPower(), 100 - 59, random); | |
numHits[results] += 1; | |
} | |
StringJoiner sj = new StringJoiner(","); | |
for (int i = 0; i < unit1.getPower() + 1; i++) { | |
sj.add(String.format("%d=%2.2f%%", i, ((numHits[i] * 100.0) / NUM_SAMPLES))); | |
} | |
System.out.println(sj.toString()); | |
} | |
private static int performRoundOfAttacks(int numAttacks, int targetNum, Random local_random) { | |
int numHits = 0; | |
for(int i = 0; i < numAttacks; i++) { | |
if (determineHit(targetNum, local_random)) { | |
numHits++; | |
} | |
} | |
return(numHits); | |
} | |
private static boolean determineHit(int targetNum, Random local_random) { | |
int randomNum = local_random.nextInt(100) + 1; | |
// System.out.println("ATTACK RESOLUTION targetNum=" + targetNum + ", randomNum=" + randomNum + "."); | |
return (randomNum >= targetNum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment