Search in sources :

Example 11 with TournamentPlayer

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

the class TournamentController method timeout.

public void timeout(UUID userId) {
    if (userPlayerMap.containsKey(userId)) {
        TournamentPlayer tournamentPlayer = tournament.getPlayer(userPlayerMap.get(userId));
        if (tournamentPlayer.getDeck() != null) {
            tournament.autoSubmit(userPlayerMap.get(userId), tournamentPlayer.generateDeck());
        } else {
            StringBuilder sb = new StringBuilder();
            managerFactory.userManager().getUser(userId).ifPresent(user -> sb.append(user.getName()));
            sb.append(" - no deck found for auto submit");
            logger.fatal(sb);
            tournamentPlayer.setEliminated();
            tournamentPlayer.setStateInfo("No deck for auto submit");
        }
    }
}
Also used : TournamentPlayer(mage.game.tournament.TournamentPlayer)

Example 12 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer 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 13 with TournamentPlayer

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

the class SwissPairingSimple method getPairingsSimple.

private RoundPairings getPairingsSimple(List<TournamentPlayer> players, List<Round> rounds) {
    List<TournamentPairing> pairings = new ArrayList<>();
    List<TournamentPlayer> playerByes = new ArrayList<>();
    // sort players by tournament points
    players.sort((p1, p2) -> p2.getPoints() - p1.getPoints());
    // create pairings
    while (!players.isEmpty()) {
        TournamentPlayer player1 = players.get(0);
        players.remove(0);
        TournamentPlayer playerForPossibleSecondPairing = null;
        for (TournamentPlayer player2 : players) {
            if (alreadyPaired(rounds, player1, player2)) {
                // if already paired but equal points -> remember if second pairing is needed
                if (playerForPossibleSecondPairing == null) {
                    playerForPossibleSecondPairing = player2;
                }
            } else {
                if (player2.getPoints() < player1.getPoints() && playerForPossibleSecondPairing != null) {
                    // pair again with a player
                    pairings.add(new TournamentPairing(player1, playerForPossibleSecondPairing));
                    players.remove(playerForPossibleSecondPairing);
                    player1 = null;
                    break;
                } else {
                    // pair agains the next not paired before
                    pairings.add(new TournamentPairing(player1, player2));
                    players.remove(player2);
                    player1 = null;
                    break;
                }
            }
        }
        if (player1 != null) {
            // no pairing done yet
            if (playerForPossibleSecondPairing != null) {
                // pair again with a player
                pairings.add(new TournamentPairing(player1, playerForPossibleSecondPairing));
                players.remove(playerForPossibleSecondPairing);
            } else {
                // player free round - add to bye players of this round
                playerByes.add(player1);
            }
        }
    }
    return new RoundPairings(pairings, playerByes);
}
Also used : TournamentPlayer(mage.game.tournament.TournamentPlayer) ArrayList(java.util.ArrayList) TournamentPairing(mage.game.tournament.TournamentPairing)

Example 14 with TournamentPlayer

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

the class SwissPairingMinimalWeightMatching method getRoundPairings.

public RoundPairings getRoundPairings() {
    // return round pairings with minimal weight
    List<TournamentPairing> pairings = new ArrayList<>();
    List<TournamentPlayer> playerByes = new ArrayList<>();
    Map<Integer, TournamentPlayer> map = new HashMap<>();
    for (PlayerInfo player : swissPlayers) {
        map.put(player.getId(), player.getTournamentPlayer());
    }
    if (n > playersCount) {
        // last vertex -- bye
        playerByes.add(map.get(result[n - 1]));
        result[result[n - 1]] = -1;
        result[n - 1] = -1;
    }
    for (int i = 0; i < playersCount; i++) {
        if (result[i] >= 0) {
            pairings.add(new TournamentPairing(map.get(i), map.get(result[i])));
            result[result[i]] = -1;
            result[i] = -1;
        }
    }
    return new RoundPairings(pairings, playerByes);
}
Also used : TournamentPlayer(mage.game.tournament.TournamentPlayer) TournamentPairing(mage.game.tournament.TournamentPairing)

Example 15 with TournamentPlayer

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

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