* Fixed a bug that if opponent left tournament during a match, get got points for that mathc if he won more games (fixes #1310).

This commit is contained in:
LevelX2 2015-10-11 11:19:19 +02:00
parent f4b667650c
commit 673cd6b38a

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.game.tournament; package mage.game.tournament;
import java.util.ArrayList; import java.util.ArrayList;
@ -209,7 +208,7 @@ public abstract class TournamentImpl implements Tournament {
} }
protected void playRound(Round round) { protected void playRound(Round round) {
for (TournamentPairing pair: round.getPairs()) { for (TournamentPairing pair : round.getPairs()) {
playMatch(pair); playMatch(pair);
} }
updateResults(); // show points from byes updateResults(); // show points from byes
@ -227,7 +226,7 @@ public abstract class TournamentImpl implements Tournament {
protected List<TournamentPlayer> getActivePlayers() { protected List<TournamentPlayer> getActivePlayers() {
List<TournamentPlayer> activePlayers = new ArrayList<>(); List<TournamentPlayer> activePlayers = new ArrayList<>();
for (TournamentPlayer player: players.values()) { for (TournamentPlayer player : players.values()) {
if (!player.isEliminated()) { if (!player.isEliminated()) {
activePlayers.add(player); activePlayers.add(player);
} }
@ -240,13 +239,13 @@ public abstract class TournamentImpl implements Tournament {
*/ */
@Override @Override
public void updateResults() { public void updateResults() {
for (TournamentPlayer player: players.values()) { for (TournamentPlayer player : players.values()) {
player.setResults(""); player.setResults("");
player.setPoints(0); player.setPoints(0);
player.setStateInfo(""); player.setStateInfo("");
} }
for (Round round: rounds) { for (Round round : rounds) {
for (TournamentPairing pair: round.getPairs()) { for (TournamentPairing pair : round.getPairs()) {
Match match = pair.getMatch(); Match match = pair.getMatch();
if (match != null && match.hasEnded()) { if (match != null && match.hasEnded()) {
TournamentPlayer tp1 = pair.getPlayer1(); TournamentPlayer tp1 = pair.getPlayer1();
@ -276,9 +275,9 @@ public abstract class TournamentImpl implements Tournament {
tp2.setResults(addRoundResult(round.getRoundNumber(), pair, tp2, tp1)); tp2.setResults(addRoundResult(round.getRoundNumber(), pair, tp2, tp1));
// Add points // Add points
if (mp2.hasQuit() || mp1.getWins() > mp2.getWins()) { if ((!mp1.hasQuit() && mp1.getWins() > mp2.getWins()) || mp2.hasQuit()) {
tp1.setPoints(tp1.getPoints() + 3); tp1.setPoints(tp1.getPoints() + 3);
} else if (mp1.hasQuit() || mp1.getWins() < mp2.getWins()) { } else if ((!mp2.hasQuit() && mp1.getWins() < mp2.getWins()) || mp1.hasQuit()) {
tp2.setPoints(tp2.getPoints() + 3); tp2.setPoints(tp2.getPoints() + 3);
} else { } else {
tp1.setPoints(tp1.getPoints() + 1); tp1.setPoints(tp1.getPoints() + 1);
@ -307,14 +306,14 @@ public abstract class TournamentImpl implements Tournament {
matchResult.append(p2.getPlayer().getName()); matchResult.append(p2.getPlayer().getName());
matchResult.append(" [").append(mp1.getWins()); matchResult.append(" [").append(mp1.getWins());
if (mp1.hasQuit()) { if (mp1.hasQuit()) {
matchResult.append(mp1.getPlayer().hasIdleTimeout()? "I" :(mp1.getPlayer().hasTimerTimeout()?"T":"Q")); matchResult.append(mp1.getPlayer().hasIdleTimeout() ? "I" : (mp1.getPlayer().hasTimerTimeout() ? "T" : "Q"));
} }
if (match.getDraws() > 0) { if (match.getDraws() > 0) {
matchResult.append("-").append(match.getDraws()); matchResult.append("-").append(match.getDraws());
} }
matchResult.append("-").append(mp2.getWins()); matchResult.append("-").append(mp2.getWins());
if (mp2.hasQuit()) { if (mp2.hasQuit()) {
matchResult.append(mp2.getPlayer().hasIdleTimeout()? "I" :(mp2.getPlayer().hasTimerTimeout()?"T":"Q")); matchResult.append(mp2.getPlayer().hasIdleTimeout() ? "I" : (mp2.getPlayer().hasTimerTimeout() ? "T" : "Q"));
} }
matchResult.append("] "); matchResult.append("] ");
return matchResult.toString(); return matchResult.toString();
@ -322,7 +321,7 @@ public abstract class TournamentImpl implements Tournament {
@Override @Override
public boolean isDoneConstructing() { public boolean isDoneConstructing() {
for (TournamentPlayer player: this.players.values()) { for (TournamentPlayer player : this.players.values()) {
if (!player.isDoneConstructing()) { if (!player.isDoneConstructing()) {
return false; return false;
} }
@ -332,7 +331,7 @@ public abstract class TournamentImpl implements Tournament {
@Override @Override
public boolean allJoined() { public boolean allJoined() {
for (TournamentPlayer player: this.players.values()) { for (TournamentPlayer player : this.players.values()) {
if (!player.isJoined()) { if (!player.isJoined()) {
return false; return false;
} }
@ -358,22 +357,21 @@ public abstract class TournamentImpl implements Tournament {
public void construct() { public void construct() {
tableEventSource.fireTableEvent(EventType.CONSTRUCT); tableEventSource.fireTableEvent(EventType.CONSTRUCT);
if (!isAbort()) { if (!isAbort()) {
for (final TournamentPlayer player: players.values()) { for (final TournamentPlayer player : players.values()) {
player.setConstructing(); player.setConstructing();
new Thread( new Thread(
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
player.getPlayer().construct(TournamentImpl.this, player.getDeck()); player.getPlayer().construct(TournamentImpl.this, player.getDeck());
}
} }
}
).start(); ).start();
} }
// add autosubmit trigger // add autosubmit trigger
synchronized (this) {
synchronized(this) {
while (!isDoneConstructing()) { while (!isDoneConstructing()) {
try { try {
this.wait(); this.wait();
@ -387,7 +385,7 @@ public abstract class TournamentImpl implements Tournament {
} }
protected void openBoosters() { protected void openBoosters() {
for (TournamentPlayer player: this.players.values()) { for (TournamentPlayer player : this.players.values()) {
player.setDeck(new Deck()); player.setDeck(new Deck());
if (options.getLimitedOptions().getDraftCube() != null) { if (options.getLimitedOptions().getDraftCube() != null) {
DraftCube cube = options.getLimitedOptions().getDraftCube(); DraftCube cube = options.getLimitedOptions().getDraftCube();
@ -395,7 +393,7 @@ public abstract class TournamentImpl implements Tournament {
player.getDeck().getSideboard().addAll(cube.createBooster()); player.getDeck().getSideboard().addAll(cube.createBooster());
} }
} else { } else {
for (ExpansionSet set: sets) { for (ExpansionSet set : sets) {
player.getDeck().getSideboard().addAll(set.createBooster()); player.getDeck().getSideboard().addAll(set.createBooster());
} }
} }
@ -406,7 +404,7 @@ public abstract class TournamentImpl implements Tournament {
public void resetBufferedCards() { public void resetBufferedCards() {
HashSet<ExpansionSet> setsDone = new HashSet<>(); HashSet<ExpansionSet> setsDone = new HashSet<>();
for(ExpansionSet set: sets) { for (ExpansionSet set : sets) {
if (!setsDone.contains(set)) { if (!setsDone.contains(set)) {
set.removeSavedCards(); set.removeSavedCards();
setsDone.add(set); setsDone.add(set);
@ -454,7 +452,7 @@ public abstract class TournamentImpl implements Tournament {
protected void winners() { protected void winners() {
List<TournamentPlayer> winners = new ArrayList<>(); List<TournamentPlayer> winners = new ArrayList<>();
int pointsWinner = 1; // with less than 1 point you can't win int pointsWinner = 1; // with less than 1 point you can't win
for(TournamentPlayer tournamentPlayer: this.getPlayers()) { for (TournamentPlayer tournamentPlayer : this.getPlayers()) {
if (pointsWinner < tournamentPlayer.getPoints()) { if (pointsWinner < tournamentPlayer.getPoints()) {
winners.clear(); winners.clear();
winners.add(tournamentPlayer); winners.add(tournamentPlayer);
@ -464,14 +462,14 @@ public abstract class TournamentImpl implements Tournament {
} }
} }
// set winner state for the players with the most points > 0 // set winner state for the players with the most points > 0
for (TournamentPlayer tournamentPlayer: winners) { for (TournamentPlayer tournamentPlayer : winners) {
tournamentPlayer.setStateInfo("Winner"); tournamentPlayer.setStateInfo("Winner");
} }
} }
@Override @Override
public void cleanUpOnTournamentEnd() { public void cleanUpOnTournamentEnd() {
for(TournamentPlayer tournamentPlayer: players.values()) { for (TournamentPlayer tournamentPlayer : players.values()) {
tournamentPlayer.CleanUpOnTournamentEnd(); tournamentPlayer.CleanUpOnTournamentEnd();
} }
} }
@ -509,7 +507,6 @@ public abstract class TournamentImpl implements Tournament {
this.startTime = new Date(); this.startTime = new Date();
} }
@Override @Override
public void setStepStartTime(Date stepStartTime) { public void setStepStartTime(Date stepStartTime) {
this.stepStartTime = stepStartTime; this.stepStartTime = stepStartTime;