From a2c7425458f645802a352abc4783e0afc73dba13 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Thu, 3 Dec 2020 19:22:35 -0500 Subject: Adapt to esodata changes --- .../main/java/bjc/utils/gen/WeightedRandom.java | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'base/src/main/java/bjc/utils/gen/WeightedRandom.java') diff --git a/base/src/main/java/bjc/utils/gen/WeightedRandom.java b/base/src/main/java/bjc/utils/gen/WeightedRandom.java index 969020e..01a961f 100644 --- a/base/src/main/java/bjc/utils/gen/WeightedRandom.java +++ b/base/src/main/java/bjc/utils/gen/WeightedRandom.java @@ -2,10 +2,10 @@ package bjc.utils.gen; import java.util.Random; -import bjc.data.IPair; import bjc.data.Pair; +import bjc.data.SimplePair; import bjc.funcdata.FunctionalList; -import bjc.funcdata.IList; +import bjc.funcdata.ListEx; /** * Represents a random number generator where certain results are weighted more @@ -17,7 +17,7 @@ import bjc.funcdata.IList; * The type of values that are randomly selected. */ public class WeightedRandom { - private final IList> values; + private final ListEx> values; /* The source for any needed random numbers */ private Random source; @@ -50,7 +50,7 @@ public class WeightedRandom { this(BASE); } - private WeightedRandom(Random src, IList> vals, int chance) { + private WeightedRandom(Random src, ListEx> vals, int chance) { source = src; values = vals; @@ -68,7 +68,7 @@ public class WeightedRandom { * The result to get when the chance comes up. */ public void addProbability(final int chance, final E result) { - values.add(new Pair<>(chance, result)); + values.add(new SimplePair<>(chance, result)); totalChance += chance; } @@ -91,7 +91,7 @@ public class WeightedRandom { */ public E generateValue(Random rn) { int target = rn.nextInt(totalChance); - for (IPair val : values) { + for (Pair val : values) { int prob = val.getLeft(); if (target < prob) { @@ -114,8 +114,8 @@ public class WeightedRandom { * * @return A list of all the values that can be generated */ - public IList getResults() { - return values.map(IPair::getRight); + public ListEx getResults() { + return values.map(Pair::getRight); } /** @@ -124,7 +124,7 @@ public class WeightedRandom { * * @return A list of pairs of values and value probabilities */ - public IList> getValues() { + public ListEx> getValues() { return values; } @@ -157,7 +157,7 @@ public class WeightedRandom { public E getDescent(int factor, Random rn) { if (values.getSize() == 0) return null; - for (IPair val : values) { + for (Pair val : values) { if (rn.nextInt(factor) == 0) continue; if (exhaust) { @@ -169,7 +169,7 @@ public class WeightedRandom { return val.getRight(); } - IPair val = values.getByIndex(values.getSize() - 1); + Pair val = values.getByIndex(values.getSize() - 1); if (exhaust) values.removeMatching(val); return val.getRight(); @@ -231,7 +231,7 @@ public class WeightedRandom { // System.err.printf("\tTRACE: got %d success for binomial trials (%d <= 1d%d, // %d times)\n", numSuc, target, bound, trials); - IPair val = values.getByIndex(Math.min(numSuc, values.getSize() - 1)); + Pair val = values.getByIndex(Math.min(numSuc, values.getSize() - 1)); if (exhaust) { totalChance -= val.getLeft(); @@ -248,8 +248,8 @@ public class WeightedRandom { * @return A new WeightedRandom that is exhaustible. */ public WeightedRandom exhaustible() { - IList> lst = new FunctionalList<>(); - for (IPair val : values) lst.add(val); + ListEx> lst = new FunctionalList<>(); + for (Pair val : values) lst.add(val); WeightedRandom res = new WeightedRandom<>(source, lst, totalChance); -- cgit v1.2.3