diff --git a/pom.xml b/pom.xml
index 3e4302b..6b4cb47 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,8 +7,10 @@
jar
UTF-8
- 15
- 15
+
+ 14
+ 14
+
16
0.0.6
@@ -32,4 +34,4 @@
${javafx.version}
-
\ No newline at end of file
+
diff --git a/src/main/java/lol/client/Client.java b/src/main/java/lol/client/Client.java
index 7577b2d..464aaac 100644
--- a/src/main/java/lol/client/Client.java
+++ b/src/main/java/lol/client/Client.java
@@ -15,7 +15,9 @@ public static void main(String[] args) {
ASCIIBattlefieldBuilder battlefieldBuilder = new ASCIIBattlefieldBuilder();
Battlefield battlefield = battlefieldBuilder.build();
Arena arena = new Arena(battlefield);
- RandomAI ai = new RandomAI(arena, battlefield);
+
+ RandomAISpell ai = new RandomAISpell(arena, battlefield);
+
new Client(ai, arena, battlefield).run();
}
diff --git a/src/main/java/lol/client/ai/RandomAI.java b/src/main/java/lol/client/ai/RandomAI.java
index b7e1329..55f8cad 100644
--- a/src/main/java/lol/client/ai/RandomAI.java
+++ b/src/main/java/lol/client/ai/RandomAI.java
@@ -1,4 +1,4 @@
-package lol.client.ai;
+ package lol.client.ai;
import java.util.*;
import lol.game.*;
diff --git a/src/main/java/lol/client/ai/RandomAISpell.java b/src/main/java/lol/client/ai/RandomAISpell.java
new file mode 100644
index 0000000..3a90d7e
--- /dev/null
+++ b/src/main/java/lol/client/ai/RandomAISpell.java
@@ -0,0 +1,50 @@
+package lol.client.ai;
+
+import java.util.*;
+import lol.game.*;
+import lol.game.action.*;
+
+public class RandomAISpell extends RandomAITower {
+
+ public RandomAISpell(Arena arena, Battlefield battlefield) {
+ super(arena, battlefield);
+ }
+
+ public Turn turn() {
+ Turn turn = new Turn();
+ //try to attack with a spell first
+ tryDoubleDamageOnNexus(turn);
+ // Try to attack the Nexus
+ tryAttackNexus(turn);
+
+ tryDoubleDamageOnTower(turn);
+ // Try to attack a Tower.
+ // Add a move action in case we could not attack the Nexus.
+ tryAttackTower(turn);
+ tryMove(turn);
+ return turn;
+ }
+
+ protected void tryDoubleDamageOnNexus(Turn turn) {
+ arena.teamOf(teamID).forEachChampion((champion, id) ->
+ battlefield.visitAdjacent(champion.x(), champion.y(), champion.attackRange(), new TileVisitor(){
+ public void visitNexus(Nexus nexus) {
+ if(nexus.teamOfNexus() != teamID) {
+ turn.registerAction(new DoubleDamage(teamID, id, nexus.x(), nexus.y()));
+ }
+ }
+ }));
+ }
+
+ protected void tryDoubleDamageOnTower(Turn turn) {
+ arena.teamOf(teamID).forEachChampion((champion, id) ->
+ battlefield.visitAdjacent(champion.x(), champion.y(), champion.attackRange(), new TileVisitor(){
+ public void visitTower(Tower tower) {
+ if(tower.teamOfTower() != teamID) {
+ turn.registerAction(new DoubleDamage(teamID, id, tower.x(), tower.y()));
+ }
+ }
+ }));
+ }
+
+}
diff --git a/src/main/java/lol/client/ai/RandomAITower.java b/src/main/java/lol/client/ai/RandomAITower.java
index ba5ac93..9da4cc4 100644
--- a/src/main/java/lol/client/ai/RandomAITower.java
+++ b/src/main/java/lol/client/ai/RandomAITower.java
@@ -21,7 +21,7 @@ public Turn turn() {
return turn;
}
- private void tryAttackTower(Turn turn) {
+ protected void tryAttackTower(Turn turn) {
arena.teamOf(teamID).forEachChampion((champion, id) ->
traversal.visitAdjacent(champion.x(), champion.y(), champion.attackRange(), new TileVisitor(){
public void visitTower(Tower tower) {
diff --git a/src/main/java/lol/game/Arena.java b/src/main/java/lol/game/Arena.java
index 8435bb3..b3ffa54 100644
--- a/src/main/java/lol/game/Arena.java
+++ b/src/main/java/lol/game/Arena.java
@@ -76,6 +76,19 @@ public void visitAttack(int teamID, int championID, int x, int y) {
}
}
+ public void visitDoubleDamage(int teamID, int championID, int x, int y) {
+ if(phase == Phase.GAME) {
+ if(!championsWhoActed.contains(championID)) {
+ if(teams.get(teamID).championDoubleDamage(championID, x, y)) {
+ championsWhoActed.add(championID);
+ }
+ }
+ }
+ else {
+ System.out.println("Team " + teamID + " tried to move a champion outside a GAME phase.");
+ }
+ }
+
public void visitChampionSelect(int teamID, String championName) {
if(phase == Phase.CHAMP_SELECT) {
try {
@@ -92,6 +105,7 @@ public void visitChampionSelect(int teamID, String championName) {
}
}
+
public void applyTurn(Turn turn) {
turn.accept(new ApplyAction());
}
diff --git a/src/main/java/lol/game/Attacker.java b/src/main/java/lol/game/Attacker.java
index 60503ce..fee5d47 100644
--- a/src/main/java/lol/game/Attacker.java
+++ b/src/main/java/lol/game/Attacker.java
@@ -3,8 +3,8 @@
// class is abstract, since it should never be used alone
public abstract class Attacker extends Destructible {
- private int rangeOfAttack;
- private int damages;
+ protected int rangeOfAttack;
+ protected int damages;
public Attacker(int hp, int rangeOfAttack, int damages) {
super(hp);
diff --git a/src/main/java/lol/game/Battlefield.java b/src/main/java/lol/game/Battlefield.java
index e1a36db..3766564 100644
--- a/src/main/java/lol/game/Battlefield.java
+++ b/src/main/java/lol/game/Battlefield.java
@@ -142,6 +142,7 @@ public boolean moveTo(Destructible d, int x, int y) {
public void destroy(Destructible d) {
battlefield[d.y()][d.x()] = Optional.empty();
+
}
// Visit a tile using the visitor.
diff --git a/src/main/java/lol/game/Champion.java b/src/main/java/lol/game/Champion.java
index a6d5d71..cbebe36 100644
--- a/src/main/java/lol/game/Champion.java
+++ b/src/main/java/lol/game/Champion.java
@@ -48,6 +48,44 @@ public boolean canWalkTo(int toX, int toY) {
return distanceFrom(toX, toY) <= speed;
}
+
+ //for speed spells
+ public boolean canWalkToEnhanced(int toX, int toY, int factor) {
+ return distanceFrom(toX, toY) <= speed*factor;
+ }
+
+ //for healing spells
+ public void heal(int hp) {
+ super.currentHP = Math.min(super.currentHP + hp, super.initialHP);
+ }
+
+ public boolean canAttack(int toX, int toY) {
+ return distanceFrom(toX, toY) <= rangeOfAttack;
+ }
+
+ //for changing the range of attack in spells
+ public boolean canAttackEnhanced(int toX, int toY, int factor) {
+ return distanceFrom(toX, toY) <= rangeOfAttack*factor;
+ }
+
+ public boolean attack(Destructible d) {
+ if(canAttack(d.x(), d.y())) {
+ d.hit(damages);
+ return true;
+ }
+ return false;
+ }
+
+ //for damage spells
+ public boolean attackEnhanced(Destructible d, int factor) {
+ if(canAttack(d.x(), d.y())) {
+ d.hit(damages*factor);
+ return true;
+ }
+ return false;
+ }
+
+
@Override public String toString() {
return name() + " (speed: " + this.speed + " - damages: " + this.damages() + ")";
}
diff --git a/src/main/java/lol/game/Destructible.java b/src/main/java/lol/game/Destructible.java
index d72b696..5b652e9 100644
--- a/src/main/java/lol/game/Destructible.java
+++ b/src/main/java/lol/game/Destructible.java
@@ -2,10 +2,10 @@
// The coordinates are the position of the destructible in the battlefield.
public abstract class Destructible {
- private int xCoord;
- private int yCoord;
- private int initialHP;
- private int currentHP;
+ protected int xCoord;
+ protected int yCoord;
+ protected int initialHP;
+ protected int currentHP;
public Destructible(int hp) {
this.initialHP = hp;
diff --git a/src/main/java/lol/game/Team.java b/src/main/java/lol/game/Team.java
index 245b8f4..736f569 100644
--- a/src/main/java/lol/game/Team.java
+++ b/src/main/java/lol/game/Team.java
@@ -78,6 +78,23 @@ public boolean championAttack(int championID, int x, int y) {
return attacked[0];
}
+ public boolean championDoubleDamage(int championID,int x, int y){
+ Champion champion = champions.get(championID);
+ boolean[] attacked = {false};
+ battlefield.visit(x, y, new TileVisitor(){
+ @Override public void visitDestructible(Destructible d) {
+ attacked[0] = champion.attackEnhanced(d,2);
+ if(d.isDead()){
+ battlefield.destroy(d);
+ }
+ }
+ });
+ if(!attacked[0]) {
+ System.out.println("Invalid attack target of champion " + champion.name());
+ }
+ return attacked[0];
+ }
+
public void makeSpawnTurn(final Turn turn) {
int[] champIdx = {0};
traversal.visitAdjacent(nexus.x(), nexus.y(), 1, new TileVisitor(){
diff --git a/src/main/java/lol/game/action/ActionVisitor.java b/src/main/java/lol/game/action/ActionVisitor.java
index 8f847da..93472c6 100644
--- a/src/main/java/lol/game/action/ActionVisitor.java
+++ b/src/main/java/lol/game/action/ActionVisitor.java
@@ -5,4 +5,5 @@ public interface ActionVisitor {
public void visitMove(int teamID, int championID, int x, int y);
public void visitAttack(int teamID, int championID, int x, int y);
public void visitChampionSelect(int teamID, String championName);
+ public void visitDoubleDamage(int teamID, int championID, int x, int y);
}
\ No newline at end of file
diff --git a/src/main/java/lol/game/action/DoubleDamage.java b/src/main/java/lol/game/action/DoubleDamage.java
new file mode 100644
index 0000000..b6dc660
--- /dev/null
+++ b/src/main/java/lol/game/action/DoubleDamage.java
@@ -0,0 +1,19 @@
+package lol.game.action;
+
+import lol.game.*;
+import java.io.Serializable;
+
+public class DoubleDamage extends Spell implements Serializable {
+ protected int x;
+ protected int y;
+
+ public DoubleDamage(int teamID, int championID, int x, int y) {
+ super(teamID,championID);
+ this.x = x;
+ this.y = y;
+ }
+
+ public void accept(ActionVisitor visitor) {
+ visitor.visitDoubleDamage(teamID, championID, x, y);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/lol/game/action/Spell.java b/src/main/java/lol/game/action/Spell.java
new file mode 100644
index 0000000..067fddb
--- /dev/null
+++ b/src/main/java/lol/game/action/Spell.java
@@ -0,0 +1,13 @@
+package lol.game.action;
+
+import lol.game.*;
+import java.io.Serializable;
+
+public abstract class Spell extends Action implements Serializable {
+ protected int championID;
+
+ public Spell(int teamID, int championID) {
+ super(teamID);
+ this.championID=championID;
+ }
+}
\ No newline at end of file