WIP GraphAlgorithm

This commit is contained in:
joachimschmidt557 2019-03-22 18:49:27 +01:00
parent 07e292a5e1
commit 9f62d1bccc
4 changed files with 116 additions and 3 deletions

View file

@ -31,7 +31,7 @@ public class GameConstants {
public static final Goal GAME_GOALS[] = {
new ConquerGoal(),
new TimeGoal(),
// TODO: Add more Goals
new CaptureTheFlagGoal(),
};
public static final Class<?> PLAYER_TYPES[] = {

View file

@ -12,6 +12,8 @@ import game.map.Castle;
public class CaptureTheFlagGoal extends Goal {
final static boolean DEBUG = true;
final static int ROUND_FOR_DISTRIBUTION = 2;
final static int MIN_ROUND_FOR_WIN = 2;
final static int NUM_FLAG_CASTLES = 4;
@ -26,17 +28,25 @@ public class CaptureTheFlagGoal extends Goal {
public CaptureTheFlagGoal() {
super("Capture the flag", "Derjenige Spieler gewinnt, der zuerst"
+ " alle " + NUM_FLAG_CASTLES + " Flaggen-Schlösser erobert.");
flagCastles = new ArrayList<Castle>();
}
@Override
public boolean isCompleted() {
if (DEBUG)
System.out.println("Checking is completed");
Game game = this.getGame();
// As this function is called every round,
// let's check if we can set the flag castles
if (flagCastles == null && game.getRound() > ROUND_FOR_DISTRIBUTION) {
if (flagCastles.isEmpty() && game.getRound() >= ROUND_FOR_DISTRIBUTION) {
if (DEBUG)
System.out.println("Distributing");
distributeFlagCastles();
return false;
}
return this.getWinner() != null;
@ -95,6 +105,9 @@ public class CaptureTheFlagGoal extends Goal {
for (int i = 0; i < players.size(); i++) {
if (DEBUG)
System.out.println("Distributing for " + players.get(i).getName());
int playersLeft = players.size() - i;
int numCastlesForPlayer = numCastlesToDistribute / playersLeft;
@ -136,6 +149,9 @@ public class CaptureTheFlagGoal extends Goal {
}
if (DEBUG)
System.out.println(nums);
return nums.stream().map(x -> castles.get(x)).collect(Collectors.toList());