From b5b987db39888a197a4e8b13b1e911d819f043ef Mon Sep 17 00:00:00 2001 From: Jonas Suess Date: Tue, 26 Mar 2019 21:27:56 +0100 Subject: [PATCH] StrongAI improvement --- .../src/game/players/StrongAI.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Projektgruppe_175/src/game/players/StrongAI.java b/Projektgruppe_175/src/game/players/StrongAI.java index dd5dd67..583c2de 100644 --- a/Projektgruppe_175/src/game/players/StrongAI.java +++ b/Projektgruppe_175/src/game/players/StrongAI.java @@ -22,7 +22,7 @@ public class StrongAI extends AI { // These values were determined mostly by trial-and-error - private static double UTILITY_F1 = 4.0; // Number of adjacent friendly castles + private static double UTILITY_F1 = 5.0; // Number of adjacent friendly castles private static double UTILITY_F2 = 1.0; // Number of adjacent enemy castles private static double UTILITY_F3 = 3.0; // Number of connected edges private static double UTILITY_F4 = -10.0; // Is surrounded by opponents castles @@ -42,9 +42,6 @@ public class StrongAI extends AI { private static int scare_threshold = 5; // Number of troops to use scare joker - private boolean playedJoker1 = false; - - public StrongAI(String name, Color color) { super(name, color); @@ -191,6 +188,7 @@ public class StrongAI extends AI { while(availableCastles.size() > 0 && getRemainingTroops() > 0) { sleep(1000); + // Find best castle Castle best = availableCastles.get(0); double bestScore = 0; double score = 0; @@ -239,12 +237,13 @@ public class StrongAI extends AI { */ private void reinforceCastles(Game game) { Graph g = game.getMap().getGraph(); + // The castles that can send troops List distributors = game.getMap().getCastles().stream() .filter(x->x.getOwner() == this) .filter(x->x.getTroopCount() > 1) .filter(x->isBorder(g, x) == false) .collect(Collectors.toList()); - + // The castles that can receive troops List receivers = game.getMap().getCastles().stream() .filter(x->x.getOwner() == this) .filter(x->isBorder(g, x) == true) @@ -282,6 +281,7 @@ public class StrongAI extends AI { */ private boolean attackCastles(Game game) throws InterruptedException { Graph g = game.getMap().getGraph(); + // Castles that can attack List attackers = g.getAllValues().stream() .filter(x->x.getOwner() == this) .filter(x->isBorder(g, x)) @@ -298,6 +298,7 @@ public class StrongAI extends AI { if(targets.isEmpty()) continue; + // Find best target to attack Castle best = targets.get(0); double bestScore = 0; for(Castle t : targets) { @@ -333,11 +334,9 @@ public class StrongAI extends AI { if(game.getRound() == 1) { chooseInitialCastles(game); }else { - if(!playedJoker1) { - if(getJokers()[0] == JokerTypes.ADD_TROOPS) { - playTroopsJoker(); - } - } + if(getJokers()[0] == JokerTypes.ADD_TROOPS) { + playTroopsJoker(); + } distributeTroops(game); boolean shouldAttack = false; do {