diff --git a/forge-ai/src/main/java/forge/ai/AiController.java b/forge-ai/src/main/java/forge/ai/AiController.java index 49de5aa3519..84934c2e0c0 100644 --- a/forge-ai/src/main/java/forge/ai/AiController.java +++ b/forge-ai/src/main/java/forge/ai/AiController.java @@ -100,22 +100,25 @@ import forge.util.MyRandom; * @version $Id$ */ public class AiController { - private static boolean USE_SIMULATION = false; - private final Player player; private final Game game; private final AiCardMemory memory; - public boolean bCheatShuffle; + private boolean cheatShuffle; + private boolean useSimulation; private SpellAbilityPicker simPicker; public boolean canCheatShuffle() { - return bCheatShuffle; + return cheatShuffle; } public void allowCheatShuffle(boolean canCheatShuffle) { - this.bCheatShuffle = canCheatShuffle; + this.cheatShuffle = canCheatShuffle; } + public void setUseSimulation(boolean value) { + this.useSimulation = value; + } + public Game getGame() { return game; } @@ -1213,7 +1216,7 @@ public class AiController { if (all == null || all.isEmpty()) return null; - if (USE_SIMULATION) { + if (useSimulation) { return simPicker.chooseSpellAbilityToPlay(getOriginalAndAltCostAbilities(all), skipCounter); } diff --git a/forge-ai/src/main/java/forge/ai/LobbyPlayerAi.java b/forge-ai/src/main/java/forge/ai/LobbyPlayerAi.java index 30d6d2345a8..c8c7c20f5ba 100644 --- a/forge-ai/src/main/java/forge/ai/LobbyPlayerAi.java +++ b/forge-ai/src/main/java/forge/ai/LobbyPlayerAi.java @@ -1,5 +1,7 @@ package forge.ai; +import java.util.Map; + import forge.LobbyPlayer; import forge.game.Game; import forge.game.player.IGameEntitiesFactory; @@ -7,19 +9,23 @@ import forge.game.player.Player; import forge.game.player.PlayerController; public class LobbyPlayerAi extends LobbyPlayer implements IGameEntitiesFactory { - public LobbyPlayerAi(String name) { - super(name); - } private String aiProfile = ""; private boolean rotateProfileEachGame; private boolean allowCheatShuffle; + private boolean useSimulation; + + public LobbyPlayerAi(String name, Map options) { + super(name); + if (options != null && "True".equals(options.get("UseSimulation"))) { + this.useSimulation = true; + } + } public boolean isAllowCheatShuffle() { return allowCheatShuffle; } - public void setAllowCheatShuffle(boolean allowCheatShuffle) { this.allowCheatShuffle = allowCheatShuffle; } @@ -38,6 +44,7 @@ public class LobbyPlayerAi extends LobbyPlayer implements IGameEntitiesFactory { private PlayerControllerAi createControllerFor(Player ai) { PlayerControllerAi result = new PlayerControllerAi(ai.getGame(), ai, this); + result.setUseSimulation(useSimulation); result.allowCheatShuffle(allowCheatShuffle); return result; } diff --git a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java index 0b3c19ce75b..383f97d8428 100644 --- a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java +++ b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java @@ -74,6 +74,9 @@ public class PlayerControllerAi extends PlayerController { brains.allowCheatShuffle(value); } + public void setUseSimulation(boolean value) { + brains.setUseSimulation(value); + } public SpellAbility getAbilityToPlay(List abilities, ITriggerEvent triggerEvent) { if (abilities.size() == 0) { diff --git a/forge-gui-desktop/src/main/java/forge/screens/home/sanctioned/CSubmenuConstructed.java b/forge-gui-desktop/src/main/java/forge/screens/home/sanctioned/CSubmenuConstructed.java index 7a78b89d594..953f1e50c02 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/home/sanctioned/CSubmenuConstructed.java +++ b/forge-gui-desktop/src/main/java/forge/screens/home/sanctioned/CSubmenuConstructed.java @@ -228,7 +228,7 @@ public enum CSubmenuConstructed implements ICDoc, IMenuProvider { for (final int i : view.getParticipants()) { String name = view.getPlayerName(i); LobbyPlayer lobbyPlayer = view.isPlayerAI(i) - ? GamePlayerUtil.createAiPlayer(name, view.getPlayerAvatar(i)) + ? GamePlayerUtil.createAiPlayer(name, view.getPlayerAvatar(i), view.getAiOptions(i)) : GamePlayerUtil.getGuiPlayer(name, i); RegisteredPlayer rp = view.getDeckChooser(i).getPlayer(); diff --git a/forge-gui-desktop/src/main/java/forge/screens/home/sanctioned/VSubmenuConstructed.java b/forge-gui-desktop/src/main/java/forge/screens/home/sanctioned/VSubmenuConstructed.java index bdbfafcb44f..bfa5cf99300 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/home/sanctioned/VSubmenuConstructed.java +++ b/forge-gui-desktop/src/main/java/forge/screens/home/sanctioned/VSubmenuConstructed.java @@ -12,14 +12,18 @@ import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.Vector; import javax.swing.ButtonGroup; import javax.swing.JButton; +import javax.swing.JCheckBoxMenuItem; import javax.swing.JPanel; +import javax.swing.JPopupMenu; import javax.swing.ScrollPaneConstants; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -469,6 +473,15 @@ public enum VSubmenuConstructed implements IVSubmenu { return playerPanels.get(playernum).isAi(); } + public Map getAiOptions(int playernum) { + if (playerPanels.get(playernum).isSimulatedAi()) { + Map options = new HashMap(); + options.put("UseSimulation", "True"); + return options; + } + return null; + } + public int getNumPlayers() { return activePlayersNum; } @@ -506,6 +519,7 @@ public enum VSubmenuConstructed implements IVSubmenu { private final FTextField txtPlayerName = new FTextField.Builder().text("Player name").build(); private FRadioButton radioHuman; private FRadioButton radioAi; + private JCheckBoxMenuItem radioAiUseSimulation; private FComboBoxWrapper teamComboBox = new FComboBoxWrapper(); private FComboBoxWrapper aeTeamComboBox = new FComboBoxWrapper(); @@ -559,7 +573,7 @@ public enum VSubmenuConstructed implements IVSubmenu { this.add(radioAi, "wrap"); this.add(newLabel("Team:"), "w 40px, h 30px"); - populateTeamsComboBoxes(); + populateTeamsComboBoxes(); teamComboBox.addActionListener(teamListener); aeTeamComboBox.addActionListener(teamListener); teamComboBox.addTo(this, variantBtnConstraints + ", pushx, growx, gaptop 5px"); @@ -742,9 +756,13 @@ public enum VSubmenuConstructed implements IVSubmenu { } } - public Boolean isAi() { + public boolean isAi() { return radioAi.isSelected(); } + + public boolean isSimulatedAi() { + return radioAi.isSelected() && radioAiUseSimulation.isSelected(); + } public void setVanguardButtonText(String text) { vgdSelectorBtn.setText(text); @@ -906,6 +924,10 @@ public enum VSubmenuConstructed implements IVSubmenu { private void createPlayerTypeOptions() { radioHuman = new FRadioButton("Human", index == 0); radioAi = new FRadioButton("AI", index != 0); + JPopupMenu menu = new JPopupMenu(); + radioAiUseSimulation = new JCheckBoxMenuItem("Use Simulation"); + menu.add(radioAiUseSimulation); + radioAi.setComponentPopupMenu(menu); radioHuman.addMouseListener(radioMouseAdapter); radioAi.addMouseListener(radioMouseAdapter); @@ -1382,15 +1404,15 @@ public enum VSubmenuConstructed implements IVSubmenu { /** update vanguard list. */ public void updateVanguardList(int playerIndex) { - FList vgdList = getVanguardLists().get(playerIndex); - Object lastSelection = vgdList.getSelectedValue(); - vgdList.setListData(isPlayerAI(playerIndex) ? aiListData : humanListData); - if (null != lastSelection) { - vgdList.setSelectedValue(lastSelection, true); - } + FList vgdList = getVanguardLists().get(playerIndex); + Object lastSelection = vgdList.getSelectedValue(); + vgdList.setListData(isPlayerAI(playerIndex) ? aiListData : humanListData); + if (null != lastSelection) { + vgdList.setSelectedValue(lastSelection, true); + } - if (-1 == vgdList.getSelectedIndex()) { - vgdList.setSelectedIndex(0); - } + if (-1 == vgdList.getSelectedIndex()) { + vgdList.setSelectedIndex(0); + } } } diff --git a/forge-gui-desktop/src/test/java/forge/ai/simulation/GameSimulatorTest.java b/forge-gui-desktop/src/test/java/forge/ai/simulation/GameSimulatorTest.java index 3f8c0915f19..f6b8683f8b7 100644 --- a/forge-gui-desktop/src/test/java/forge/ai/simulation/GameSimulatorTest.java +++ b/forge-gui-desktop/src/test/java/forge/ai/simulation/GameSimulatorTest.java @@ -29,8 +29,8 @@ public class GameSimulatorTest extends TestCase { private Game initAndCreateGame() { List players = Lists.newArrayList(); Deck d1 = new Deck(); - players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p2"))); - players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p1"))); + players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p2", null))); + players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p1", null))); GameRules rules = new GameRules(GameType.Constructed); Match match = new Match(rules, players); Game game = new Game(players, rules, match); diff --git a/forge-gui/src/main/java/forge/player/GamePlayerUtil.java b/forge-gui/src/main/java/forge/player/GamePlayerUtil.java index b22fc72454c..42cfcf2bc22 100644 --- a/forge-gui/src/main/java/forge/player/GamePlayerUtil.java +++ b/forge-gui/src/main/java/forge/player/GamePlayerUtil.java @@ -1,5 +1,7 @@ package forge.player; +import java.util.Map; + import forge.GuiBase; import forge.LobbyPlayer; import forge.ai.AiProfileUtil; @@ -46,7 +48,10 @@ public final class GamePlayerUtil { return createAiPlayer(name, avatarCount == 0 ? 0 : MyRandom.getRandom().nextInt(avatarCount)); } public final static LobbyPlayer createAiPlayer(String name, int avatarIndex) { - LobbyPlayerAi player = new LobbyPlayerAi(name); + return createAiPlayer(name, avatarIndex, null); + } + public final static LobbyPlayer createAiPlayer(String name, int avatarIndex, Map options) { + LobbyPlayerAi player = new LobbyPlayerAi(name, options); // TODO: implement specific AI profiles for quest mode. String lastProfileChosen = FModel.getPreferences().getPref(FPref.UI_CURRENT_AI_PROFILE);