Revert "Merge branch 'temp_dev6' into 'master'"

This reverts merge request !499
This commit is contained in:
Sol
2018-05-01 01:11:29 +00:00
parent 64e8dd35c2
commit 1a3308017a
19 changed files with 22 additions and 49 deletions

View File

@@ -2216,9 +2216,7 @@ public class ComputerUtil {
} }
return ComputerUtilCard.getBestAI(list); return ComputerUtilCard.getBestAI(list);
} else { } else {
// TODO: This is just picking randomly amongst already picked things. It should probably pick the worst instead. return Iterables.getFirst(votes.keySet(), null);
List<Object> a = Arrays.asList(votes.keySet().toArray());
return a.get(MyRandom.getRandom().nextInt(a.size()));
} }
case "Protection": case "Protection":
if (votes.isEmpty()) { if (votes.isEmpty()) {

View File

@@ -134,11 +134,7 @@ public class ComputerUtilMana {
Collections.sort(orderedCards, new Comparator<Card>() { Collections.sort(orderedCards, new Comparator<Card>() {
@Override @Override
public int compare(final Card card1, final Card card2) { public int compare(final Card card1, final Card card2) {
int result = Integer.compare(manaCardMap.get(card1), manaCardMap.get(card2)); return Integer.compare(manaCardMap.get(card1), manaCardMap.get(card2));
if(result == 0) {
result = Float.compare(card1.getTimestamp(), card2.getTimestamp());
}
return result;
} }
}); });
@@ -312,7 +308,7 @@ public class ComputerUtilMana {
} }
// select which abilities may be used for each shard // select which abilities may be used for each shard
ListMultimap<ManaCostShard, SpellAbility> sourcesForShards = ComputerUtilMana.groupAndOrderToPayShards(ai, manaAbilityMap, cost); Multimap<ManaCostShard, SpellAbility> sourcesForShards = ComputerUtilMana.groupAndOrderToPayShards(ai, manaAbilityMap, cost);
sortManaAbilities(sourcesForShards); sortManaAbilities(sourcesForShards);
@@ -862,6 +858,7 @@ public class ComputerUtilMana {
} }
AiController aic = ((PlayerControllerAi)ai.getController()).getAi(); AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
int chanceToReserve = aic.getIntProperty(AiProps.RESERVE_MANA_FOR_MAIN2_CHANCE);
PhaseType curPhase = ai.getGame().getPhaseHandler().getPhase(); PhaseType curPhase = ai.getGame().getPhaseHandler().getPhase();
@@ -880,8 +877,7 @@ public class ComputerUtilMana {
// obey mana reservations for Main 2; otherwise, obey mana reservations depending on the "chance to reserve" // obey mana reservations for Main 2; otherwise, obey mana reservations depending on the "chance to reserve"
// AI profile variable. // AI profile variable.
if (sa.getSVar("LowPriorityAI").equals("")) { if (sa.getSVar("LowPriorityAI").equals("")) {
float chanceToReserve = aic.getFloatProperty(AiProps.RESERVE_MANA_FOR_MAIN2_CHANCE); if (chanceToReserve == 0 || MyRandom.getRandom().nextInt(100) >= chanceToReserve) {
if (MyRandom.getRandom().nextDouble() >= chanceToReserve) {
return false; return false;
} }
} }

View File

@@ -5,7 +5,6 @@ import java.util.List;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import forge.ai.ComputerUtilAbility; import forge.ai.ComputerUtilAbility;
import forge.ai.ComputerUtilCard; import forge.ai.ComputerUtilCard;

View File

@@ -2,7 +2,6 @@ package forge.ai.ability;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import forge.ai.ComputerUtil; import forge.ai.ComputerUtil;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;
import forge.game.player.Player; import forge.game.player.Player;

View File

@@ -2,7 +2,6 @@ package forge.ai.ability;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import forge.ai.ComputerUtil; import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilCard; import forge.ai.ComputerUtilCard;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;

View File

@@ -2,7 +2,6 @@ package forge.ai.ability;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import forge.ai.ComputerUtil; import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilCost; import forge.ai.ComputerUtilCost;
import forge.ai.ComputerUtilMana; import forge.ai.ComputerUtilMana;

View File

@@ -1,7 +1,6 @@
package forge.ai.ability; package forge.ai.ability;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import forge.ai.ComputerUtil; import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilCard; import forge.ai.ComputerUtilCard;
import forge.ai.ComputerUtilMana; import forge.ai.ComputerUtilMana;

View File

@@ -1,7 +1,6 @@
package forge.ai.ability; package forge.ai.ability;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.card.CounterType; import forge.game.card.CounterType;

View File

@@ -1,7 +1,6 @@
package forge.ai.ability; package forge.ai.ability;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import forge.ai.ComputerUtil; import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilMana; import forge.ai.ComputerUtilMana;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;

View File

@@ -1,7 +1,6 @@
package forge.ai.ability; package forge.ai.ability;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import forge.ai.ComputerUtil; import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilCard; import forge.ai.ComputerUtilCard;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;

View File

@@ -1,7 +1,6 @@
package forge.ai.ability; package forge.ai.ability;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import forge.ai.ComputerUtilCard; import forge.ai.ComputerUtilCard;
import forge.ai.SpecialCardAi; import forge.ai.SpecialCardAi;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;

View File

@@ -1,7 +1,6 @@
package forge.ai.ability; package forge.ai.ability;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import forge.ai.ComputerUtilMana; import forge.ai.ComputerUtilMana;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;
import forge.game.ability.ApiType; import forge.game.ability.ApiType;

View File

@@ -1,7 +1,6 @@
package forge.ai.ability; package forge.ai.ability;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import forge.ai.ComputerUtilCard; import forge.ai.ComputerUtilCard;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;
import forge.card.CardSplitType; import forge.card.CardSplitType;

View File

@@ -34,27 +34,22 @@ public class MyRandom {
private static Random random = new SecureRandom(); private static Random random = new SecureRandom();
/** /**
* Changes into a non-CSPRNG, which can be seeded for use in tests/repeatable experiments. * <p>
*/ * percentTrue.<br>
public static void setSeed(int seed) { * If percent is like 30, then 30% of the time it will be true.
System.out.println("Setting the RNG seed to: " + seed); * </p>
random = new Random(seed);
}
/**
* Returns True with Percent probability.
* *
* TODO: My guess is no one is passing in a number scaled to 100. This API should probably be cut. * @param percent
* a int.
* @return a boolean.
*/ */
public static boolean percentTrue(final long percent) { public static boolean percentTrue(final int percent) {
return percent > MyRandom.getRandom().nextDouble() * 100; return percent > MyRandom.getRandom().nextInt(100);
} }
/** /**
* Gets the random. * Gets the random.
* *
* TODO: Make this private, and instead add a robust set of APIs here.
*
* @return the random * @return the random
*/ */
public static Random getRandom() { public static Random getRandom() {
@@ -65,7 +60,7 @@ public class MyRandom {
int[] groups = new int[numGroups]; int[] groups = new int[numGroups];
for (int i = 0; i < value; i++) { for (int i = 0; i < value; i++) {
groups[MyRandom.getRandom().nextInt(numGroups)]++; groups[random.nextInt(numGroups)]++;
} }
return groups; return groups;

View File

@@ -35,7 +35,7 @@ public class KeywordCollection implements Iterable<String>, Serializable {
} }
public int size() { public int size() {
return map.size(); return map.values().size();
} }
public int getAmount(Keyword keyword) { public int getAmount(Keyword keyword) {

View File

@@ -22,7 +22,6 @@ import forge.game.player.RegisteredPlayer;
import forge.model.FModel; import forge.model.FModel;
import forge.player.GamePlayerUtil; import forge.player.GamePlayerUtil;
import forge.util.Lang; import forge.util.Lang;
import forge.util.MyRandom;
public class SimulateMatch { public class SimulateMatch {
public static void simulate(String[] args) { public static void simulate(String[] args) {
@@ -56,7 +55,6 @@ public class SimulateMatch {
} }
else { else {
System.err.println("Illegal parameter usage"); System.err.println("Illegal parameter usage");
argumentHelp();
return; return;
} }
} }
@@ -80,10 +78,6 @@ public class SimulateMatch {
type = GameType.valueOf(WordUtils.capitalize(params.get("f").get(0))); 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); GameRules rules = new GameRules(type);
rules.setAppliedVariants(EnumSet.of(type)); rules.setAppliedVariants(EnumSet.of(type));
@@ -151,7 +145,7 @@ public class SimulateMatch {
} }
private static void argumentHelp() { 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] -s [S] -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] -q");
System.out.println("\tsim - stands for simulation mode"); 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("\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"); System.out.println("\tdeck is treated as file if it ends with a dot followed by three numbers or letters");
@@ -161,7 +155,6 @@ public class SimulateMatch {
System.out.println("\tT - Type of tournament to run with all provided decks (Bracket, RoundRobin, Swiss)"); 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("\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("\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."); System.out.println("\tq - Quiet flag. Output just the game result, not the entire game log.");
} }
@@ -174,6 +167,7 @@ public class SimulateMatch {
final Game g1 = mc.createGame(); final Game g1 = mc.createGame();
// will run match in the same thread // will run match in the same thread
long startTime = System.currentTimeMillis();
try { try {
TimeLimitedCodeBlock.runWithTimeout(new Runnable() { TimeLimitedCodeBlock.runWithTimeout(new Runnable() {
@Override @Override

View File

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

View File

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

View File

@@ -368,6 +368,9 @@ public class QuestDraftUtils {
// Update dialog with winner // Update dialog with winner
} }
RegisteredPlayer regPlayer = mc.getWinner();
//draft.setWinner(regPlayer.getPlayer().getName());
//FModel.getQuest().save();
gui.finishGame(); gui.finishGame();
} else { } else {
final HostedMatch newMatch = GuiBase.getInterface().hostMatch(); final HostedMatch newMatch = GuiBase.getInterface().hostMatch();