Merge branch 'temp_dev6' into 'master'

Allow for Seeded RNG in simulation games!

See merge request core-developers/forge!499
This commit is contained in:
Sol
2018-05-01 01:01:30 +00:00
19 changed files with 50 additions and 23 deletions

View File

@@ -22,6 +22,7 @@ import forge.game.player.RegisteredPlayer;
import forge.model.FModel;
import forge.player.GamePlayerUtil;
import forge.util.Lang;
import forge.util.MyRandom;
public class SimulateMatch {
public static void simulate(String[] args) {
@@ -55,6 +56,7 @@ public class SimulateMatch {
}
else {
System.err.println("Illegal parameter usage");
argumentHelp();
return;
}
}
@@ -78,6 +80,10 @@ public class SimulateMatch {
type = GameType.valueOf(WordUtils.capitalize(params.get("f").get(0)));
}
if (params.containsKey("s")) {
MyRandom.setSeed(Integer.parseInt(params.get("s").get(0)));
}
GameRules rules = new GameRules(type);
rules.setAppliedVariants(EnumSet.of(type));
@@ -145,7 +151,7 @@ public class SimulateMatch {
}
private static void argumentHelp() {
System.out.println("Syntax: forge.exe sim -d <deck1[.dck]> ... <deckX[.dck]> -D [D] -n [N] -m [M] -t [T] -p [P] -f [F] -q");
System.out.println("Syntax: forge.exe sim -d <deck1[.dck]> ... <deckX[.dck]> -D [D] -n [N] -m [M] -t [T] -p [P] -f [F] -s [S] -q");
System.out.println("\tsim - stands for simulation mode");
System.out.println("\tdeck1 (or deck2,...,X) - constructed deck name or filename (has to be quoted when contains multiple words)");
System.out.println("\tdeck is treated as file if it ends with a dot followed by three numbers or letters");
@@ -155,6 +161,7 @@ public class SimulateMatch {
System.out.println("\tT - Type of tournament to run with all provided decks (Bracket, RoundRobin, Swiss)");
System.out.println("\tP - Amount of players per match (used only with Tournaments, defaults to 2)");
System.out.println("\tF - format of games, defaults to constructed");
System.out.println("\ts - Set the RNG seed. Use if you want to play the same game twice.");
System.out.println("\tq - Quiet flag. Output just the game result, not the entire game log.");
}
@@ -167,7 +174,6 @@ public class SimulateMatch {
final Game g1 = mc.createGame();
// will run match in the same thread
long startTime = System.currentTimeMillis();
try {
TimeLimitedCodeBlock.runWithTimeout(new Runnable() {
@Override

View File

@@ -183,7 +183,7 @@ public class GameSimulatorTest extends SimulationTestCase {
GameSimulator sim = createSimulator(game, p);
Game simGame = sim.getSimulatedGameState();
SpellAbility unmorphSA = findSAWithPrefix(ripper, "Morph—Reveal a black card");
SpellAbility unmorphSA = findSAWithPrefix(ripper, "Morph"); // —Reveal a black card
assertNotNull(unmorphSA);
sim.simulateSpellAbility(unmorphSA);
assertEquals(18, simGame.getPlayers().get(0).getLife());

View File

@@ -29,12 +29,14 @@ import forge.item.IPaperCard;
import forge.model.FModel;
import forge.properties.ForgePreferences;
import forge.properties.ForgePreferences.FPref;
import forge.util.MyRandom;
import junit.framework.TestCase;
public class SimulationTestCase extends TestCase {
private static boolean initialized = false;
protected Game initAndCreateGame() {
MyRandom.setSeed(0); // Initialize the random seed to create predictable tests.
List<RegisteredPlayer> players = Lists.newArrayList();
Deck d1 = new Deck();
players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p2", null)));