2017-05-09 14:03:51 -07:00
|
|
|
package magic;
|
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
import java.util.HashMap;
|
2017-05-09 14:03:51 -07:00
|
|
|
import java.util.Locale;
|
2019-12-06 18:36:02 -08:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.function.Function;
|
2020-01-15 12:02:42 -08:00
|
|
|
|
2017-05-09 15:02:55 -07:00
|
|
|
import magic.ai.MagicAI;
|
2017-05-09 14:03:51 -07:00
|
|
|
import magic.ai.MagicAIImpl;
|
2017-05-10 04:49:39 -07:00
|
|
|
import magic.data.DuelConfig;
|
2017-05-09 14:03:51 -07:00
|
|
|
import magic.utility.MagicSystem;
|
|
|
|
|
|
|
|
class CommandLineArgs {
|
2019-12-06 18:36:02 -08:00
|
|
|
private static Map<String, Arg<?>> argMap = new HashMap<>();
|
|
|
|
private static Map<String, Flag> flagMap = new HashMap<>();
|
2017-05-09 14:03:51 -07:00
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
// set player 1 deck (see wiki page for value syntax)
|
|
|
|
private Arg<String> deck1 = new Arg<>("--deck1", "", x -> {
|
|
|
|
MagicSystem.setAiVersusAi(true);
|
|
|
|
return x;
|
|
|
|
});
|
2017-05-09 14:03:51 -07:00
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
// set player 2 deck (see wiki page for value syntax)
|
|
|
|
private Arg<String> deck2 = new Arg<>("--deck2", "", x -> {
|
|
|
|
MagicSystem.setAiVersusAi(true);
|
|
|
|
return x;
|
|
|
|
});
|
2017-05-09 14:03:51 -07:00
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
// HeadlessAiGame-only settings
|
|
|
|
private Flag headless = new Flag("--headless");
|
|
|
|
private Flag cardTest = new Flag("--cardtest");
|
2017-05-09 14:03:51 -07:00
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
// displays refresh rate in hertz for each screen device.
|
|
|
|
private Flag showFps = new Flag("--showfps");
|
2017-05-11 03:20:36 -07:00
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
// turns off gameplay animations for session (does not change preferences).
|
|
|
|
private Flag isAnimationsDisabled = new Flag("--nofx");
|
2017-05-09 14:03:51 -07:00
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
// enables access to additional functionality.
|
|
|
|
private Flag isDevMode = new Flag("--devmode");
|
|
|
|
|
|
|
|
// shows wiki help page in browser.
|
|
|
|
private Flag showHelp = new Flag("--help");
|
|
|
|
|
|
|
|
// sets the desired frames-per-second for the Trident animation library.
|
|
|
|
private Arg<Integer> fps = new Arg<>("--fps", 0, x -> Integer.parseInt(x));
|
2017-05-11 15:01:09 -07:00
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
// limits the number of threads AI uses. (eg. --threads 2)
|
|
|
|
private Arg<Integer> maxAiThreads = new Arg<>("--threads", MagicAI.getMaxThreads(), x -> Integer.parseInt(x));
|
|
|
|
|
|
|
|
// Runs specified test game, equivalent to -DtestGame VM arg. (eg. --test TestAura)
|
|
|
|
private Arg<String> testGame = new Arg<>("--test", "", x -> {
|
|
|
|
System.setProperty("testGame", x);
|
|
|
|
return x;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Setting any of the following arguments will automatically run an AI vs AI game.
|
|
|
|
|
|
|
|
// MagicAIImpl class to load as player 1. (eg. --ai1 MMABFast)
|
|
|
|
private Arg<MagicAIImpl> ai1 = new Arg<>("--ai1", MagicAIImpl.MMABFast, x -> {
|
|
|
|
MagicSystem.setAiVersusAi(true);
|
|
|
|
return MagicAIImpl.valueOf(x);
|
|
|
|
});
|
|
|
|
// MagicAIImpl class to load as player 2. (eg. --ai2 MMABFast)
|
|
|
|
private Arg<MagicAIImpl> ai2 = new Arg<>("--ai2", MagicAIImpl.MMABFast, x -> {
|
|
|
|
MagicSystem.setAiVersusAi(true);
|
|
|
|
return MagicAIImpl.valueOf(x);
|
|
|
|
});
|
|
|
|
// level of AI player #1. (eg. --str1 8)
|
|
|
|
private Arg<Integer> ai1Level = new Arg<>("--str1", 6, x -> {
|
2017-05-11 15:01:09 -07:00
|
|
|
MagicSystem.setAiVersusAi(true);
|
2019-12-06 18:36:02 -08:00
|
|
|
return Integer.parseInt(x);
|
|
|
|
});
|
|
|
|
// level of AI player #2. (eg. --str2 8)
|
|
|
|
private Arg<Integer> ai2Level = new Arg<>("--str2", 6, x -> {
|
|
|
|
MagicSystem.setAiVersusAi(true);
|
|
|
|
return Integer.parseInt(x);
|
|
|
|
});
|
|
|
|
// "best of..." games total in AI v AI game. (eg. --games 3 = best of 3 games)
|
|
|
|
private Arg<Integer> games = new Arg<>("--games", DuelConfig.DEFAULT_GAMES, x -> {
|
|
|
|
MagicSystem.setAiVersusAi(true);
|
|
|
|
return Integer.parseInt(x);
|
|
|
|
});
|
|
|
|
// initial life for each AI player. (eg. --life 10)
|
|
|
|
private Arg<Integer> startLife = new Arg<>("--life", DuelConfig.DEFAULT_LIFE, x -> {
|
|
|
|
MagicSystem.setAiVersusAi(true);
|
|
|
|
return Integer.parseInt(x);
|
|
|
|
});
|
|
|
|
|
|
|
|
// the number of duels to play [--duels 1].
|
|
|
|
private Arg<Integer> duels = new Arg<>("--duels", 1, x -> Integer.parseInt(x));
|
|
|
|
|
2019-12-06 18:36:26 -08:00
|
|
|
// Skiplist for card test
|
|
|
|
private Arg<String> skipList = new Arg<>("--skip", null, x -> x);
|
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
/**
|
|
|
|
* Commandline argument requiring a value
|
|
|
|
*
|
|
|
|
* @param <V> type of internally stored value
|
|
|
|
*/
|
|
|
|
private static class Arg<V> {
|
|
|
|
private String argName;
|
|
|
|
public V value;
|
|
|
|
private Function<String, V> setter;
|
|
|
|
|
|
|
|
public Arg(String argName, V defaultValue, Function<String, V> setter) {
|
|
|
|
this.argName = argName;
|
|
|
|
this.value = defaultValue;
|
|
|
|
this.setter = setter;
|
|
|
|
argMap.put(argName, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void set(String arg) {
|
|
|
|
value = setter.apply(arg);
|
|
|
|
}
|
2017-05-11 15:01:09 -07:00
|
|
|
}
|
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
/**
|
|
|
|
* Commandline argument that is a flag that enables something.
|
|
|
|
*/
|
|
|
|
private static class Flag {
|
|
|
|
public boolean value = false;
|
|
|
|
|
|
|
|
public Flag(String argName) {
|
|
|
|
flagMap.put(argName, this);
|
|
|
|
}
|
2017-05-10 05:20:23 -07:00
|
|
|
}
|
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
CommandLineArgs(final String[] args) {
|
|
|
|
isDevMode.value = MagicSystem.isDevMode();
|
|
|
|
for (int i = 0; i < args.length; i++) {
|
|
|
|
final String arg = args[i].toLowerCase(Locale.ENGLISH);
|
|
|
|
Arg<?> argValue = argMap.get(arg);
|
|
|
|
if (argValue != null) {
|
|
|
|
String arg0 = nextArg(args, i);
|
|
|
|
if (arg0 == null) {
|
|
|
|
throw new IllegalArgumentException("Argument " + argValue.argName + " requires a value");
|
|
|
|
} else {
|
|
|
|
argValue.set(arg0);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
Flag flagValue = flagMap.get(arg);
|
|
|
|
if (flagValue != null) {
|
|
|
|
flagValue.value = true;
|
|
|
|
}
|
|
|
|
}
|
2017-05-10 04:49:39 -07:00
|
|
|
}
|
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
private String nextArg(String[] args, int i) {
|
|
|
|
if (i + 1 >= args.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return args[i + 1].trim();
|
2017-05-09 14:03:51 -07:00
|
|
|
}
|
|
|
|
|
2019-12-06 18:36:02 -08:00
|
|
|
|
2017-05-09 14:03:51 -07:00
|
|
|
MagicAIImpl getAi1() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return ai1.value;
|
2017-05-09 14:03:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MagicAIImpl getAi2() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return ai2.value;
|
2017-05-09 14:03:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int getAi1Level() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return ai1Level.value;
|
2017-05-09 14:03:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int getAi2Level() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return ai2Level.value;
|
2017-05-09 14:03:51 -07:00
|
|
|
}
|
|
|
|
|
2017-05-10 02:29:44 -07:00
|
|
|
boolean isAnimationsEnabled() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return !isAnimationsDisabled.value;
|
2017-05-10 02:29:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int getMaxThreads() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return maxAiThreads.value;
|
2017-05-10 02:29:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean isDevMode() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return isDevMode.value;
|
2017-05-10 02:29:44 -07:00
|
|
|
}
|
|
|
|
|
2017-05-10 04:49:39 -07:00
|
|
|
int getGames() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return games.value;
|
2017-05-10 04:49:39 -07:00
|
|
|
}
|
|
|
|
|
2017-05-10 05:20:23 -07:00
|
|
|
int getLife() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return startLife.value;
|
2017-05-10 05:20:23 -07:00
|
|
|
}
|
|
|
|
|
2017-05-11 03:20:36 -07:00
|
|
|
boolean showHelp() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return showHelp.value;
|
2017-05-11 03:20:36 -07:00
|
|
|
}
|
|
|
|
|
2017-05-11 15:01:09 -07:00
|
|
|
String getDeck1() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return deck1.value;
|
2017-05-11 15:01:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
String getDeck2() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return deck2.value;
|
2017-05-11 15:01:09 -07:00
|
|
|
}
|
|
|
|
|
2017-05-18 17:23:24 -07:00
|
|
|
boolean showFPS() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return showFps.value;
|
2017-05-18 17:23:24 -07:00
|
|
|
}
|
|
|
|
|
2017-06-11 23:38:10 -07:00
|
|
|
boolean isHeadless() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return headless.value;
|
2017-06-11 23:38:10 -07:00
|
|
|
}
|
|
|
|
|
2019-12-05 17:52:53 -08:00
|
|
|
boolean isCardTest() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return cardTest.value;
|
2019-12-05 17:52:53 -08:00
|
|
|
}
|
|
|
|
|
2017-05-18 17:23:24 -07:00
|
|
|
int getFPS() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return fps.value;
|
2017-05-18 17:23:24 -07:00
|
|
|
}
|
|
|
|
|
2017-06-11 14:44:12 -07:00
|
|
|
int getDuels() {
|
2019-12-06 18:36:02 -08:00
|
|
|
return duels.value;
|
2017-06-11 14:44:12 -07:00
|
|
|
}
|
|
|
|
|
2019-12-06 18:36:26 -08:00
|
|
|
String getSkipList() {
|
|
|
|
return skipList.value;
|
|
|
|
}
|
2017-05-09 14:03:51 -07:00
|
|
|
}
|