Search in sources :

Example 1 with Round

use of mage.game.tournament.Round 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 Round

use of mage.game.tournament.Round 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 3 with Round

use of mage.game.tournament.Round 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 4 with Round

use of mage.game.tournament.Round 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 5 with Round

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

Aggregations

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