Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>

<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>

<javafx.version>16</javafx.version>
<javafx.maven.plugin.version>0.0.6</javafx.maven.plugin.version>
</properties>
Expand All @@ -32,4 +34,4 @@
<version>${javafx.version}</version>
</dependency>
</dependencies>
</project>
</project>
4 changes: 3 additions & 1 deletion src/main/java/lol/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/lol/client/ai/RandomAI.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lol.client.ai;
package lol.client.ai;

import java.util.*;
import lol.game.*;
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/lol/client/ai/RandomAISpell.java
Original file line number Diff line number Diff line change
@@ -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()));
}
}
}));
}

}
2 changes: 1 addition & 1 deletion src/main/java/lol/client/ai/RandomAITower.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/lol/game/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -92,6 +105,7 @@ public void visitChampionSelect(int teamID, String championName) {
}
}


public void applyTurn(Turn turn) {
turn.accept(new ApplyAction());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/lol/game/Attacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/lol/game/Battlefield.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/lol/game/Champion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create a private attack(Destructible d, int damage) method that is used by both attackEnhanced and attack (to avoid code duplication).

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() + ")";
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/lol/game/Destructible.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/lol/game/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
1 change: 1 addition & 0 deletions src/main/java/lol/game/action/ActionVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
19 changes: 19 additions & 0 deletions src/main/java/lol/game/action/DoubleDamage.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
13 changes: 13 additions & 0 deletions src/main/java/lol/game/action/Spell.java
Original file line number Diff line number Diff line change
@@ -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;
}
}