From c87328d08e68464e934e764d432a34c022dec49a Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Sat, 7 May 2011 23:16:00 -0400 Subject: [PATCH] skill setting is now used by AIs --- .../main/java/mage/client/table/TablesPanel.java | 4 ++-- .../src/mage/player/ai/ComputerPlayer6.java | 10 ++++++---- .../src/mage/player/ai/ComputerPlayer7.java | 6 ++---- .../src/mage/player/ai/Config2.java | 8 ++++---- .../src/mage/player/ai/ComputerPlayer2.java | 10 ++++++---- .../src/mage/player/ai/ComputerPlayer3.java | 6 ++---- .../src/mage/player/ai/Config.java | 8 ++++---- .../src/mage/player/ai/SimulatedPlayer.java | 4 ++-- .../src/mage/player/human/HumanPlayer.java | 2 +- .../src/main/java/mage/server/ServerImpl.java | 4 ++-- .../main/java/mage/server/TableController.java | 16 ++++++++-------- .../src/main/java/mage/server/TableManager.java | 8 ++++---- .../main/java/mage/server/game/GamesRoom.java | 4 ++-- .../java/mage/server/game/GamesRoomImpl.java | 8 ++++---- .../java/mage/server/game/PlayerFactory.java | 6 +++--- 15 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java index bba40defc9..c4034f38d0 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -303,14 +303,14 @@ public class TablesPanel extends javax.swing.JPanel implements Observer { try { MatchOptions options = new MatchOptions("1", "Two Player Duel"); options.getPlayerTypes().add("Human"); - options.getPlayerTypes().add("Computer - default"); + options.getPlayerTypes().add("Computer - minimax"); options.setDeckType("Limited"); options.setAttackOption(MultiplayerAttackOption.LEFT); options.setRange(RangeOfInfluence.ALL); options.setWinsNeeded(1); table = session.createTable(roomId, options); session.joinTable(roomId, table.getTableId(), "Human", "Human", 1, Sets.loadDeck("test.dck")); - session.joinTable(roomId, table.getTableId(), "Computer", "Computer - default", 1, Sets.loadDeck("test.dck")); + session.joinTable(roomId, table.getTableId(), "Computer", "Computer - minimax", 1, Sets.loadDeck("test.dck")); session.startGame(roomId, table.getTableId()); } catch (Exception ex) { handleError(ex); diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java index ed96192549..dfa67a63c1 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java @@ -75,6 +75,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements protected int maxDepth; protected int maxNodes; + protected int maxThink; protected LinkedList actions = new LinkedList(); protected List targets = new ArrayList(); protected List choices = new ArrayList(); @@ -82,9 +83,10 @@ public class ComputerPlayer6 extends ComputerPlayer implements protected int currentScore; protected SimulationNode2 root; - public ComputerPlayer6(String name, RangeOfInfluence range) { + public ComputerPlayer6(String name, RangeOfInfluence range, int skill) { super(name, range); - maxDepth = Config2.maxDepth; + maxDepth = skill * 2; + maxThink = skill * 3; maxNodes = Config2.maxNodes; } @@ -370,7 +372,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements }); pool.execute(task); try { - return task.get(Config2.maxThinkSeconds, TimeUnit.SECONDS); + return task.get(maxThink, TimeUnit.SECONDS); } catch (TimeoutException e) { logger.info("simulating - timed out"); task.cancel(true); @@ -501,7 +503,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements targets = node.getTargets(); if (node.getChoices().size() > 0) choices = node.getChoices(); - if (depth == Config2.maxDepth) { + if (depth == maxDepth) { logger.info("saved"); node.children.clear(); node.children.add(bestNode); diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer7.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer7.java index 49d6b409a2..536b633fb5 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer7.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer7.java @@ -66,10 +66,8 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player { } - public ComputerPlayer7(String name, RangeOfInfluence range) { - super(name, range); - maxDepth = Config2.maxDepth; - maxNodes = Config2.maxNodes; + public ComputerPlayer7(String name, RangeOfInfluence range, int skill) { + super(name, range, skill); } public ComputerPlayer7(final ComputerPlayer7 player) { diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/Config2.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/Config2.java index 2d837e1e37..191b9be967 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/Config2.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/Config2.java @@ -45,13 +45,13 @@ public class Config2 { private final static Logger logger = Logging.getLogger(Config2.class.getName()); - public static final int maxDepth; +// public static final int maxDepth; public static final int maxNodes; public static final int evaluatorLifeFactor; public static final int evaluatorPermanentFactor; public static final int evaluatorCreatureFactor; public static final int evaluatorHandFactor; - public static final int maxThinkSeconds; +// public static final int maxThinkSeconds; static { Properties p = new Properties(); @@ -63,13 +63,13 @@ public class Config2 { } catch (URISyntaxException ex) { Logger.getLogger(Config2.class.getName()).log(Level.SEVERE, null, ex); } - maxDepth = Integer.parseInt(p.getProperty("maxDepth")); +// maxDepth = Integer.parseInt(p.getProperty("maxDepth")); maxNodes = Integer.parseInt(p.getProperty("maxNodes")); evaluatorLifeFactor = Integer.parseInt(p.getProperty("evaluatorLifeFactor")); evaluatorPermanentFactor = Integer.parseInt(p.getProperty("evaluatorPermanentFactor")); evaluatorCreatureFactor = Integer.parseInt(p.getProperty("evaluatorCreatureFactor")); evaluatorHandFactor = Integer.parseInt(p.getProperty("evaluatorHandFactor")); - maxThinkSeconds = Integer.parseInt(p.getProperty("maxThinkSeconds")); +// maxThinkSeconds = Integer.parseInt(p.getProperty("maxThinkSeconds")); } } diff --git a/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/ComputerPlayer2.java b/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/ComputerPlayer2.java index 5e9c992cf2..84a29314ed 100644 --- a/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/ComputerPlayer2.java +++ b/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/ComputerPlayer2.java @@ -95,6 +95,7 @@ public class ComputerPlayer2 extends ComputerPlayer implements protected int maxDepth; protected int maxNodes; + protected int maxThink; protected int nodeCount = 0; protected long thinkTime = 0; protected LinkedList actions = new LinkedList(); @@ -104,9 +105,10 @@ public class ComputerPlayer2 extends ComputerPlayer implements protected int currentScore; protected SimulationNode root; - public ComputerPlayer2(String name, RangeOfInfluence range) { + public ComputerPlayer2(String name, RangeOfInfluence range, int skill) { super(name, range); - maxDepth = Config.maxDepth; + maxDepth = skill * 2; + maxThink = skill * 3; maxNodes = Config.maxNodes; } @@ -323,7 +325,7 @@ public class ComputerPlayer2 extends ComputerPlayer implements long startTime = System.nanoTime(); pool.execute(task); try { - task.get(Config.maxThinkSeconds, TimeUnit.SECONDS); + task.get(maxThink, TimeUnit.SECONDS); long endTime = System.nanoTime(); long duration = endTime - startTime; logger.info("Calculated " + root.nodeCount + " nodes in " + duration/1000000000.0 + "s"); @@ -720,7 +722,7 @@ public class ComputerPlayer2 extends ComputerPlayer implements for (Player copyPlayer: sim.getState().getPlayers().values()) { Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId()); - SimulatedPlayer newPlayer = new SimulatedPlayer(copyPlayer.getId(), copyPlayer.getId().equals(playerId)); + SimulatedPlayer newPlayer = new SimulatedPlayer(copyPlayer.getId(), copyPlayer.getId().equals(playerId), maxDepth); newPlayer.restore(origPlayer); sim.getState().getPlayers().put(copyPlayer.getId(), newPlayer); } diff --git a/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/ComputerPlayer3.java b/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/ComputerPlayer3.java index 980c5ddf1e..9a4cff1869 100644 --- a/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/ComputerPlayer3.java +++ b/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/ComputerPlayer3.java @@ -81,10 +81,8 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player { } - public ComputerPlayer3(String name, RangeOfInfluence range) { - super(name, range); - maxDepth = Config.maxDepth; - maxNodes = Config.maxNodes; + public ComputerPlayer3(String name, RangeOfInfluence range, int skill) { + super(name, range, skill); } public ComputerPlayer3(final ComputerPlayer3 player) { diff --git a/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/Config.java b/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/Config.java index a5ad2526d4..e583cec05e 100644 --- a/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/Config.java +++ b/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/Config.java @@ -43,13 +43,13 @@ public class Config { private final static Logger logger = Logger.getLogger(Config.class); - public static final int maxDepth; +// public static final int maxDepth; public static final int maxNodes; public static final int evaluatorLifeFactor; public static final int evaluatorPermanentFactor; public static final int evaluatorCreatureFactor; public static final int evaluatorHandFactor; - public static final int maxThinkSeconds; +// public static final int maxThinkSeconds; static { Properties p = new Properties(); @@ -61,13 +61,13 @@ public class Config { } catch (URISyntaxException ex) { logger.fatal("", ex); } - maxDepth = Integer.parseInt(p.getProperty("maxDepth")); +// maxDepth = Integer.parseInt(p.getProperty("maxDepth")); maxNodes = Integer.parseInt(p.getProperty("maxNodes")); evaluatorLifeFactor = Integer.parseInt(p.getProperty("evaluatorLifeFactor")); evaluatorPermanentFactor = Integer.parseInt(p.getProperty("evaluatorPermanentFactor")); evaluatorCreatureFactor = Integer.parseInt(p.getProperty("evaluatorCreatureFactor")); evaluatorHandFactor = Integer.parseInt(p.getProperty("evaluatorHandFactor")); - maxThinkSeconds = Integer.parseInt(p.getProperty("maxThinkSeconds")); +// maxThinkSeconds = Integer.parseInt(p.getProperty("maxThinkSeconds")); } } diff --git a/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/SimulatedPlayer.java b/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/SimulatedPlayer.java index a57cf12176..7dc1a557f5 100644 --- a/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/SimulatedPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/SimulatedPlayer.java @@ -68,9 +68,9 @@ public class SimulatedPlayer extends ComputerPlayer { private static PassAbility pass = new PassAbility(); protected int maxDepth; - public SimulatedPlayer(UUID id, boolean isSimulatedPlayer) { + public SimulatedPlayer(UUID id, boolean isSimulatedPlayer, int maxDepth) { super(id); - maxDepth = Config.maxDepth; + this.maxDepth = maxDepth; pass.setControllerId(playerId); this.isSimulatedPlayer = isSimulatedPlayer; } diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index 00f2515fe8..8adebdbc91 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -87,7 +87,7 @@ public class HumanPlayer extends PlayerImpl { } protected transient TargetCreaturePermanent targetCombat = new TargetCreaturePermanent(filter); - public HumanPlayer(String name, RangeOfInfluence range) { + public HumanPlayer(String name, RangeOfInfluence range, int skill) { super(name, range); human = true; } diff --git a/Mage.Server/src/main/java/mage/server/ServerImpl.java b/Mage.Server/src/main/java/mage/server/ServerImpl.java index 76ecbb5fbd..653f32b688 100644 --- a/Mage.Server/src/main/java/mage/server/ServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/ServerImpl.java @@ -167,7 +167,7 @@ public class ServerImpl extends RemoteServer implements Server { @Override public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException, GameException { try { - boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(sessionId, tableId, name, playerType, deckList); + boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(sessionId, tableId, name, playerType, skill, deckList); logger.info("Session " + sessionId + " joined table " + tableId); return ret; } @@ -182,7 +182,7 @@ public class ServerImpl extends RemoteServer implements Server { @Override public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill) throws MageException, GameException { try { - boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name, playerType); + boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name, playerType, skill); logger.info("Session " + sessionId + " joined table " + tableId); return ret; } diff --git a/Mage.Server/src/main/java/mage/server/TableController.java b/Mage.Server/src/main/java/mage/server/TableController.java index e5105d179b..7d3eded0f7 100644 --- a/Mage.Server/src/main/java/mage/server/TableController.java +++ b/Mage.Server/src/main/java/mage/server/TableController.java @@ -106,7 +106,7 @@ public class TableController { ); } - public synchronized boolean joinTournament(UUID sessionId, String name, String playerType) throws GameException { + public synchronized boolean joinTournament(UUID sessionId, String name, String playerType, int skill) throws GameException { if (table.getState() != TableState.WAITING) { return false; } @@ -114,7 +114,7 @@ public class TableController { if (seat == null) { throw new GameException("No available seats."); } - Player player = createPlayer(name, seat.getPlayerType()); + Player player = createPlayer(name, seat.getPlayerType(), skill); tournament.addPlayer(player, seat.getPlayerType()); table.joinTable(player, seat); logger.info("player joined " + player.getId()); @@ -126,7 +126,7 @@ public class TableController { return true; } - public synchronized boolean joinTable(UUID sessionId, String name, String playerType, DeckCardLists deckList) throws GameException { + public synchronized boolean joinTable(UUID sessionId, String name, String playerType, int skill, DeckCardLists deckList) throws GameException { if (table.getState() != TableState.WAITING) { return false; } @@ -139,7 +139,7 @@ public class TableController { throw new GameException(name + " has an invalid deck for this format"); } - Player player = createPlayer(name, seat.getPlayerType()); + Player player = createPlayer(name, seat.getPlayerType(), skill); match.addPlayer(player, deck); table.joinTable(player, seat); logger.info("player joined " + player.getId()); @@ -207,13 +207,13 @@ public class TableController { return table.getValidator().validate(deck); } - private Player createPlayer(String name, String playerType) { + private Player createPlayer(String name, String playerType, int skill) { Player player; if (options == null) { - player = PlayerFactory.getInstance().createPlayer(playerType, name, RangeOfInfluence.ALL); + player = PlayerFactory.getInstance().createPlayer(playerType, name, RangeOfInfluence.ALL, skill); } else { - player = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange()); + player = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange(), skill); } logger.info("Player created " + player.getId()); return player; @@ -238,7 +238,7 @@ public class TableController { table.initGame(); GameOptions options = new GameOptions(); options.testMode = true; - match.getGame().setGameOptions(options); +// match.getGame().setGameOptions(options); GameManager.getInstance().createGameSession(match.getGame(), sessionPlayerMap, table.getId(), null); ChallengeManager.getInstance().prepareChallenge(getPlayerId(), match); SessionManager sessionManager = SessionManager.getInstance(); diff --git a/Mage.Server/src/main/java/mage/server/TableManager.java b/Mage.Server/src/main/java/mage/server/TableManager.java index 1b857e5c38..110b025be9 100644 --- a/Mage.Server/src/main/java/mage/server/TableManager.java +++ b/Mage.Server/src/main/java/mage/server/TableManager.java @@ -91,12 +91,12 @@ public class TableManager { return tables.values(); } - public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws GameException { - return controllers.get(tableId).joinTable(sessionId, name, playerType, deckList); + public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws GameException { + return controllers.get(tableId).joinTable(sessionId, name, playerType, skill, deckList); } - public boolean joinTournament(UUID sessionId, UUID tableId, String name, String playerType) throws GameException { - return controllers.get(tableId).joinTournament(sessionId, name, playerType); + public boolean joinTournament(UUID sessionId, UUID tableId, String name, String playerType, int skill) throws GameException { + return controllers.get(tableId).joinTournament(sessionId, name, playerType, skill); } public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws GameException { diff --git a/Mage.Server/src/main/java/mage/server/game/GamesRoom.java b/Mage.Server/src/main/java/mage/server/game/GamesRoom.java index e752b81a3e..86ea03e6e7 100644 --- a/Mage.Server/src/main/java/mage/server/game/GamesRoom.java +++ b/Mage.Server/src/main/java/mage/server/game/GamesRoom.java @@ -44,8 +44,8 @@ import mage.view.TableView; public interface GamesRoom extends Room { public List getTables(); - public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws GameException; - public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name, String playerType) throws GameException; + public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws GameException; + public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name, String playerType, int skill) throws GameException; public TableView createTable(UUID sessionId, MatchOptions options); public TableView createTournamentTable(UUID sessionId, TournamentOptions options); public void removeTable(UUID sessionId, UUID tableId); diff --git a/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java b/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java index bf87f5eb31..fded9f96ec 100644 --- a/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java +++ b/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java @@ -63,9 +63,9 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable { } @Override - public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, DeckCardLists deckList) throws GameException { + public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws GameException { if (tables.containsKey(tableId)) { - return TableManager.getInstance().joinTable(sessionId, tableId, name, playerType, deckList); + return TableManager.getInstance().joinTable(sessionId, tableId, name, playerType, skill, deckList); } else { return false; } @@ -79,9 +79,9 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable { } @Override - public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name, String playerType) throws GameException { + public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name, String playerType, int skill) throws GameException { if (tables.containsKey(tableId)) { - return TableManager.getInstance().joinTournament(sessionId, tableId, name, playerType); + return TableManager.getInstance().joinTournament(sessionId, tableId, name, playerType, skill); } else { return false; } diff --git a/Mage.Server/src/main/java/mage/server/game/PlayerFactory.java b/Mage.Server/src/main/java/mage/server/game/PlayerFactory.java index a9d295b8d4..4420d80ba3 100644 --- a/Mage.Server/src/main/java/mage/server/game/PlayerFactory.java +++ b/Mage.Server/src/main/java/mage/server/game/PlayerFactory.java @@ -53,12 +53,12 @@ public class PlayerFactory { private PlayerFactory() {} - public Player createPlayer(String playerType, String name, RangeOfInfluence range) { + public Player createPlayer(String playerType, String name, RangeOfInfluence range, int skill) { Player player; Constructor con; try { - con = playerTypes.get(playerType).getConstructor(new Class[]{String.class, RangeOfInfluence.class}); - player = (Player)con.newInstance(new Object[] {name, range}); + con = playerTypes.get(playerType).getConstructor(new Class[]{String.class, RangeOfInfluence.class, int.class}); + player = (Player)con.newInstance(new Object[] {name, range, skill}); } catch (Exception ex) { logger.fatal("PlayerFactory error ", ex); return null;