Skip to content

Commit

Permalink
Merge pull request #39 from Jabbo16/develop
Browse files Browse the repository at this point in the history
SSCAIT 2018
  • Loading branch information
Jabbo16 authored Dec 20, 2018
2 parents 7f1368c + 37e404c commit a990580
Show file tree
Hide file tree
Showing 146 changed files with 3,767 additions and 3,306 deletions.
Binary file modified BWAPI4JBridge.dll
Binary file not shown.
Binary file modified lib/BWAPI4J-javadoc.jar
Binary file not shown.
Binary file modified lib/BWAPI4J-sources.jar
Binary file not shown.
Binary file modified lib/BWAPI4J.jar
Binary file not shown.
Binary file added lib/ass-1.0-SNAPSHOT.jar
Binary file not shown.
40 changes: 0 additions & 40 deletions src/ecgberht/Agents/Agent.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package ecgberht.Agents;

import ecgberht.Util.Util;
import org.openbw.bwapi4j.Position;
import org.openbw.bwapi4j.unit.MobileUnit;
import org.openbw.bwapi4j.unit.PlayerUnit;
import org.openbw.bwapi4j.unit.Unit;

import java.util.Set;
import java.util.TreeSet;

import static ecgberht.Ecgberht.getGs;

public abstract class Agent {

public Unit myUnit;
Expand All @@ -19,8 +11,6 @@ public abstract class Agent {
Unit attackUnit = null;
int frameLastOrder = 0;
int actualFrame = 0;
Set<Unit> closeEnemies = new TreeSet<>();
Set<Unit> mainTargets = new TreeSet<>();

public String statusToString() {
if (status == Status.ATTACK) return "Attack";
Expand All @@ -32,36 +22,6 @@ public String statusToString() {
return "None";
}

Position selectNewAttack() {
Position p = Util.chooseAttackPosition(myUnit.getPosition(), false);
if (p != null && getGs().getGame().getBWMap().isValidPosition(p)) return p;
if (getGs().enemyMainBase != null) return getGs().enemyMainBase.getLocation().toPosition();
return null;
}

Unit getUnitToAttack(Unit myUnit, Set<Unit> enemies) {
Unit chosen = null;
double distB = Double.MAX_VALUE;
for (Unit u : enemies) {
if (u.getType().isFlyer() || ((PlayerUnit) u).isCloaked()) continue;
double distA = Util.broodWarDistance(myUnit.getPosition(), u.getPosition());
if (chosen == null || distA < distB) {
chosen = u;
distB = distA;
}
}
if (chosen != null) return chosen;
return null;
}

protected void retreat() {
Position CC = getGs().getNearestCC(myUnit.getPosition());
if (CC != null) ((MobileUnit) myUnit).move(CC);
else ((MobileUnit) myUnit).move(getGs().getPlayer().getStartLocation().toPosition());
attackPos = null;
attackUnit = null;
}

public abstract boolean runAgent();

enum Status {ATTACK, KITE, COMBAT, IDLE, RETREAT, PATROL}
Expand Down
3 changes: 1 addition & 2 deletions src/ecgberht/Agents/DropShipAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ private void picking() {
private void idle() {
}

@Override
protected void retreat() {
Position CC = getGs().getNearestCC(myUnit.getPosition());
Position CC = getGs().getNearestCC(myUnit.getPosition(), false);
if (CC != null) target = CC;
else target = getGs().getPlayer().getStartLocation().toPosition();
((MobileUnit) myUnit).move(target);
Expand Down
118 changes: 82 additions & 36 deletions src/ecgberht/Agents/VesselAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ecgberht.Simulation.SimInfo;
import ecgberht.Squad;
import ecgberht.Util.Util;
import ecgberht.Util.UtilMicro;
import org.openbw.bwapi4j.Position;
import org.openbw.bwapi4j.type.Order;
import org.openbw.bwapi4j.type.Race;
Expand Down Expand Up @@ -58,6 +59,32 @@ public boolean runAgent() {
retreat();
return false;
}
switch (status) {
case DMATRIX:
if (unit.getEnergy() <= TechType.Defensive_Matrix.energyCost()) {
getGs().wizard.irradiatedUnits.remove(unit);
status = Status.IDLE;
target = null;
oldTarget = null;
}
break;
case IRRADIATE:
if (unit.getEnergy() <= TechType.Irradiate.energyCost()) {
getGs().wizard.irradiatedUnits.remove(unit);
status = Status.IDLE;
target = null;
oldTarget = null;
}
break;
case EMP:
if (unit.getEnergy() <= TechType.EMP_Shockwave.energyCost()) {
getGs().wizard.EMPedUnits.remove(unit);
status = Status.IDLE;
target = null;
oldTarget = null;
}
break;
}
center = follow.getSquadCenter();
getNewStatus();
switch (status) {
Expand Down Expand Up @@ -93,11 +120,8 @@ public boolean runAgent() {

private void hover() {
Position attack = follow.attack;
if (attack == null) return;
if (!getGs().getGame().getBWMap().isValidPosition(attack)) return;
Position target = unit.getOrderTargetPosition();
if (target != null && !target.equals(attack)) unit.move(attack);
else if (target == null) unit.move(attack);
if (attack == null || !getGs().getGame().getBWMap().isValidPosition(attack)) return;
UtilMicro.move(unit, attack);
}

private Squad chooseVesselSquad() {
Expand All @@ -115,51 +139,63 @@ private Squad chooseVesselSquad() {
}

private void emp() {
if (oldTarget != null && !oldTarget.exists()) oldTarget = null;
if (target != null && !target.exists()) target = null;
if (oldTarget != null && oldTarget.equals(target)) return;
if (target != null && target.exists() && unit.getOrder() != Order.CastEMPShockwave) {
unit.empShockWave(target.getPosition());
if (unit.getOrder() == Order.CastEMPShockwave) {
if (target != null && oldTarget != null && !target.equals(oldTarget)) {
UtilMicro.emp(unit, target.getPosition());
getGs().wizard.addEMPed(unit, (PlayerUnit) target);
oldTarget = target;
}
} else if (target != null && target.exists() && unit.getOrder() != Order.CastEMPShockwave) {
UtilMicro.emp(unit, target.getPosition());
getGs().wizard.addEMPed(unit, (PlayerUnit) target);
oldTarget = target;
} else target = oldTarget = null;
}
if (oldTarget != null && (!oldTarget.exists() || ((PlayerUnit) oldTarget).getShields() <= 1)) oldTarget = null;
if (target != null && (!target.exists() || ((PlayerUnit) target).getShields() <= 1)) target = null;
}

private void irradiate() {
if (oldTarget != null && !oldTarget.exists()) oldTarget = null;
if (target != null && !target.exists()) target = null;
if (oldTarget != null && oldTarget.equals(target)) return;
if (target != null && target.exists() && unit.getOrder() != Order.CastIrradiate) {
unit.irradiate((PlayerUnit) target);
if (unit.getOrder() == Order.CastIrradiate) {
if (target != null && oldTarget != null && !target.equals(oldTarget)) {
UtilMicro.irradiate(unit, (PlayerUnit) target);
getGs().wizard.addIrradiated(unit, (PlayerUnit) target);
oldTarget = target;
}
} else if (target != null && target.exists() && unit.getOrder() != Order.CastIrradiate) {
UtilMicro.irradiate(unit, (PlayerUnit) target);
getGs().wizard.addIrradiated(unit, (PlayerUnit) target);
oldTarget = target;
} else target = oldTarget = null;
}
if (oldTarget != null && (!oldTarget.exists() || ((PlayerUnit) oldTarget).isIrradiated())) oldTarget = null;
if (target != null && (!target.exists() || ((PlayerUnit) target).isIrradiated())) target = null;
}

private void dMatrix() {
if (oldTarget != null && !oldTarget.exists()) oldTarget = null;
if (target != null && !target.exists()) target = null;
if (oldTarget != null && oldTarget.equals(target)) return;
if (target != null && target.exists() && unit.getOrder() != Order.CastDefensiveMatrix) {
unit.empShockWave(target.getPosition());
if (unit.getOrder() == Order.CastDefensiveMatrix) {
if (target != null && oldTarget != null && !target.equals(oldTarget)) {
UtilMicro.defenseMatrix(unit, (MobileUnit) target);
getGs().wizard.addDefenseMatrixed(unit, (MobileUnit) target);
oldTarget = target;
}
} else if (target != null && target.exists() && unit.getOrder() != Order.CastDefensiveMatrix) {
UtilMicro.defenseMatrix(unit, (MobileUnit) target);
getGs().wizard.addDefenseMatrixed(unit, (MobileUnit) target);
oldTarget = target;
} else target = oldTarget = null;
}
if (oldTarget != null && (!oldTarget.exists() || ((MobileUnit) oldTarget).isDefenseMatrixed()))
oldTarget = null;
if (target != null && (!target.exists() || ((MobileUnit) target).isDefenseMatrixed())) target = null;
}

private void kite() {
Position kite = getGs().kiteAway(unit, airAttackers);
Position kite = UtilMicro.kiteAway(unit, airAttackers);
if (kite == null || !getGs().getGame().getBWMap().isValidPosition(kite)) return;
Position target = unit.getOrderTargetPosition();
if (target != null && !target.equals(kite)) unit.move(kite);
if (target == null) unit.move(kite);
UtilMicro.move(unit, kite);
}

private void followSquad() {
if (!getGs().getGame().getBWMap().isValidPosition(center)) return;
Position target = unit.getOrderTargetPosition();
if (target != null && !target.equals(center)) unit.move(center);
if (target == null) unit.move(center);
if (center == null || !getGs().getGame().getBWMap().isValidPosition(center)) return;
UtilMicro.move(unit, center);
}

private void getNewStatus() {
Expand Down Expand Up @@ -198,19 +234,19 @@ private void getNewStatus() {
if (u.equals(close) || !(close instanceof Organic)) continue;
if (close.getDistance(u) <= 32) closeUnits++;
}
if (u instanceof Lurker) score = ((Lurker) u).isBurrowed() ? 16 : 14;
if (u instanceof Lurker) score = ((Lurker) u).isBurrowed() ? 20 : 18; // Kill it with fire!!
else if (u instanceof Mutalisk) score = 8;
else if (u instanceof Hydralisk) score = 6;
else if (u instanceof Zergling) score = 3;
score *= ((double) ((PlayerUnit) u).getHitPoints()) / (double) (((PlayerUnit) u).maxHitPoints()); //Prefer healthy units
double multiplier = u instanceof SiegeTank ? 3.5 : u instanceof Lurker ? 2 : 0.75;
double multiplier = u instanceof SiegeTank ? 3.75 : u instanceof Lurker ? 2.5 : u instanceof Mutalisk ? 2 : 1;
score += multiplier * closeUnits;
if (chosen == null || score > maxScore) {
chosen = (PlayerUnit) u;
maxScore = score;
}
}
if (maxScore >= 5.5) {
if (maxScore >= 5) {
status = Status.IRRADIATE;
target = chosen;
return;
Expand Down Expand Up @@ -263,21 +299,22 @@ private void getNewStatus() {
int score = 1;
if (!((PlayerUnit) u).isUnderAttack() || ((MobileUnit) u).isDefenseMatrixed()) continue;
if (u instanceof Mechanical) score = 8;
if (u instanceof Marine) score = 3;
if (u instanceof Marine || u instanceof Firebat) score = 3;
if (u instanceof SCV || u instanceof Medic) score = 1;
score *= ((PlayerUnit) u).maxHitPoints() / ((PlayerUnit) u).getHitPoints();
if (chosen == null || score > maxScore) {
chosen = (PlayerUnit) u;
maxScore = score;
}
}
if (maxScore > 2) {
if (maxScore >= 2) {
status = Status.DMATRIX;
target = chosen;
return;
}
}
}
if ((status == Status.IRRADIATE || status == Status.DMATRIX || status == Status.EMP) && target != null) return;
if (!mySimAir.enemies.isEmpty()) {
if (unit.isUnderAttack() || chasenByScourge || sporeColony) status = Status.KITE;
else if (Util.broodWarDistance(unit.getPosition(), center) >= 100) status = Status.FOLLOW;
Expand All @@ -287,6 +324,15 @@ private void getNewStatus() {
else status = Status.HOVER;
}

private void retreat() {
Position CC = getGs().getNearestCC(myUnit.getPosition(), true);
if (CC != null) ((MobileUnit) myUnit).move(CC);
else ((MobileUnit) myUnit).move(getGs().getPlayer().getStartLocation().toPosition());
attackPos = null;
attackUnit = null;
}


@Override
public boolean equals(Object o) {
if (o == this.unit) return true;
Expand Down
Loading

0 comments on commit a990580

Please sign in to comment.