Taught strong AI to use jokers

This commit is contained in:
Jonas Suess 2019-03-26 19:26:09 +01:00
parent 58ed71eb91
commit 551cb5ac90

View file

@ -15,6 +15,7 @@ import game.Player;
import game.map.Castle; import game.map.Castle;
import game.map.PathFinding; import game.map.PathFinding;
import gui.AttackThread; import gui.AttackThread;
import gui.components.JokerPanel.JokerTypes;
import gui.components.MapPanel.Action; import gui.components.MapPanel.Action;
public class StrongAI extends AI { public class StrongAI extends AI {
@ -39,8 +40,10 @@ public class StrongAI extends AI {
private static double EVAL_OWN = 3.0; // Weight of own utilities private static double EVAL_OWN = 3.0; // Weight of own utilities
private static double EVAL_OPP = -10.0; // Weight of opponents utilities private static double EVAL_OPP = -10.0; // Weight of opponents utilities
private static int scare_threshold = 5; // Number of troops to use scare joker
private boolean playedJoker1 = false; private boolean playedJoker1 = false;
private boolean playedJoker2 = false;
public StrongAI(String name, Color color) { public StrongAI(String name, Color color) {
@ -306,6 +309,11 @@ public class StrongAI extends AI {
} }
// Attack, if the chance of taking the castle is more useful than not attacking // Attack, if the chance of taking the castle is more useful than not attacking
if(bestScore > evaluateState(game, g, this, Optional.empty()) && a.getTroopCount() > best.getTroopCount()) { if(bestScore > evaluateState(game, g, this, Optional.empty()) && a.getTroopCount() > best.getTroopCount()) {
if(best.getTroopCount() > scare_threshold || getBatch(g, best.getOwner(), best, new ArrayList<>()).size() == 1) {
if(getJokers()[1] == JokerTypes.SCARE_TROOPS) {
playScareJoker(best, game);
}
}
AttackThread attackThread = game.startAttack(a, best, a.getTroopCount()); AttackThread attackThread = game.startAttack(a, best, a.getTroopCount());
if(fastForward) if(fastForward)
attackThread.fastForward(); attackThread.fastForward();
@ -320,29 +328,16 @@ public class StrongAI extends AI {
return false; return false;
} }
/**
* Play some jokers
* @param game the current game
*/
private void playJokers(Game game) {
if(!playedJoker1) {
if(this.getCastles(game).size() <= game.getMap().getCastles().size()/2) {
playedJoker1 = true;
System.out.println("StrongAI played joker 1.");
this.addTroops(5);
}
}
if(!playedJoker2) {
// TODO: Play joker 2
}
}
@Override @Override
protected void actions(Game game) throws InterruptedException { protected void actions(Game game) throws InterruptedException {
if(game.getRound() == 1) { if(game.getRound() == 1) {
chooseInitialCastles(game); chooseInitialCastles(game);
}else { }else {
playJokers(game); if(!playedJoker1) {
if(getJokers()[0] == JokerTypes.ADD_TROOPS) {
playTroopsJoker();
}
}
distributeTroops(game); distributeTroops(game);
boolean shouldAttack = false; boolean shouldAttack = false;
do { do {