Target mutations bias players with lower health
This commit is contained in:
parent
9da64d8372
commit
3d64b00d39
|
@ -2,9 +2,12 @@ package tc.oc.pgm.mutation.types;
|
|||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import tc.oc.commons.core.stream.Collectors;
|
||||
import com.google.api.client.util.Lists;
|
||||
import tc.oc.commons.core.random.MutableWeightedRandomChooser;
|
||||
import tc.oc.commons.core.util.TimeUtils;
|
||||
import tc.oc.pgm.match.Match;
|
||||
import tc.oc.pgm.match.MatchPlayer;
|
||||
|
@ -54,9 +57,18 @@ public interface TargetMutation extends MutationModule {
|
|||
* @return the random players.
|
||||
*/
|
||||
default List<MatchPlayer> search() {
|
||||
return match().participants()
|
||||
.filter(MatchPlayer::isSpawned)
|
||||
.collect(Collectors.toRandomSubList(entropy(), targets()));
|
||||
Set<MatchPlayer> players = new HashSet<>();
|
||||
MutableWeightedRandomChooser<MatchPlayer, Double> chooser = new MutableWeightedRandomChooser<>(
|
||||
match().participants().filter(MatchPlayer::canInteract),
|
||||
player -> Math.max(1, player.getBukkit().getMaxHealth() - player.getBukkit().getHealth())
|
||||
);
|
||||
int targets = targets();
|
||||
for(int i = 0; !chooser.isEmpty() && i < targets; i++) {
|
||||
MatchPlayer choice = chooser.choose(entropy());
|
||||
players.add(choice);
|
||||
chooser.remove(choice);
|
||||
}
|
||||
return Lists.newArrayList(players);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package tc.oc.commons.core.random;
|
||||
|
||||
import tc.oc.commons.core.stream.Collectors;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* A random chooser that supports insertion and removal of choices.
|
||||
|
@ -17,6 +21,10 @@ public class MutableWeightedRandomChooser<T, N extends Number> extends WeightedR
|
|||
addAll(weights);
|
||||
}
|
||||
|
||||
public MutableWeightedRandomChooser(Stream<T> elements, Function<T, N> scale) {
|
||||
this(elements.collect(Collectors.mappingTo(scale)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return options.isEmpty();
|
||||
|
|
Loading…
Reference in New Issue