use of mage.game.match.MatchOptions in project mage by magefree.
the class GameChooser method createTestGame.
// GEN-LAST:event_btnNewTournamentActionPerformed
private void createTestGame(String gameName, String gameType, boolean useMonteCarloAI) {
TableView table;
try {
String testDeckFile = "test.dck";
File f = new File(testDeckFile);
if (!f.exists()) {
// default test deck
testDeckFile = DeckUtil.writeTextToTempFile("" + "5 Swamp" + System.lineSeparator() + "5 Forest" + System.lineSeparator() + "5 Island" + System.lineSeparator() + "5 Mountain" + System.lineSeparator() + "5 Plains");
}
DeckCardLists testDeck = DeckImporter.importDeckFromFile(testDeckFile, false);
PlayerType aiType = useMonteCarloAI ? PlayerType.COMPUTER_MONTE_CARLO : PlayerType.COMPUTER_MAD;
MatchOptions options = new MatchOptions(gameName, gameType, false, 2);
options.getPlayerTypes().add(PlayerType.HUMAN);
options.getPlayerTypes().add(aiType);
options.setDeckType("Limited");
options.setAttackOption(MultiplayerAttackOption.LEFT);
options.setRange(RangeOfInfluence.ALL);
options.setWinsNeeded(1);
options.setMatchTimeLimit(MatchTimeLimit.NONE);
options.setFreeMulligans(2);
options.setSkillLevel(SkillLevel.CASUAL);
options.setRollbackTurnsAllowed(true);
options.setQuitRatio(100);
options.setMinimumRating(0);
String serverAddress = SessionHandler.getSession().getServerHostname().orElse("");
options.setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress));
table = SessionHandler.createTable(roomId, options);
SessionHandler.joinTable(roomId, table.getTableId(), "Human", PlayerType.HUMAN, 1, testDeck, "");
SessionHandler.joinTable(roomId, table.getTableId(), "Computer", aiType, 5, testDeck, "");
SessionHandler.startMatch(roomId, table.getTableId());
} catch (HeadlessException ex) {
handleError(ex);
}
}
use of mage.game.match.MatchOptions in project mage by magefree.
the class TournamentController method init.
private void init() {
tournament.addTableEventListener((Listener<TableEvent>) event -> {
switch(event.getEventType()) {
case CHECK_STATE_PLAYERS:
checkPlayersState();
break;
case INFO:
managerFactory.chatManager().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, null, MessageType.STATUS, null);
logger.debug(tournament.getId() + " " + event.getMessage());
break;
case START_DRAFT:
startDraft(event.getDraft());
break;
case CONSTRUCT:
if (!isAbort()) {
construct();
} else {
endTournament();
}
break;
case START_MATCH:
if (!isAbort()) {
initTournament();
startMatch(event.getPair(), event.getMatchOptions());
}
break;
case START_MULTIPLAYER_MATCH:
if (!isAbort()) {
initTournament();
MatchOptions matchOptions = event.getMatchOptions();
if (matchOptions != null && event.getMultiplayerRound() != null) {
for (TournamentPlayer player : event.getMultiplayerRound().getAllPlayers()) {
matchOptions.getPlayerTypes().add(player.getPlayerType());
}
}
startMultiplayerMatch(event.getMultiplayerRound(), event.getMatchOptions());
}
break;
case END:
endTournament();
break;
}
});
tournament.addPlayerQueryEventListener((Listener<PlayerQueryEvent>) event -> {
try {
switch(event.getQueryType()) {
case CONSTRUCT:
construct(event.getPlayerId(), event.getMax());
break;
}
} catch (MageException ex) {
logger.fatal("Player event listener error", ex);
}
});
for (TournamentPlayer player : tournament.getPlayers()) {
if (!player.getPlayer().isHuman()) {
player.setJoined();
logger.debug("player " + player.getPlayer().getId() + " has joined tournament " + tournament.getId());
managerFactory.chatManager().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, null);
}
}
checkStart();
}
use of mage.game.match.MatchOptions in project mage by magefree.
the class MageBase method start.
public void start() throws Exception {
if (server == null) {
String[] args = new String[] { "-testMode=true" };
Main.main(args);
connect("player", "localhost", 17171);
UUID roomId = server.getMainRoomId();
MatchOptions options = new MatchOptions("1", "Two Player Duel");
options.getPlayerTypes().add("Human");
options.getPlayerTypes().add("Computer - default");
options.setDeckType("Limited");
options.setAttackOption(MultiplayerAttackOption.LEFT);
options.setRange(RangeOfInfluence.ALL);
options.setWinsNeeded(1);
TableView table = server.createTable(sessionId, roomId, options);
System.out.println("Cards in the deck: " + Sets.loadDeck("UW Control.dck").getCards().size());
server.joinTable(sessionId, roomId, table.getTableId(), "Human", "Human", Sets.loadDeck("UW Control.dck"));
server.joinTable(sessionId, roomId, table.getTableId(), "Computer", "Computer - default", Sets.loadDeck("UW Control.dck"));
server.startMatch(sessionId, roomId, table.getTableId());
synchronized (syncStart) {
int waitTime = 7000;
Date prev = new Date();
syncStart.wait(waitTime);
Date intermediate = new Date();
if (intermediate.getTime() - prev.getTime() > waitTime - 500) {
throw new IllegalStateException("Couldn't start server");
}
}
}
}
use of mage.game.match.MatchOptions in project mage by magefree.
the class LoadTest method createSimpleGameOptions.
private MatchOptions createSimpleGameOptions(String gameName, GameTypeView gameTypeView, Session session, PlayerType playersType) {
MatchOptions options = new MatchOptions(gameName, gameTypeView.getName(), false, 2);
options.getPlayerTypes().add(playersType);
options.getPlayerTypes().add(playersType);
options.setDeckType(session.getDeckTypes()[0]);
options.setLimited(false);
options.setAttackOption(MultiplayerAttackOption.MULTIPLE);
options.setRange(RangeOfInfluence.ALL);
options.setWinsNeeded(1);
options.setMatchTimeLimit(MatchTimeLimit.MIN__15);
return options;
}
use of mage.game.match.MatchOptions in project mage by magefree.
the class LoadTest method test_TwoUsersPlayGameUntilEnd.
@Test
@Ignore
public void test_TwoUsersPlayGameUntilEnd() {
// monitor other players
LoadPlayer monitor = new LoadPlayer("monitor");
// users
LoadPlayer player1 = new LoadPlayer("1");
LoadPlayer player2 = new LoadPlayer("2");
// game by user 1
GameTypeView gameType = player1.session.getGameTypes().get(0);
MatchOptions gameOptions = createSimpleGameOptionsForBots(gameType, player1.session);
TableView game = player1.session.createTable(player1.roomID, gameOptions);
UUID tableId = game.getTableId();
Assert.assertEquals(player1.userName, game.getControllerName());
DeckCardLists deckList = DeckTestUtils.buildRandomDeckAndInitCards("GR", true);
Optional<TableView> checkGame;
/*
for(DeckCardInfo info: deckList.getCards()) {
logger.info(info.getCardName());
}*/
// before connect
checkGame = monitor.getTable(tableId);
Assert.assertTrue(checkGame.isPresent());
Assert.assertEquals(2, checkGame.get().getSeats().size());
Assert.assertEquals("", checkGame.get().getSeats().get(0).getPlayerName());
Assert.assertEquals("", checkGame.get().getSeats().get(1).getPlayerName());
// connect user 1
Assert.assertTrue(player1.session.joinTable(player1.roomID, tableId, player1.userName, PlayerType.HUMAN, 1, deckList, ""));
checkGame = monitor.getTable(tableId);
Assert.assertTrue(checkGame.isPresent());
Assert.assertEquals(2, checkGame.get().getSeats().size());
Assert.assertEquals(player1.userName, checkGame.get().getSeats().get(0).getPlayerName());
Assert.assertEquals("", checkGame.get().getSeats().get(1).getPlayerName());
// connect user 2
Assert.assertTrue(player2.session.joinTable(player2.roomID, tableId, player2.userName, PlayerType.HUMAN, 1, deckList, ""));
checkGame = monitor.getTable(tableId);
Assert.assertTrue(checkGame.isPresent());
Assert.assertEquals(2, checkGame.get().getSeats().size());
Assert.assertEquals(player1.userName, checkGame.get().getSeats().get(0).getPlayerName());
Assert.assertEquals(player2.userName, checkGame.get().getSeats().get(1).getPlayerName());
// match start
Assert.assertTrue(player1.session.startMatch(player1.roomID, tableId));
// playing until game over
while (!player1.client.isGameOver() && !player2.client.isGameOver()) {
checkGame = monitor.getTable(tableId);
logger.warn(checkGame.get().getTableState());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.error(e.getMessage(), e);
}
}
}
Aggregations