StrongAI improvement
This commit is contained in:
parent
a26f17a56e
commit
b5b987db39
1 changed files with 9 additions and 10 deletions
|
|
@ -22,7 +22,7 @@ public class StrongAI extends AI {
|
||||||
|
|
||||||
// These values were determined mostly by trial-and-error
|
// 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_F2 = 1.0; // Number of adjacent enemy castles
|
||||||
private static double UTILITY_F3 = 3.0; // Number of connected edges
|
private static double UTILITY_F3 = 3.0; // Number of connected edges
|
||||||
private static double UTILITY_F4 = -10.0; // Is surrounded by opponents castles
|
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 static int scare_threshold = 5; // Number of troops to use scare joker
|
||||||
|
|
||||||
private boolean playedJoker1 = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public StrongAI(String name, Color color) {
|
public StrongAI(String name, Color color) {
|
||||||
super(name, color);
|
super(name, color);
|
||||||
|
|
@ -191,6 +188,7 @@ public class StrongAI extends AI {
|
||||||
|
|
||||||
while(availableCastles.size() > 0 && getRemainingTroops() > 0) {
|
while(availableCastles.size() > 0 && getRemainingTroops() > 0) {
|
||||||
sleep(1000);
|
sleep(1000);
|
||||||
|
// Find best castle
|
||||||
Castle best = availableCastles.get(0);
|
Castle best = availableCastles.get(0);
|
||||||
double bestScore = 0;
|
double bestScore = 0;
|
||||||
double score = 0;
|
double score = 0;
|
||||||
|
|
@ -239,12 +237,13 @@ public class StrongAI extends AI {
|
||||||
*/
|
*/
|
||||||
private void reinforceCastles(Game game) {
|
private void reinforceCastles(Game game) {
|
||||||
Graph<Castle> g = game.getMap().getGraph();
|
Graph<Castle> g = game.getMap().getGraph();
|
||||||
|
// The castles that can send troops
|
||||||
List<Castle> distributors = game.getMap().getCastles().stream()
|
List<Castle> distributors = game.getMap().getCastles().stream()
|
||||||
.filter(x->x.getOwner() == this)
|
.filter(x->x.getOwner() == this)
|
||||||
.filter(x->x.getTroopCount() > 1)
|
.filter(x->x.getTroopCount() > 1)
|
||||||
.filter(x->isBorder(g, x) == false)
|
.filter(x->isBorder(g, x) == false)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
// The castles that can receive troops
|
||||||
List<Castle> receivers = game.getMap().getCastles().stream()
|
List<Castle> receivers = game.getMap().getCastles().stream()
|
||||||
.filter(x->x.getOwner() == this)
|
.filter(x->x.getOwner() == this)
|
||||||
.filter(x->isBorder(g, x) == true)
|
.filter(x->isBorder(g, x) == true)
|
||||||
|
|
@ -282,6 +281,7 @@ public class StrongAI extends AI {
|
||||||
*/
|
*/
|
||||||
private boolean attackCastles(Game game) throws InterruptedException {
|
private boolean attackCastles(Game game) throws InterruptedException {
|
||||||
Graph<Castle> g = game.getMap().getGraph();
|
Graph<Castle> g = game.getMap().getGraph();
|
||||||
|
// Castles that can attack
|
||||||
List<Castle> attackers = g.getAllValues().stream()
|
List<Castle> attackers = g.getAllValues().stream()
|
||||||
.filter(x->x.getOwner() == this)
|
.filter(x->x.getOwner() == this)
|
||||||
.filter(x->isBorder(g, x))
|
.filter(x->isBorder(g, x))
|
||||||
|
|
@ -298,6 +298,7 @@ public class StrongAI extends AI {
|
||||||
if(targets.isEmpty())
|
if(targets.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Find best target to attack
|
||||||
Castle best = targets.get(0);
|
Castle best = targets.get(0);
|
||||||
double bestScore = 0;
|
double bestScore = 0;
|
||||||
for(Castle t : targets) {
|
for(Castle t : targets) {
|
||||||
|
|
@ -333,11 +334,9 @@ public class StrongAI extends AI {
|
||||||
if(game.getRound() == 1) {
|
if(game.getRound() == 1) {
|
||||||
chooseInitialCastles(game);
|
chooseInitialCastles(game);
|
||||||
}else {
|
}else {
|
||||||
if(!playedJoker1) {
|
if(getJokers()[0] == JokerTypes.ADD_TROOPS) {
|
||||||
if(getJokers()[0] == JokerTypes.ADD_TROOPS) {
|
playTroopsJoker();
|
||||||
playTroopsJoker();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
distributeTroops(game);
|
distributeTroops(game);
|
||||||
boolean shouldAttack = false;
|
boolean shouldAttack = false;
|
||||||
do {
|
do {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue