Search in sources :

Example 16 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class SwissPairingMinimalWeightMatchingTest method PlayerLeftTournamentAfterFirstRound.

@Test
public void PlayerLeftTournamentAfterFirstRound() {
    // 1 > 3
    // 2 > 4
    // 4 left the tournament
    TournamentPlayer player1 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player2 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player3 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player4 = new TournamentPlayer(new PlayerStub(), null);
    List<TournamentPlayer> players = new ArrayList<>();
    // players.add(player4); -- player 4 is not active
    players.add(player2);
    players.add(player3);
    players.add(player1);
    player1.setPoints(3);
    player2.setPoints(3);
    player3.setPoints(0);
    player4.setPoints(0);
    List<Round> rounds = new ArrayList<>();
    Round round = new Round(1, new TournamentStub());
    TournamentPairing pair1 = new TournamentPairing(player1, player3);
    round.addPairing(pair1);
    TournamentPairing pair2 = new TournamentPairing(player4, player2);
    round.addPairing(pair2);
    rounds.add(round);
    SwissPairingMinimalWeightMatching swissPairing = new SwissPairingMinimalWeightMatching(players, rounds, false);
    RoundPairings roundPairings = swissPairing.getRoundPairings();
    Assert.assertEquals(1, roundPairings.getPairings().size());
    Assert.assertEquals(1, roundPairings.getPlayerByes().size());
    CheckPair(roundPairings.getPairings(), player1, player2);
    Assert.assertTrue(roundPairings.getPlayerByes().contains(player3));
}
Also used : PlayerStub(org.mage.test.stub.PlayerStub) RoundPairings(mage.game.tournament.pairing.RoundPairings) TournamentPlayer(mage.game.tournament.TournamentPlayer) ArrayList(java.util.ArrayList) TournamentStub(org.mage.test.stub.TournamentStub) Round(mage.game.tournament.Round) TournamentPairing(mage.game.tournament.TournamentPairing) SwissPairingMinimalWeightMatching(mage.game.tournament.pairing.SwissPairingMinimalWeightMatching) Test(org.junit.Test)

Example 17 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class SwissPairingMinimalWeightMatchingTest method FourPlayersSecondThirdTest.

@Test
public void FourPlayersSecondThirdTest() {
    // 1 > 3
    // 2 > 4
    // 
    // 1 > 2
    // 3 > 4
    TournamentPlayer player3 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player2 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player4 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player1 = new TournamentPlayer(new PlayerStub(), null);
    List<TournamentPlayer> players = new ArrayList<>();
    players.add(player4);
    players.add(player2);
    players.add(player3);
    players.add(player1);
    player1.setPoints(6);
    player2.setPoints(3);
    player3.setPoints(3);
    player4.setPoints(0);
    List<Round> rounds = new ArrayList<>();
    // round 1
    Round round = new Round(1, new TournamentStub());
    TournamentPairing pair1 = new TournamentPairing(player1, player3);
    round.addPairing(pair1);
    TournamentPairing pair2 = new TournamentPairing(player4, player2);
    round.addPairing(pair2);
    rounds.add(round);
    // round 2
    round = new Round(2, new TournamentStub());
    pair1 = new TournamentPairing(player2, player1);
    round.addPairing(pair1);
    pair2 = new TournamentPairing(player4, player3);
    round.addPairing(pair2);
    rounds.add(round);
    SwissPairingMinimalWeightMatching swissPairing = new SwissPairingMinimalWeightMatching(players, rounds, true);
    RoundPairings roundPairings = swissPairing.getRoundPairings();
    Assert.assertEquals(2, roundPairings.getPairings().size());
    Assert.assertEquals(0, roundPairings.getPlayerByes().size());
    CheckPair(roundPairings.getPairings(), player1, player4);
    CheckPair(roundPairings.getPairings(), player2, player3);
    Assert.assertEquals(0, roundPairings.getPlayerByes().size());
}
Also used : PlayerStub(org.mage.test.stub.PlayerStub) RoundPairings(mage.game.tournament.pairing.RoundPairings) TournamentPlayer(mage.game.tournament.TournamentPlayer) ArrayList(java.util.ArrayList) TournamentStub(org.mage.test.stub.TournamentStub) Round(mage.game.tournament.Round) TournamentPairing(mage.game.tournament.TournamentPairing) SwissPairingMinimalWeightMatching(mage.game.tournament.pairing.SwissPairingMinimalWeightMatching) Test(org.junit.Test)

