Update PopulationGoal.java

Edge case
This commit is contained in:
Dennis Weinberger 2019-03-26 18:59:16 +00:00
parent 3727b4ea88
commit 8e5660a370

View file

@ -20,16 +20,21 @@ public class PopulationGoal extends Goal {
private int populationNeeded = 10; private int populationNeeded = 10;
private int castlesNeeded = 5; private int castlesNeeded = 5;
boolean isDraw;
/** /**
* Creates a new population goal * Creates a new population goal
*/ */
public PopulationGoal() { public PopulationGoal() {
super("Bevölkerung", "Derjenige Spieler gewinnt, der als erstes jeweils 10 Truppen auf 5 Burgen bringt"); super("Bevölkerung", "Derjenige Spieler gewinnt, der als erstes jeweils 10 Truppen auf 5 Burgen bringt");
isDraw = false;
} }
@Override @Override
public boolean isCompleted() { public boolean isCompleted() {
return this.getWinner() != null; // Call getWinner to set isDraw
getWinner();
return isDraw || this.getWinner() != null;
} }
@Override @Override
@ -74,7 +79,17 @@ public class PopulationGoal extends Goal {
} }
}; };
return Collections.max(highPopulationPlayers, comp);
Collections.sort(playerList, comp);
// Edge Case: Mind. Zwei spieler haben die gleiche Anzahl an Burgen
if(playerList.get(0).getNumRegions(game) == playerList.get(1).getNumRegions(game)) {
isDraw = true;
return null;
}
return Collections.max(playerList, comp);
} }
// Ansonsten... gewinnt noch kein spieler. // Ansonsten... gewinnt noch kein spieler.