mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Update lots of code to use MyRandom directly.
Some parts of the code were using the normal random, instead of going through the MyRandom class. This makes it much harder to change the RNG method later. For example, you may want to change the RNG to always be seeded with the same number, for running AI experiments. This change makes that easier.
This commit is contained in:
@@ -50,6 +50,7 @@ import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.trackable.Tracker;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.Visitor;
|
||||
|
||||
import java.util.*;
|
||||
@@ -797,7 +798,7 @@ public class Game {
|
||||
onePlayerHasTimeShifted = false;
|
||||
}
|
||||
|
||||
CardRarity anteRarity = validRarities.get(new Random().nextInt(validRarities.size()));
|
||||
CardRarity anteRarity = validRarities.get(MyRandom.getRandom().nextInt(validRarities.size()));
|
||||
|
||||
System.out.println("Rarity chosen for ante: " + anteRarity.name());
|
||||
|
||||
@@ -827,7 +828,7 @@ public class Game {
|
||||
library.removeAll((Collection<?>)toRemove);
|
||||
|
||||
if (library.size() > 0) { //Make sure that matches were found. If not, use the original method to choose antes
|
||||
Card ante = library.get(new Random().nextInt(library.size()));
|
||||
Card ante = library.get(MyRandom.getRandom().nextInt(library.size()));
|
||||
anteed.put(player, ante);
|
||||
} else {
|
||||
chooseRandomCardsForAnte(player, anteed);
|
||||
|
||||
@@ -179,7 +179,7 @@ public class Match {
|
||||
return myRemovedAnteCards;
|
||||
}
|
||||
|
||||
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, CardPool section, boolean canRandomFoil, Random generator) {
|
||||
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, CardPool section, boolean canRandomFoil) {
|
||||
PlayerZone library = player.getZone(zoneType);
|
||||
List<Card> newLibrary = new ArrayList<Card>();
|
||||
for (final Entry<PaperCard, Integer> stackOfCards : section) {
|
||||
@@ -245,11 +245,9 @@ public class Match {
|
||||
}
|
||||
}
|
||||
|
||||
Random generator = MyRandom.getRandom();
|
||||
|
||||
preparePlayerLibrary(player, ZoneType.Library, myDeck.getMain(), psc.useRandomFoil(), generator);
|
||||
preparePlayerLibrary(player, ZoneType.Library, myDeck.getMain(), psc.useRandomFoil());
|
||||
if (myDeck.has(DeckSection.Sideboard)) {
|
||||
preparePlayerLibrary(player, ZoneType.Sideboard, myDeck.get(DeckSection.Sideboard), psc.useRandomFoil(), generator);
|
||||
preparePlayerLibrary(player, ZoneType.Sideboard, myDeck.get(DeckSection.Sideboard), psc.useRandomFoil());
|
||||
}
|
||||
|
||||
player.initVariantsZones(psc);
|
||||
|
||||
@@ -9,11 +9,11 @@ import forge.game.player.Player;
|
||||
import forge.game.spellability.AbilitySub;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
public class ChooseNumberEffect extends SpellAbilityEffect {
|
||||
|
||||
@@ -54,8 +54,7 @@ public class ChooseNumberEffect extends SpellAbilityEffect {
|
||||
if ((tgt == null) || p.canBeTargetedBy(sa)) {
|
||||
int chosen;
|
||||
if (random) {
|
||||
final Random randomGen = new Random();
|
||||
chosen = randomGen.nextInt(max - min) + min;
|
||||
chosen = MyRandom.getRandom().nextInt(max - min) + min;
|
||||
p.getGame().getAction().nofityOfValue(sa, p, Integer.toString(chosen), null);
|
||||
} else {
|
||||
String title = sa.hasParam("ListTitle") ? sa.getParam("ListTitle") : "Choose a number";
|
||||
|
||||
@@ -179,8 +179,7 @@ public class DigUntilEffect extends SpellAbilityEffect {
|
||||
}
|
||||
}
|
||||
if (sa.hasParam("RevealRandomOrder")) {
|
||||
final Random random = MyRandom.getRandom();
|
||||
Collections.shuffle(revealed, random);
|
||||
Collections.shuffle(revealed, MyRandom.getRandom());
|
||||
}
|
||||
|
||||
if (sa.hasParam("NoneFoundDestination") && found.size() < untilAmount) {
|
||||
|
||||
@@ -11,7 +11,6 @@ import forge.util.MyRandom;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class ReorderZoneEffect extends SpellAbilityEffect {
|
||||
@Override
|
||||
@@ -33,8 +32,7 @@ public class ReorderZoneEffect extends SpellAbilityEffect {
|
||||
if ((tgt == null) || p.canBeTargetedBy(sa)) {
|
||||
CardCollection list = new CardCollection(p.getCardsIn(zone));
|
||||
if (shuffle) {
|
||||
final Random ran = MyRandom.getRandom();
|
||||
Collections.shuffle(list, ran);
|
||||
Collections.shuffle(list, MyRandom.getRandom());
|
||||
p.getZone(zone).setCards(list);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user