Example 18 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class SwissPairingMinimalWeightMatchingTest method FourPlayersSecondRoundTest.

@Test
public void FourPlayersSecondRoundTest() {
    // 1 > 3
    // 2 > 4
    TournamentPlayer player1 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player2 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player3 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player4 = new TournamentPlayer(new PlayerStub(), null);
    List<TournamentPlayer> players = new ArrayList<>();
    players.add(player4);
    players.add(player2);
    players.add(player3);
    players.add(player1);
    player1.setPoints(3);
    player2.setPoints(3);
    player3.setPoints(0);
    player4.setPoints(0);
    List<Round> rounds = new ArrayList<>();
    Round round = new Round(1, new TournamentStub());
    TournamentPairing pair1 = new TournamentPairing(player1, player3);
    round.addPairing(pair1);
    TournamentPairing pair2 = new TournamentPairing(player4, player2);
    round.addPairing(pair2);
    rounds.add(round);
    SwissPairingMinimalWeightMatching swissPairing = new SwissPairingMinimalWeightMatching(players, rounds, false);
    RoundPairings roundPairings = swissPairing.getRoundPairings();
    Assert.assertEquals(2, roundPairings.getPairings().size());
    Assert.assertEquals(0, roundPairings.getPlayerByes().size());
    CheckPair(roundPairings.getPairings(), player1, player2);
    CheckPair(roundPairings.getPairings(), player3, player4);
    Assert.assertEquals(0, roundPairings.getPlayerByes().size());
}
Also used : PlayerStub(org.mage.test.stub.PlayerStub) RoundPairings(mage.game.tournament.pairing.RoundPairings) TournamentPlayer(mage.game.tournament.TournamentPlayer) ArrayList(java.util.ArrayList) TournamentStub(org.mage.test.stub.TournamentStub) Round(mage.game.tournament.Round) TournamentPairing(mage.game.tournament.TournamentPairing) SwissPairingMinimalWeightMatching(mage.game.tournament.pairing.SwissPairingMinimalWeightMatching) Test(org.junit.Test)

Example 19 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class SwissPairingMinimalWeightMatchingTest method FivePlayersThirdRoundTest.

@Test
public void FivePlayersThirdRoundTest() {
    // 1 > 2
    // 3 > 4
    // 5
    // 
    // 1 > 5
    // 2 > 3
    // 4
    TournamentPlayer player1 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player2 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player3 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player4 = new TournamentPlayer(new PlayerStub(), null);
    TournamentPlayer player5 = new TournamentPlayer(new PlayerStub(), null);
    List<TournamentPlayer> players = new ArrayList<>();
    players.add(player4);
    players.add(player2);
    players.add(player5);
    players.add(player3);
    players.add(player1);
    player1.setPoints(6);
    player2.setPoints(3);
    player3.setPoints(3);
    player4.setPoints(3);
    player5.setPoints(3);
    List<Round> rounds = new ArrayList<>();
    // first round
    Round round = new Round(1, new TournamentStub());
    TournamentPairing pair1 = new TournamentPairing(player1, player2);
    round.addPairing(pair1);
    TournamentPairing pair2 = new TournamentPairing(player3, player4);
    round.addPairing(pair2);
    round.getPlayerByes().add(player5);
    rounds.add(round);
    // second round
    round = new Round(1, new TournamentStub());
    pair1 = new TournamentPairing(player1, player5);
    round.addPairing(pair1);
    pair2 = new TournamentPairing(player2, player3);
    round.addPairing(pair2);
    round.getPlayerByes().add(player4);
    rounds.add(round);
    SwissPairingMinimalWeightMatching swissPairing = new SwissPairingMinimalWeightMatching(players, rounds, false);
    RoundPairings roundPairings = swissPairing.getRoundPairings();
    Assert.assertEquals(2, roundPairings.getPairings().size());
    Assert.assertEquals(1, roundPairings.getPlayerByes().size());
    CheckPair(roundPairings.getPairings(), player1, player4);
    CheckPair(roundPairings.getPairings(), player2, player5);
    Assert.assertTrue(roundPairings.getPlayerByes().contains(player3));
}
Also used : PlayerStub(org.mage.test.stub.PlayerStub) RoundPairings(mage.game.tournament.pairing.RoundPairings) TournamentPlayer(mage.game.tournament.TournamentPlayer) ArrayList(java.util.ArrayList) TournamentStub(org.mage.test.stub.TournamentStub) Round(mage.game.tournament.Round) TournamentPairing(mage.game.tournament.TournamentPairing) SwissPairingMinimalWeightMatching(mage.game.tournament.pairing.SwissPairingMinimalWeightMatching) Test(org.junit.Test)

Example 20 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class MatchView method initTournamentTable.

// used for tournaments
private void initTournamentTable(Table table) {
    this.matchId = table.getTournament().getId();
    this.matchName = table.getName();
    this.gameType = table.getGameType();
    if (table.getTournament().getOptions().getNumberRounds() > 0) {
        this.gameType = new StringBuilder(this.gameType).append(' ').append(table.getTournament().getOptions().getNumberRounds()).append(" Rounds").toString();
    }
    StringBuilder sbDeckType = new StringBuilder(table.getDeckType());
    if (!table.getTournament().getBoosterInfo().isEmpty()) {
        sbDeckType.append(' ').append(table.getTournament().getBoosterInfo());
    }
    if (table.getName() != null && !table.getName().isEmpty()) {
        sbDeckType.append(table.getDeckType()).append(" [").append(table.getName()).append(']');
    }
    this.deckType = sbDeckType.toString();
    StringBuilder sb1 = new StringBuilder();
    for (TournamentPlayer tPlayer : table.getTournament().getPlayers()) {
        sb1.append(tPlayer.getPlayer().getName()).append(" (").append(tPlayer.getPoints()).append(" P.) ");
    }
    this.players = sb1.toString();
    StringBuilder sb2 = new StringBuilder();
    if (!table.getTournament().getRounds().isEmpty()) {
        for (TournamentPlayer tPlayer : table.getTournament().getPlayers()) {
            sb2.append(tPlayer.getPlayer().getName()).append(": ").append(tPlayer.getResults()).append(' ');
        }
    } else {
        sb2.append("Canceled");
    }
    this.result = sb2.toString();
    this.startTime = table.getTournament().getStartTime();
    this.endTime = table.getTournament().getEndTime();
    this.replayAvailable = false;
    this.rated = table.getTournament().getOptions().getMatchOptions().isRated();
}
Also used : TournamentPlayer(mage.game.tournament.TournamentPlayer)

Aggregations

TournamentPlayer (mage.game.tournament.TournamentPlayer)32 TournamentPairing (mage.game.tournament.TournamentPairing)10 ArrayList (java.util.ArrayList)7 DraftOptions (mage.game.draft.DraftOptions)6 Round (mage.game.tournament.Round)6 RoundPairings (mage.game.tournament.pairing.RoundPairings)6 SwissPairingMinimalWeightMatching (mage.game.tournament.pairing.SwissPairingMinimalWeightMatching)6 UUID (java.util.UUID)5 Table (mage.game.Table)5 User (mage.server.User)5 PlayerStub (org.mage.test.stub.PlayerStub)5 TournamentStub (org.mage.test.stub.TournamentStub)5 Deck (mage.cards.decks.Deck)4 GameException (mage.game.GameException)4 MatchPlayer (mage.game.match.MatchPlayer)4 Test (org.junit.Test)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TableManager (mage.server.managers.TableManager)3 Entry (java.util.Map.Entry)2 Optional (java.util.Optional)2