StrongAI improvement

This commit is contained in:
Jonas Suess 2019-03-26 21:27:56 +01:00
parent a26f17a56e
commit b5b987db39

View file

@ -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<Castle> g = game.getMap().getGraph();
// The castles that can send troops
List<Castle> 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<Castle> 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<Castle> g = game.getMap().getGraph();
// Castles that can attack
List<Castle> 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();
}
}
distributeTroops(game);
boolean shouldAttack = false;
do {