* Tournament handling - Finished pairing are updated now to tournament players list immediately.

This commit is contained in:
LevelX2 2014-02-17 00:41:40 +01:00
parent ce967ee88c
commit 4e5de2b7f9
10 changed files with 120 additions and 76 deletions

View file

@ -34,7 +34,8 @@
package mage.client.tournament; package mage.client.tournament;
import java.awt.*; import java.awt.Component;
import java.awt.Rectangle;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -42,7 +43,10 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import javax.swing.*; import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.chat.ChatPanel; import mage.client.chat.ChatPanel;
@ -66,10 +70,10 @@ public class TournamentPanel extends javax.swing.JPanel {
private UUID tournamentId; private UUID tournamentId;
private boolean firstInitDone = false; private boolean firstInitDone = false;
private Session session; private Session session;
private TournamentPlayersTableModel playersModel; private final TournamentPlayersTableModel playersModel;
private TournamentMatchesTableModel matchesModel; private TournamentMatchesTableModel matchesModel;
private UpdateTournamentTask updateTask; private UpdateTournamentTask updateTask;
private DateFormat df; private final DateFormat df;
/** Creates new form TournamentPanel */ /** Creates new form TournamentPanel */
public TournamentPanel() { public TournamentPanel() {
@ -448,7 +452,7 @@ public class TournamentPanel extends javax.swing.JPanel {
} }
class TournamentPlayersTableModel extends AbstractTableModel { class TournamentPlayersTableModel extends AbstractTableModel {
private String[] columnNames = new String[]{"Player Name", "State", "Points", "Results"}; private final String[] columnNames = new String[]{"Player Name", "State", "Points", "Results"};
private TournamentPlayerView[] players = new TournamentPlayerView[0]; private TournamentPlayerView[] players = new TournamentPlayerView[0];
public void loadData(TournamentView tournament) { public void loadData(TournamentView tournament) {
@ -508,7 +512,7 @@ class TournamentMatchesTableModel extends AbstractTableModel {
public static final int ACTION_COLUMN = 4; // column the action is located public static final int ACTION_COLUMN = 4; // column the action is located
private String[] columnNames = new String[]{"Round Number", "Players", "State", "Result", "Action"}; private final String[] columnNames = new String[]{"Round Number", "Players", "State", "Result", "Action"};
private TournamentGameView[] games = new TournamentGameView[0]; private TournamentGameView[] games = new TournamentGameView[0];
private boolean watchingAllowed; private boolean watchingAllowed;
@ -582,19 +586,16 @@ class TournamentMatchesTableModel extends AbstractTableModel {
@Override @Override
public boolean isCellEditable(int rowIndex, int columnIndex) { public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex != ACTION_COLUMN) { return columnIndex == ACTION_COLUMN;
return false;
}
return true;
} }
} }
class UpdateTournamentTask extends SwingWorker<Void, TournamentView> { class UpdateTournamentTask extends SwingWorker<Void, TournamentView> {
private Session session; private final Session session;
private UUID tournamentId; private final UUID tournamentId;
private TournamentPanel panel; private final TournamentPanel panel;
private static final Logger logger = Logger.getLogger(UpdateTournamentTask.class); private static final Logger logger = Logger.getLogger(UpdateTournamentTask.class);

View file

@ -41,13 +41,13 @@ import mage.game.tournament.TournamentPairing;
public class TournamentGameView implements Serializable { public class TournamentGameView implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int roundNum; private final int roundNum;
private UUID matchId; private final UUID matchId;
private UUID gameId; private final UUID gameId;
private String state; private final String state;
private String result; private final String result;
private String players; private final String players;
private UUID tableId; private final UUID tableId;
TournamentGameView(int roundNum, TournamentPairing pair, Game game) { TournamentGameView(int roundNum, TournamentPairing pair, Game game) {
this.roundNum = roundNum; this.roundNum = roundNum;

View file

@ -39,11 +39,11 @@ import mage.game.tournament.TournamentPlayer;
public class TournamentPlayerView implements Serializable { public class TournamentPlayerView implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String name; private final String name;
private String state; private final String state;
private String results; private final String results;
private int points; private final int points;
private boolean quit; private final boolean quit;
TournamentPlayerView(TournamentPlayer player) { TournamentPlayerView(TournamentPlayer player) {
this.name = player.getPlayer().getName(); this.name = player.getPlayer().getName();

View file

@ -38,14 +38,14 @@ import mage.game.tournament.TournamentType;
public class TournamentTypeView implements Serializable { public class TournamentTypeView implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String name; private final String name;
private int minPlayers; private final int minPlayers;
private int maxPlayers; private final int maxPlayers;
private int numBoosters; private final int numBoosters;
private boolean draft; private final boolean draft;
private boolean limited; private final boolean limited;
private boolean cubeBooster; private final boolean cubeBooster;
private boolean elimination; private final boolean elimination;
public TournamentTypeView(TournamentType tournamentType) { public TournamentTypeView(TournamentType tournamentType) {

View file

@ -43,16 +43,16 @@ import mage.game.tournament.TournamentPlayer;
public class TournamentView implements Serializable { public class TournamentView implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String tournamentName; private final String tournamentName;
private String tournamentType; private final String tournamentType;
private Date startTime; private final Date startTime;
private Date endTime; private final Date endTime;
private boolean watchingAllowed; private final boolean watchingAllowed;
private List<RoundView> rounds = new ArrayList<RoundView>(); private final List<RoundView> rounds = new ArrayList<RoundView>();
private List<TournamentPlayerView> players = new ArrayList<TournamentPlayerView>(); private final List<TournamentPlayerView> players = new ArrayList<TournamentPlayerView>();
public TournamentView(Tournament tournament) { public TournamentView(Tournament tournament) {

View file

@ -38,12 +38,14 @@ import java.util.UUID;
*/ */
public class Round { public class Round {
private int roundNum; private final int roundNum;
private List<TournamentPairing> pairs = new ArrayList<TournamentPairing>(); private final Tournament tournament;
private List<TournamentPlayer> playerByes = new ArrayList<TournamentPlayer>(); private final List<TournamentPairing> pairs = new ArrayList<TournamentPairing>();
private final List<TournamentPlayer> playerByes = new ArrayList<TournamentPlayer>();
public Round(int roundNum) { public Round(int roundNum, Tournament tournament) {
this.roundNum = roundNum; this.roundNum = roundNum;
this.tournament = tournament;
} }
public void addPairing(TournamentPairing match) { public void addPairing(TournamentPairing match) {
@ -68,12 +70,18 @@ public class Round {
} }
public boolean isRoundOver() { public boolean isRoundOver() {
boolean roundIsOver = true;
for (TournamentPairing pair: pairs) { for (TournamentPairing pair: pairs) {
if (!pair.getMatch().isMatchOver()) { if (!pair.getMatch().isMatchOver()) {
return false; roundIsOver = false;
} else {
if (!pair.isAlreadyPublished()) {
tournament.updateResults();
pair.setAlreadyPublished(true);
}
} }
} }
return true; return roundIsOver;
} }
public List<TournamentPlayer> getPlayerByes() { public List<TournamentPlayer> getPlayerByes() {

View file

@ -53,6 +53,7 @@ public interface Tournament {
Collection<Round> getRounds(); Collection<Round> getRounds();
List<ExpansionSet> getSets(); List<ExpansionSet> getSets();
void updateResults();
void setBoosterInfo(String setInfo); void setBoosterInfo(String setInfo);
/** /**
* Gives back a String that shows the included sets (e.g. "3xRTR" or "1xDGM 1xGTC 1xRTR") or cube name * Gives back a String that shows the included sets (e.g. "3xRTR" or "1xDGM 1xGTC 1xRTR") or cube name

View file

@ -28,20 +28,30 @@
package mage.game.tournament; package mage.game.tournament;
import java.util.*; import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.ExpansionSet; import mage.cards.ExpansionSet;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.constants.TournamentPlayerState; import mage.constants.TournamentPlayerState;
import mage.game.draft.DraftCube; import mage.game.draft.DraftCube;
import mage.game.events.*; import mage.game.events.Listener;
import mage.game.events.PlayerQueryEvent;
import mage.game.events.PlayerQueryEventSource;
import mage.game.events.TableEvent;
import mage.game.events.TableEvent.EventType; import mage.game.events.TableEvent.EventType;
import mage.game.events.TableEventSource;
import mage.game.match.Match; import mage.game.match.Match;
import mage.players.Player; import mage.players.Player;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -164,7 +174,7 @@ public abstract class TournamentImpl implements Tournament {
} }
protected Round createRoundRandom() { protected Round createRoundRandom() {
Round round = new Round(rounds.size() + 1); Round round = new Round(rounds.size() + 1, this);
rounds.add(round); rounds.add(round);
List<TournamentPlayer> roundPlayers = getActivePlayers(); List<TournamentPlayer> roundPlayers = getActivePlayers();
while (roundPlayers.size() > 1) { while (roundPlayers.size() > 1) {
@ -213,7 +223,11 @@ public abstract class TournamentImpl implements Tournament {
return activePlayers; return activePlayers;
} }
protected void updateResults() { /**
*
*/
@Override
public void updateResults() {
for (TournamentPlayer player: players.values()) { for (TournamentPlayer player: players.values()) {
player.setResults(""); player.setResults("");
player.setPoints(0); player.setPoints(0);
@ -224,27 +238,37 @@ public abstract class TournamentImpl implements Tournament {
UUID player1Id = pair.getPlayer1().getPlayer().getId(); UUID player1Id = pair.getPlayer1().getPlayer().getId();
UUID player2Id = pair.getPlayer2().getPlayer().getId(); UUID player2Id = pair.getPlayer2().getPlayer().getId();
Match match = pair.getMatch(); Match match = pair.getMatch();
StringBuilder sb1 = new StringBuilder(players.get(player1Id).getResults()); if (match.isMatchOver()) {
StringBuilder sb2 = new StringBuilder(players.get(player2Id).getResults()); if (round.getRoundNumber() == rounds.size()) {
sb1.append(pair.getPlayer2().getPlayer().getName()); if (players.get(player1Id).getState().equals(TournamentPlayerState.DUELING)) {
sb1.append(" (").append(match.getPlayer(player1Id).getWins()); players.get(player1Id).setState(TournamentPlayerState.WAITING);
sb1.append("-").append(match.getPlayer(player2Id).getWins()).append(") "); }
sb2.append(pair.getPlayer1().getPlayer().getName()); if (players.get(player2Id).getState().equals(TournamentPlayerState.DUELING)) {
sb2.append(" (").append(match.getPlayer(player2Id).getWins()); players.get(player2Id).setState(TournamentPlayerState.WAITING);
sb2.append("-").append(match.getPlayer(player1Id).getWins()).append(") "); }
players.get(player1Id).setResults(sb1.toString()); }
players.get(player2Id).setResults(sb2.toString()); StringBuilder sb1 = new StringBuilder(players.get(player1Id).getResults());
if (match.getPlayer(player1Id).getWins() > match.getPlayer(player2Id).getWins()) { StringBuilder sb2 = new StringBuilder(players.get(player2Id).getResults());
int points = players.get(player1Id).getPoints(); sb1.append(pair.getPlayer2().getPlayer().getName());
players.get(player1Id).setPoints(points + 3); sb1.append(" (").append(match.getPlayer(player1Id).getWins());
} else if (match.getPlayer(player1Id).getWins() < match.getPlayer(player2Id).getWins()) { sb1.append("-").append(match.getPlayer(player2Id).getWins()).append(") ");
int points = players.get(player2Id).getPoints(); sb2.append(pair.getPlayer1().getPlayer().getName());
players.get(player2Id).setPoints(points + 3); sb2.append(" (").append(match.getPlayer(player2Id).getWins());
} else { sb2.append("-").append(match.getPlayer(player1Id).getWins()).append(") ");
int points = players.get(player1Id).getPoints(); players.get(player1Id).setResults(sb1.toString());
players.get(player1Id).setPoints(points + 1); players.get(player2Id).setResults(sb2.toString());
points = players.get(player2Id).getPoints(); if (match.getPlayer(player1Id).getWins() > match.getPlayer(player2Id).getWins()) {
players.get(player2Id).setPoints(points + 1); int points = players.get(player1Id).getPoints();
players.get(player1Id).setPoints(points + 3);
} else if (match.getPlayer(player1Id).getWins() < match.getPlayer(player2Id).getWins()) {
int points = players.get(player2Id).getPoints();
players.get(player2Id).setPoints(points + 3);
} else {
int points = players.get(player1Id).getPoints();
players.get(player1Id).setPoints(points + 1);
points = players.get(player2Id).getPoints();
players.get(player2Id).setPoints(points + 1);
}
} }
} }
for (TournamentPlayer tournamentPlayer : round.getPlayerByes()) { for (TournamentPlayer tournamentPlayer : round.getPlayerByes()) {

View file

@ -38,15 +38,17 @@ import mage.game.match.MatchPlayer;
*/ */
public class TournamentPairing { public class TournamentPairing {
private UUID id = UUID.randomUUID(); private final UUID id = UUID.randomUUID();
private UUID tableId; private UUID tableId;
private Match match; private Match match;
private TournamentPlayer player1; private final TournamentPlayer player1;
private TournamentPlayer player2; private final TournamentPlayer player2;
private boolean alreadyPublished;
public TournamentPairing(TournamentPlayer player1, TournamentPlayer player2) { public TournamentPairing(TournamentPlayer player1, TournamentPlayer player2) {
this.player1 = player1; this.player1 = player1;
this.player2 = player2; this.player2 = player2;
this.alreadyPublished = false;
} }
public UUID getId() { public UUID getId() {
@ -98,4 +100,12 @@ public class TournamentPairing {
this.tableId = tableId; this.tableId = tableId;
} }
public boolean isAlreadyPublished() {
return alreadyPublished;
}
public void setAlreadyPublished(boolean alreadyPublished) {
this.alreadyPublished = alreadyPublished;
}
} }

View file

@ -62,7 +62,7 @@ public abstract class TournamentSwiss extends TournamentImpl {
} }
protected Round createRoundSwiss() { protected Round createRoundSwiss() {
Round round = new Round(rounds.size() + 1); Round round = new Round(rounds.size() + 1, this);
rounds.add(round); rounds.add(round);
List<TournamentPlayer> roundPlayers = getActivePlayers(); List<TournamentPlayer> roundPlayers = getActivePlayers();
// sort players by tournament points // sort players by tournament points