Search in sources :

Example 1 with Match

use of mage.game.match.Match in project mage by magefree.

the class TournamentImpl method updateResults.

/**
 */
@Override
public void updateResults() {
    for (TournamentPlayer player : players.values()) {
        player.setResults("");
        player.setPoints(0);
        player.setStateInfo("");
    }
    for (Round round : rounds) {
        for (TournamentPairing pair : round.getPairs()) {
            Match match = pair.getMatch();
            if (match != null && match.hasEnded()) {
                TournamentPlayer tp1 = pair.getPlayer1();
                TournamentPlayer tp2 = pair.getPlayer2();
                MatchPlayer mp1 = match.getPlayer(pair.getPlayer1().getPlayer().getId());
                MatchPlayer mp2 = match.getPlayer(pair.getPlayer2().getPlayer().getId());
                // set player state if they finished the round
                if (round.getRoundNumber() == rounds.size()) {
                    // for elimination getRoundNumber = 0 so never true here
                    match.setTournamentRound(round.getRoundNumber());
                    if (tp1.getState() == TournamentPlayerState.DUELING) {
                        if (round.getRoundNumber() == getNumberRounds()) {
                            tp1.setState(TournamentPlayerState.FINISHED);
                        } else {
                            tp1.setState(TournamentPlayerState.WAITING);
                        }
                    }
                    if (tp2.getState() == TournamentPlayerState.DUELING) {
                        if (round.getRoundNumber() == getNumberRounds()) {
                            tp2.setState(TournamentPlayerState.FINISHED);
                        } else {
                            tp2.setState(TournamentPlayerState.WAITING);
                        }
                    }
                }
                // Add round result
                tp1.setResults(addRoundResult(round.getRoundNumber(), pair, tp1, tp2));
                tp2.setResults(addRoundResult(round.getRoundNumber(), pair, tp2, tp1));
                // Add points
                if ((!mp1.hasQuit() && mp1.getWins() > mp2.getWins()) || mp2.hasQuit()) {
                    tp1.setPoints(tp1.getPoints() + 3);
                } else if ((!mp2.hasQuit() && mp1.getWins() < mp2.getWins()) || mp1.hasQuit()) {
                    tp2.setPoints(tp2.getPoints() + 3);
                } else {
                    tp1.setPoints(tp1.getPoints() + 1);
                    tp2.setPoints(tp2.getPoints() + 1);
                }
            }
        }
        for (TournamentPlayer tp : round.getPlayerByes()) {
            tp.setResults(new StringBuilder(tp.getResults()).append('R').append(round.getRoundNumber()).append(' ').append("Bye ").toString());
            tp.setPoints(tp.getPoints() + 3);
        }
    }
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) Match(mage.game.match.Match)

Example 2 with Match

use of mage.game.match.Match in project mage by magefree.

the class TournamentImpl method toProto.

@Override
public TourneyProto toProto() {
    TourneyProto.Builder tourneyBuilder = TourneyProto.newBuilder().setBoosterInfo(this.getBoosterInfo());
    for (TournamentPlayer player : players.values()) {
        TournamentPlayer replacedPlayer = player.getReplacedTournamentPlayer();
        if (replacedPlayer != null) {
            player = replacedPlayer;
        }
        tourneyBuilder.addPlayersBuilder().mergeFrom(player.toProto());
    }
    for (Round round : rounds) {
        TourneyRoundProto.Builder roundBuilder = tourneyBuilder.addRoundsBuilder().setRound(round.getRoundNumber());
        for (TournamentPairing pair : round.getPairs()) {
            Match match = pair.getMatch();
            if (match != null && match.hasEnded()) {
                MatchProto.Builder matchBuilder = roundBuilder.addMatchesBuilder().setName(match.getName()).setGameType(match.getOptions().getGameType()).setDeckType(match.getOptions().getDeckType()).setGames(match.getNumGames()).setDraws(match.getDraws()).addPlayers(matchToProto(match, pair.getPlayer1())).addPlayers(matchToProto(match, pair.getPlayer2())).setMatchOptions(match.getOptions().toProto()).setEndTimeMs((match.getEndTime() != null ? match.getEndTime() : new Date()).getTime());
            }
        }
        for (TournamentPlayer tp : round.getPlayerByes()) {
            roundBuilder.addByes(tp.getPlayer().getName());
        }
    }
    return tourneyBuilder.build();
}
Also used : TourneyProto(mage.game.result.ResultProtos.TourneyProto) MatchProto(mage.game.result.ResultProtos.MatchProto) TourneyRoundProto(mage.game.result.ResultProtos.TourneyRoundProto) Date(java.util.Date) Match(mage.game.match.Match)

Example 3 with Match

use of mage.game.match.Match in project mage by magefree.

the class FreeformUnlimitedCommanderMatchTest method test_getOptions_returnsOriginalOptions.

@Test
public void test_getOptions_returnsOriginalOptions() {
    // Arrange
    MatchOptions options = new MatchOptions("test name", "test match name", false, 2);
    Match match = new FreeformUnlimitedCommanderMatch(options);
    // Act
    MatchOptions actual = match.getOptions();
    // Assert
    Assert.assertEquals(options, actual);
}
Also used : MatchOptions(mage.game.match.MatchOptions) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) Match(mage.game.match.Match) Test(org.junit.Test)

Example 4 with Match

use of mage.game.match.Match in project mage by magefree.

the class FreeformUnlimitedCommanderMatchTest method test_getName_returnsTestName.

@Test
public void test_getName_returnsTestName() {
    // Arrange
    MatchOptions options = new MatchOptions("test name", "test match name", false, 2);
    Match match = new FreeformUnlimitedCommanderMatch(options);
    // Act
    String actual = match.getName();
    // Assert
    Assert.assertEquals("test name", actual);
}
Also used : MatchOptions(mage.game.match.MatchOptions) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) Match(mage.game.match.Match) Test(org.junit.Test)

Example 5 with Match

use of mage.game.match.Match in project mage by magefree.

the class FreeformUnlimitedCommanderMatchTest method test_construct_returnsFreeformPlusCommanderMatch.

@Test
public void test_construct_returnsFreeformPlusCommanderMatch() {
    // Arrange
    MatchOptions options = new MatchOptions("test name", "test match name", false, 2);
    // Act
    Match match = new FreeformUnlimitedCommanderMatch(options);
    // Assert
    Assert.assertEquals(FreeformUnlimitedCommanderMatch.class, match.getClass());
}
Also used : MatchOptions(mage.game.match.MatchOptions) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) Match(mage.game.match.Match) Test(org.junit.Test)

Aggregations

Match (mage.game.match.Match)7 FreeformUnlimitedCommanderMatch (mage.game.FreeformUnlimitedCommanderMatch)3 MatchOptions (mage.game.match.MatchOptions)3 Test (org.junit.Test)3 Game (mage.game.Game)2 MatchPlayer (mage.game.match.MatchPlayer)2 Date (java.util.Date)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Table (mage.game.Table)1 MatchProto (mage.game.result.ResultProtos.MatchProto)1 TourneyProto (mage.game.result.ResultProtos.TourneyProto)1 TourneyRoundProto (mage.game.result.ResultProtos.TourneyRoundProto)1