Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dnd5e;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Random;
- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- import lombok.Value;
- public final class CreateDist {
- private static void addToPool(Map<StatPool, Integer> pool, StatPool newVal) {
- if(pool.containsKey(newVal)) {
- Integer val = pool.get(newVal);
- pool.put(newVal, val + 1);
- } else {
- pool.put(newVal, 1);
- }
- }
- private static boolean poolFilled(Map<StatPool, Integer> pool) {
- Integer checkVal = pool.values().stream().sorted((a, b) -> Integer.compare(b, a)).skip(39)
- .findFirst().orElse(-1);
- return checkVal >= 100;
- }
- private static void printTable(Map<StatPool, Integer> pool) {
- List<StatPool> sort = pool.entrySet().stream().sorted((a, b) -> Integer.compare(b.getValue(), a.getValue()))
- .limit(39).map(e -> e.getKey()).collect(Collectors.toList());
- if(sort.size() < 39) {
- throw new IllegalArgumentException("Size of the pool is < 39");
- }
- System.out.println("Roll;Distribution;BuyValue;Dist");
- for(int i = 2; i <= 40; ++ i) {
- int idx = 0;
- if(i <= 21) {
- idx = 39 + 3 - 2 * i;
- } else {
- idx = 2 * i - 43;
- }
- StatPool stat = sort.get(idx);
- int[] arr = stat.stats;
- System.out.println(String.format("%d;%d, %d, %d, %d, %d, %d;%d;%d",
- i, arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], stat.getValue(), pool.get(stat)));
- }
- }
- public static void main(String[] args) {
- Random rnd = new Random();
- Map<StatPool, Integer> randomPeasant = new HashMap<>();
- Map<StatPool, Integer> randomCompetent = new HashMap<>();
- Map<StatPool, Integer> randomHeroic = new HashMap<>();
- Map<StatPool, Integer> randomEpic = new HashMap<>();
- Map<StatPool, Integer> randomDivine = new HashMap<>();
- // Pre-fill the random distributions with a million rolled ability sets
- for(int i = 0; i < 1000000; ++ i) {
- StatPool sp = StatPool.createRandom(rnd);
- if(sp.getValue() >= 10 && sp.getValue() <= 59) {
- if(sp.getValue() <= 19) {
- addToPool(randomPeasant, sp);
- } else if(sp.getValue() <= 29) {
- addToPool(randomCompetent, sp);
- } else if(sp.getValue() <= 39) {
- addToPool(randomHeroic, sp);
- } else if(sp.getValue() <= 49) {
- addToPool(randomEpic, sp);
- } else {
- addToPool(randomDivine, sp);
- }
- }
- }
- // Make sure we have enough data now (the checks are damn slow so this should never run)
- while(!poolFilled(randomPeasant) || !poolFilled(randomCompetent) || !poolFilled(randomHeroic)
- || !poolFilled(randomEpic) || !poolFilled(randomDivine)) {
- StatPool sp = StatPool.createRandom(rnd);
- if(sp.getValue() >= 10 && sp.getValue() <= 59) {
- if(sp.getValue() <= 19) {
- addToPool(randomPeasant, sp);
- } else if(sp.getValue() <= 29) {
- addToPool(randomCompetent, sp);
- } else if(sp.getValue() <= 39) {
- addToPool(randomHeroic, sp);
- } else if(sp.getValue() <= 49) {
- addToPool(randomEpic, sp);
- } else {
- addToPool(randomDivine, sp);
- }
- }
- }
- printTable(randomPeasant);
- printTable(randomCompetent);
- printTable(randomHeroic);
- printTable(randomEpic);
- printTable(randomDivine);
- }
- @Value public static class StatPool {
- private static final int[] INT_VALUES =
- {-1000, -1000, -1000,
- -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 7, 9, 11, 14, 18, 1000};
- public static StatPool createRandom() {
- return createRandom(new Random());
- }
- public static StatPool createRandom(Random rnd) {
- StatPool res = new StatPool();
- for(int i = 0; i < 6; ++ i) {
- res.stats[i] = IntStream.range(0, 4)
- .map(v -> rnd.nextInt(6) + 1).sorted().skip(1).sum();
- }
- IntStream.range(0, 6).forEach(i -> res.stats[i] *= -1);
- Arrays.sort(res.stats);
- IntStream.range(0, 6).forEach(i -> res.stats[i] *= -1);
- return res;
- }
- public int[] stats;
- private StatPool() {
- this.stats = new int[6];
- }
- public int getValue() {
- return IntStream.of(stats).map(s -> INT_VALUES[s]).sum();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement