Search in sources :

Example 1 with RoundPairings

use of mage.game.tournament.pairing.RoundPairings in project mage by magefree.

the class SwissPairingMinimalWeightMatchingTest method PlayerWithByeLeftTournament.

@Test
public void PlayerWithByeLeftTournament() {
    // 1 > 2
    // 3 > 4
    // 5
    // 5 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);
    TournamentPlayer player5 = new TournamentPlayer(new PlayerStub(), null);
    List<TournamentPlayer> players = new ArrayList<>();
    // players.add(player5); -- player 5 is not active
    players.add(player4);
    players.add(player2);
    players.add(player3);
    players.add(player1);
    player1.setPoints(3);
    player2.setPoints(0);
    player3.setPoints(3);
    player4.setPoints(0);
    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);
    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, player3);
    CheckPair(roundPairings.getPairings(), player2, 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 2 with RoundPairings

use of mage.game.tournament.pairing.RoundPairings in project mage by magefree.

the class TournamentSwiss method createRoundSwiss.

protected Round createRoundSwiss() {
    List<TournamentPlayer> roundPlayers = getActivePlayers();
    boolean isLastRound = (rounds.size() + 1 == getNumberRounds());
    Round round = null;
    if (options.matchOptions.getNumSeats() == 2) {
        RoundPairings roundPairings;
        if (roundPlayers.size() <= 16) {
            SwissPairingMinimalWeightMatching swissPairing = new SwissPairingMinimalWeightMatching(roundPlayers, rounds, isLastRound);
            roundPairings = swissPairing.getRoundPairings();
        } else {
            SwissPairingSimple swissPairing = new SwissPairingSimple(roundPlayers, rounds);
            roundPairings = swissPairing.getRoundPairings();
        }
        round = new Round(rounds.size() + 1, this);
        rounds.add(round);
        for (TournamentPairing pairing : roundPairings.getPairings()) {
            round.addPairing(pairing);
        }
        for (TournamentPlayer playerBye : roundPairings.getPlayerByes()) {
            // player free round - add to bye players of this round
            round.getPlayerByes().add(playerBye);
            if (isLastRound) {
                playerBye.setState(TournamentPlayerState.FINISHED);
            } else {
                playerBye.setState(TournamentPlayerState.WAITING);
            }
            playerBye.setStateInfo("Round Bye");
            updateResults();
        }
    }
    return round;
}
Also used : RoundPairings(mage.game.tournament.pairing.RoundPairings) SwissPairingSimple(mage.game.tournament.pairing.SwissPairingSimple) SwissPairingMinimalWeightMatching(mage.game.tournament.pairing.SwissPairingMinimalWeightMatching)

Example 3 with RoundPairings

use of mage.game.tournament.pairing.RoundPairings in project mage by magefree.

the class TournamentSwiss method createMultiplayerRound.

public MultiplayerRound createMultiplayerRound() {
    List<TournamentPlayer> roundPlayers = getActivePlayers();
    boolean isLastRound = (rounds.size() + 1 == getNumberRounds());
    MultiplayerRound round = null;
    if (options.matchOptions.getNumSeats() > 2) {
        options.matchOptions.setAttackOption(MultiplayerAttackOption.MULTIPLE);
        RoundPairings roundPairings;
        if (roundPlayers.size() <= 16) {
            SwissPairingMinimalWeightMatching swissPairing = new SwissPairingMinimalWeightMatching(roundPlayers, rounds, isLastRound);
            roundPairings = swissPairing.getRoundPairings();
        } else {
            SwissPairingSimple swissPairing = new SwissPairingSimple(roundPlayers, rounds);
            roundPairings = swissPairing.getRoundPairings();
        }
        round = new MultiplayerRound(rounds.size() + 1, this, options.matchOptions.getNumSeats());
        for (TournamentPairing pairing : roundPairings.getPairings()) {
            round.addPairing(pairing);
        }
    }
    return round;
}
Also used : RoundPairings(mage.game.tournament.pairing.RoundPairings) SwissPairingSimple(mage.game.tournament.pairing.SwissPairingSimple) SwissPairingMinimalWeightMatching(mage.game.tournament.pairing.SwissPairingMinimalWeightMatching)

Example 4 with RoundPairings

use of mage.game.tournament.pairing.RoundPairings in project mage by magefree.

the class SwissPairingMinimalWeightMatchingTest method SimulateTournament.

private void SimulateTournament(int playersCount, int roundsCount) {
    List<TournamentPlayer> players = new ArrayList<>();
    for (int i = 0; i < playersCount; i++) {
        players.add(new TournamentPlayer(new PlayerStub(), null));
    }
    List<TournamentPairing> playedPairs = new ArrayList<>();
    Set<TournamentPlayer> playersByes = new HashSet<>();
    List<Round> rounds = new ArrayList<>();
    for (int i = 0; i < roundsCount; i++) {
        SwissPairingMinimalWeightMatching swissPairing = new SwissPairingMinimalWeightMatching(new ArrayList<>(players), rounds, i + 1 == roundsCount);
        RoundPairings roundPairings = swissPairing.getRoundPairings();
        Assert.assertEquals(playersCount / 2, roundPairings.getPairings().size());
        Assert.assertEquals(playersCount % 2, roundPairings.getPlayerByes().size());
        Round round = new Round(1, new TournamentStub());
        rounds.add(round);
        for (TournamentPairing pairing : roundPairings.getPairings()) {
            if (ContainsPair(playedPairs, pairing.getPlayer1(), pairing.getPlayer2())) {
                if (i < (playersCount + 1) / 2) {
                    throw new AssertionError("Match between players has been played already.");
                }
            }
            playedPairs.add(pairing);
            round.addPairing(pairing);
            if (RandomUtil.nextBoolean()) {
                pairing.getPlayer1().setPoints(pairing.getPlayer1().getPoints() + 3);
            } else {
                pairing.getPlayer2().setPoints(pairing.getPlayer2().getPoints() + 3);
            }
        }
        for (TournamentPlayer playerBye : roundPairings.getPlayerByes()) {
            if (playersByes.contains(playerBye)) {
                throw new AssertionError("Player already had bye.");
            }
            playersByes.add(playerBye);
            round.getPlayerByes().add(playerBye);
            playerBye.setPoints(playerBye.getPoints() + 3);
        }
    }
}
Also used : TournamentPlayer(mage.game.tournament.TournamentPlayer) ArrayList(java.util.ArrayList) PlayerStub(org.mage.test.stub.PlayerStub) RoundPairings(mage.game.tournament.pairing.RoundPairings) TournamentStub(org.mage.test.stub.TournamentStub) Round(mage.game.tournament.Round) TournamentPairing(mage.game.tournament.TournamentPairing) SwissPairingMinimalWeightMatching(mage.game.tournament.pairing.SwissPairingMinimalWeightMatching) HashSet(java.util.HashSet)

Example 5 with RoundPairings

use of mage.game.tournament.pairing.RoundPairings 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)

Aggregations

RoundPairings (mage.game.tournament.pairing.RoundPairings)8 SwissPairingMinimalWeightMatching (mage.game.tournament.pairing.SwissPairingMinimalWeightMatching)8 ArrayList (java.util.ArrayList)6 Round (mage.game.tournament.Round)6 TournamentPairing (mage.game.tournament.TournamentPairing)6 TournamentPlayer (mage.game.tournament.TournamentPlayer)6 PlayerStub (org.mage.test.stub.PlayerStub)6 TournamentStub (org.mage.test.stub.TournamentStub)6 Test (org.junit.Test)5 SwissPairingSimple (mage.game.tournament.pairing.SwissPairingSimple)2 HashSet (java.util.HashSet)1