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);
}
}
}
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();
}
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);
}
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);
}
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());
}
Aggregations