skill setting is now used by AIs

This commit is contained in:
BetaSteward 2011-05-07 23:16:00 -04:00
parent 33e7569f87
commit c87328d08e
15 changed files with 52 additions and 52 deletions

View file

@ -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);

View file

@ -75,6 +75,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
protected int maxDepth;
protected int maxNodes;
protected int maxThink;
protected LinkedList<Ability> actions = new LinkedList<Ability>();
protected List<UUID> targets = new ArrayList<UUID>();
protected List<String> choices = new ArrayList<String>();
@ -82,9 +83,10 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> 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<ComputerPlayer6> 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<ComputerPlayer6> 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);

View file

@ -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) {

View file

@ -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"));
}
}

View file

@ -95,6 +95,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
protected int maxDepth;
protected int maxNodes;
protected int maxThink;
protected int nodeCount = 0;
protected long thinkTime = 0;
protected LinkedList<Ability> actions = new LinkedList<Ability>();
@ -104,9 +105,10 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> 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<ComputerPlayer2> 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<ComputerPlayer2> 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);
}

View file

@ -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) {

View file

@ -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"));
}
}

View file

@ -68,9 +68,9 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
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;
}

View file

@ -87,7 +87,7 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
}
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;
}

View file

@ -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;
}

View file

@ -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();

View file

@ -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 {

View file

@ -44,8 +44,8 @@ import mage.view.TableView;
public interface GamesRoom extends Room {
public List<TableView> 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);

View file

@ -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;
}

View file

@ -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;