* 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;
import java.awt.*;
import java.awt.Component;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.text.DateFormat;
import java.util.ArrayList;
@ -42,7 +43,10 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.CancellationException;
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 mage.client.MageFrame;
import mage.client.chat.ChatPanel;
@ -66,10 +70,10 @@ public class TournamentPanel extends javax.swing.JPanel {
private UUID tournamentId;
private boolean firstInitDone = false;
private Session session;
private TournamentPlayersTableModel playersModel;
private final TournamentPlayersTableModel playersModel;
private TournamentMatchesTableModel matchesModel;
private UpdateTournamentTask updateTask;
private DateFormat df;
private final DateFormat df;
/** Creates new form TournamentPanel */
public TournamentPanel() {
@ -448,7 +452,7 @@ public class TournamentPanel extends javax.swing.JPanel {
}
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];
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
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 boolean watchingAllowed;
@ -582,19 +586,16 @@ class TournamentMatchesTableModel extends AbstractTableModel {
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex != ACTION_COLUMN) {
return false;
}
return true;
return columnIndex == ACTION_COLUMN;
}
}
class UpdateTournamentTask extends SwingWorker<Void, TournamentView> {
private Session session;
private UUID tournamentId;
private TournamentPanel panel;
private final Session session;
private final UUID tournamentId;
private final TournamentPanel panel;
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 {
private static final long serialVersionUID = 1L;
private int roundNum;
private UUID matchId;
private UUID gameId;
private String state;
private String result;
private String players;
private UUID tableId;
private final int roundNum;
private final UUID matchId;
private final UUID gameId;
private final String state;
private final String result;
private final String players;
private final UUID tableId;
TournamentGameView(int roundNum, TournamentPairing pair, Game game) {
this.roundNum = roundNum;

View file

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

View file

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

View file

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

View file

@ -38,12 +38,14 @@ import java.util.UUID;
*/
public class Round {
private int roundNum;
private List<TournamentPairing> pairs = new ArrayList<TournamentPairing>();
private List<TournamentPlayer> playerByes = new ArrayList<TournamentPlayer>();
private final int roundNum;
private final Tournament tournament;
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.tournament = tournament;
}
public void addPairing(TournamentPairing match) {
@ -68,12 +70,18 @@ public class Round {
}
public boolean isRoundOver() {
boolean roundIsOver = true;
for (TournamentPairing pair: pairs) {
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() {

View file

@ -53,6 +53,7 @@ public interface Tournament {
Collection<Round> getRounds();
List<ExpansionSet> getSets();
void updateResults();
void setBoosterInfo(String setInfo);
/**
* 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;
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 mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.cards.decks.Deck;
import mage.constants.TournamentPlayerState;
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.TableEventSource;
import mage.game.match.Match;
import mage.players.Player;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
@ -164,7 +174,7 @@ public abstract class TournamentImpl implements Tournament {
}
protected Round createRoundRandom() {
Round round = new Round(rounds.size() + 1);
Round round = new Round(rounds.size() + 1, this);
rounds.add(round);
List<TournamentPlayer> roundPlayers = getActivePlayers();
while (roundPlayers.size() > 1) {
@ -213,7 +223,11 @@ public abstract class TournamentImpl implements Tournament {
return activePlayers;
}
protected void updateResults() {
/**
*
*/
@Override
public void updateResults() {
for (TournamentPlayer player: players.values()) {
player.setResults("");
player.setPoints(0);
@ -224,27 +238,37 @@ public abstract class TournamentImpl implements Tournament {
UUID player1Id = pair.getPlayer1().getPlayer().getId();
UUID player2Id = pair.getPlayer2().getPlayer().getId();
Match match = pair.getMatch();
StringBuilder sb1 = new StringBuilder(players.get(player1Id).getResults());
StringBuilder sb2 = new StringBuilder(players.get(player2Id).getResults());
sb1.append(pair.getPlayer2().getPlayer().getName());
sb1.append(" (").append(match.getPlayer(player1Id).getWins());
sb1.append("-").append(match.getPlayer(player2Id).getWins()).append(") ");
sb2.append(pair.getPlayer1().getPlayer().getName());
sb2.append(" (").append(match.getPlayer(player2Id).getWins());
sb2.append("-").append(match.getPlayer(player1Id).getWins()).append(") ");
players.get(player1Id).setResults(sb1.toString());
players.get(player2Id).setResults(sb2.toString());
if (match.getPlayer(player1Id).getWins() > match.getPlayer(player2Id).getWins()) {
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);
if (match.isMatchOver()) {
if (round.getRoundNumber() == rounds.size()) {
if (players.get(player1Id).getState().equals(TournamentPlayerState.DUELING)) {
players.get(player1Id).setState(TournamentPlayerState.WAITING);
}
if (players.get(player2Id).getState().equals(TournamentPlayerState.DUELING)) {
players.get(player2Id).setState(TournamentPlayerState.WAITING);
}
}
StringBuilder sb1 = new StringBuilder(players.get(player1Id).getResults());
StringBuilder sb2 = new StringBuilder(players.get(player2Id).getResults());
sb1.append(pair.getPlayer2().getPlayer().getName());
sb1.append(" (").append(match.getPlayer(player1Id).getWins());
sb1.append("-").append(match.getPlayer(player2Id).getWins()).append(") ");
sb2.append(pair.getPlayer1().getPlayer().getName());
sb2.append(" (").append(match.getPlayer(player2Id).getWins());
sb2.append("-").append(match.getPlayer(player1Id).getWins()).append(") ");
players.get(player1Id).setResults(sb1.toString());
players.get(player2Id).setResults(sb2.toString());
if (match.getPlayer(player1Id).getWins() > match.getPlayer(player2Id).getWins()) {
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()) {

View file

@ -38,15 +38,17 @@ import mage.game.match.MatchPlayer;
*/
public class TournamentPairing {
private UUID id = UUID.randomUUID();
private final UUID id = UUID.randomUUID();
private UUID tableId;
private Match match;
private TournamentPlayer player1;
private TournamentPlayer player2;
private final TournamentPlayer player1;
private final TournamentPlayer player2;
private boolean alreadyPublished;
public TournamentPairing(TournamentPlayer player1, TournamentPlayer player2) {
this.player1 = player1;
this.player2 = player2;
this.alreadyPublished = false;
}
public UUID getId() {
@ -98,4 +100,12 @@ public class TournamentPairing {
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() {
Round round = new Round(rounds.size() + 1);
Round round = new Round(rounds.size() + 1, this);
rounds.add(round);
List<TournamentPlayer> roundPlayers = getActivePlayers();
// sort players by tournament points