mirror of
https://github.com/magefree/mage.git
synced 2026-01-23 11:49:56 -08:00
* Tournament handling - Fixed player handling for swiss tournament. No more quit sound or stat eif player already finished the tournament correctly.
This commit is contained in:
parent
95b9507c0c
commit
0e71ac5e53
7 changed files with 75 additions and 46 deletions
|
|
@ -40,8 +40,8 @@ public class Round {
|
|||
|
||||
private final int roundNum;
|
||||
private final Tournament tournament;
|
||||
private final List<TournamentPairing> pairs = new ArrayList<TournamentPairing>();
|
||||
private final List<TournamentPlayer> playerByes = new ArrayList<TournamentPlayer>();
|
||||
private final List<TournamentPairing> pairs = new ArrayList<>();
|
||||
private final List<TournamentPlayer> playerByes = new ArrayList<>();
|
||||
|
||||
public Round(int roundNum, Tournament tournament) {
|
||||
this.roundNum = roundNum;
|
||||
|
|
@ -81,6 +81,10 @@ public class Round {
|
|||
if (tournament instanceof TournamentSingleElimination) {
|
||||
pair.eliminatePlayers();
|
||||
}
|
||||
// if it's the last round, finish all players for the tournament if their match is finished
|
||||
if (getRoundNumber() == tournament.getNumberRounds()) {
|
||||
pair.finishPlayersThatPlayedLastRound();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ public abstract class TournamentImpl implements Tournament {
|
|||
protected List<TournamentPlayer> getActivePlayers() {
|
||||
List<TournamentPlayer> activePlayers = new ArrayList<>();
|
||||
for (TournamentPlayer player: players.values()) {
|
||||
if (!player.getEliminated()) {
|
||||
if (!player.isEliminated()) {
|
||||
activePlayers.add(player);
|
||||
}
|
||||
}
|
||||
|
|
@ -440,17 +440,21 @@ public abstract class TournamentImpl implements Tournament {
|
|||
}
|
||||
|
||||
protected void winners() {
|
||||
// TODO: Generate StateInfo for Swiss pairing (1st, 2nd, ...)
|
||||
for(TournamentPlayer winner: this.getActivePlayers()) {
|
||||
winner.setState(TournamentPlayerState.FINISHED);
|
||||
if (options.getNumberRounds() == 0) { // if no swiss, last active is the winner
|
||||
if (isAbort()) {
|
||||
winner.setStateInfo("Tournament canceled");
|
||||
} else {
|
||||
winner.setStateInfo("Winner");
|
||||
}
|
||||
List<TournamentPlayer> winners = new ArrayList<>();
|
||||
int pointsWinner = Integer.MIN_VALUE;
|
||||
for(TournamentPlayer tournamentPlayer: this.getPlayers()) {
|
||||
if (pointsWinner < tournamentPlayer.getPoints()) {
|
||||
winners.clear();
|
||||
winners.add(tournamentPlayer);
|
||||
pointsWinner = tournamentPlayer.getPoints();
|
||||
} else if (pointsWinner == tournamentPlayer.getPoints()) {
|
||||
winners.add(tournamentPlayer);
|
||||
}
|
||||
}
|
||||
// set winner state for the players with the most points
|
||||
for (TournamentPlayer tournamentPlayer: winners) {
|
||||
tournamentPlayer.setStateInfo("Winner");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
package mage.game.tournament;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.constants.TournamentPlayerState;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.match.MatchPlayer;
|
||||
|
||||
|
|
@ -86,6 +87,18 @@ public class TournamentPairing {
|
|||
}
|
||||
}
|
||||
}
|
||||
public void finishPlayersThatPlayedLastRound() {
|
||||
if (match.hasEnded()) {
|
||||
if (!player1.isEliminated()) {
|
||||
player1.setEliminated();
|
||||
player1.setState(TournamentPlayerState.FINISHED);
|
||||
}
|
||||
if (!player2.isEliminated()) {
|
||||
player2.setEliminated();
|
||||
player2.setState(TournamentPlayerState.FINISHED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void eliminateComputer() {
|
||||
if (!player1.getPlayer().isHuman()) {
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public class TournamentPlayer {
|
|||
this.points = points;
|
||||
}
|
||||
|
||||
public boolean getEliminated() {
|
||||
public boolean isEliminated() {
|
||||
return eliminated;
|
||||
}
|
||||
|
||||
|
|
@ -209,5 +209,11 @@ public class TournamentPlayer {
|
|||
this.setState(TournamentPlayerState.FINISHED);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInTournament() {
|
||||
return !this.getState().equals(TournamentPlayerState.CANCELED)
|
||||
&& !this.getState().equals(TournamentPlayerState.ELIMINATED)
|
||||
&& !this.getState().equals(TournamentPlayerState.FINISHED);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue