Search in sources :

Example 1 with MatchOptions

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);
    }
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) PlayerType(mage.players.PlayerType) MatchOptions(mage.game.match.MatchOptions) File(java.io.File) TableView(mage.view.TableView)

Example 2 with MatchOptions

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();
}
Also used : MultiplayerRound(mage.game.tournament.MultiplayerRound) MessageType(mage.view.ChatMessage.MessageType) DraftController(mage.server.draft.DraftController) MessageColor(mage.view.ChatMessage.MessageColor) TableEvent(mage.game.events.TableEvent) ConcurrentMap(java.util.concurrent.ConcurrentMap) Logger(org.apache.log4j.Logger) TableManager(mage.server.managers.TableManager) MatchOptions(mage.game.match.MatchOptions) User(mage.server.User) Draft(mage.game.draft.Draft) TournamentPairing(mage.game.tournament.TournamentPairing) TourneyQuitStatus(mage.game.result.ResultProtos.TourneyQuitStatus) TournamentView(mage.view.TournamentView) TableState(mage.constants.TableState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Deck(mage.cards.decks.Deck) UUID(java.util.UUID) MageException(mage.MageException) PlayerType(mage.players.PlayerType) SoundToPlay(mage.view.ChatMessage.SoundToPlay) PlayerQueryEvent(mage.game.events.PlayerQueryEvent) ManagerFactory(mage.server.managers.ManagerFactory) TournamentPlayer(mage.game.tournament.TournamentPlayer) Entry(java.util.Map.Entry) Table(mage.game.Table) Optional(java.util.Optional) TournamentPlayerState(mage.constants.TournamentPlayerState) Listener(mage.game.events.Listener) GameException(mage.game.GameException) Tournament(mage.game.tournament.Tournament) TableEvent(mage.game.events.TableEvent) TournamentPlayer(mage.game.tournament.TournamentPlayer) MageException(mage.MageException) MatchOptions(mage.game.match.MatchOptions) PlayerQueryEvent(mage.game.events.PlayerQueryEvent)

Example 3 with MatchOptions

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");
            }
        }
    }
}
Also used : MatchOptions(mage.game.match.MatchOptions) UUID(java.util.UUID) Date(java.util.Date)

Example 4 with MatchOptions

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;
}
Also used : MatchOptions(mage.game.match.MatchOptions)

Example 5 with MatchOptions

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);
        }
    }
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) MatchOptions(mage.game.match.MatchOptions) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

MatchOptions (mage.game.match.MatchOptions)13 Test (org.junit.Test)4 DeckCardLists (mage.cards.decks.DeckCardLists)3 FreeformUnlimitedCommanderMatch (mage.game.FreeformUnlimitedCommanderMatch)3 Match (mage.game.match.Match)3 UUID (java.util.UUID)2 TablePlayerPanel (mage.client.table.TablePlayerPanel)2 PlayerType (mage.players.PlayerType)2 File (java.io.File)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 MageException (mage.MageException)1 Deck (mage.cards.decks.Deck)1 TableState (mage.constants.TableState)1 TournamentPlayerState (mage.constants.TournamentPlayerState)1 GameException (mage.game.GameException)1