use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class VultureAgent method retreat.
private void retreat() {
Position CC = getGs().getNearestCC(myUnit.getPosition(), true);
if (CC != null)
UtilMicro.move(unit, CC);
else
UtilMicro.move(unit, getGs().getPlayer().getStartLocation().toPosition());
attackPos = null;
attackUnit = null;
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class VultureAgent method runAgent.
@Override
public boolean runAgent() {
try {
if (!unit.exists() || unitInfo == null)
return true;
if (unit.getHitPoints() <= 20) {
MutablePair<Base, Unit> cc = getGs().mainCC;
if (cc != null && cc.second != null) {
Position ccPos = cc.second.getPosition();
if (getGs().getGame().getBWMap().isValidPosition(ccPos)) {
unit.move(ccPos);
getGs().myArmy.add(unitInfo);
return true;
}
}
unit.move(getGs().getPlayer().getStartLocation().toPosition());
getGs().myArmy.add(unitInfo);
return true;
}
mySim = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.GROUND);
actualFrame = getGs().frameCount;
frameLastOrder = unit.getLastCommandFrame();
if (frameLastOrder == actualFrame)
return false;
// Status old = status;
getNewStatus();
// if (old == status && status != Status.COMBAT && status != Status.ATTACK) return false;
if (status != Status.COMBAT && status != Status.PATROL)
attackUnit = null;
if ((status == Status.ATTACK || status == Status.IDLE) && (unit.isIdle() || unit.getOrder() == Order.PlayerGuard)) {
Position pos = Util.chooseAttackPosition(unit.getPosition(), false);
if (pos == null || !getGs().getGame().getBWMap().isValidPosition(pos))
return false;
UtilMicro.move(unit, pos);
status = Status.ATTACK;
return false;
}
switch(status) {
case ATTACK:
attack();
break;
case COMBAT:
combat();
break;
case KITE:
kite();
break;
case RETREAT:
retreat();
break;
case PATROL:
patrol();
break;
}
return false;
} catch (Exception e) {
System.err.println("Exception VultureAgent");
e.printStackTrace();
}
return false;
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class VultureAgent method getNewStatus.
private void getNewStatus() {
if (mySim.enemies.isEmpty()) {
status = Status.ATTACK;
} else {
boolean meleeOnly = checkOnlyMelees();
if (!meleeOnly && getGs().sim.getSimulation(unitInfo, SimInfo.SimType.GROUND).lose) {
status = Util.isInOurBases(unitInfo) ? Status.KITE : Status.RETREAT;
return;
}
if (status == Status.PATROL && actualFrame - lastPatrolFrame > 5) {
status = Status.COMBAT;
return;
}
int cd = unit.getGroundWeapon().cooldown();
UnitInfo closestAttacker = Util.getClosestUnit(unitInfo, mySim.enemies, true);
if (closestAttacker != null && (cd != 0 || unitInfo.getDistance(closestAttacker) < unitInfo.groundRange * 0.6)) {
status = Status.KITE;
return;
}
if (status == Status.COMBAT || status == Status.ATTACK) {
/*if (attackUnit != null) {
int weaponRange = attackUnit instanceof GroundAttacker ? ((GroundAttacker) attackUnit).getGroundWeaponMaxRange() : 0;
if (weaponRange > type.groundWeapon().maxRange()) return;
}*/
if (cd > 0) {
if (attackUnit != null) {
Position predictedPosition = UtilMicro.predictUnitPosition(attackUnit, 2);
if (predictedPosition != null && getGs().getGame().getBWMap().isValidPosition(predictedPosition)) {
double distPredicted = unit.getDistance(predictedPosition);
double distCurrent = unitInfo.getDistance(attackUnit);
if (distPredicted > distCurrent) {
status = Status.COMBAT;
return;
} else {
attackUnit = null;
attackPos = null;
status = Status.KITE;
return;
}
}
}
if (mySim.enemies.isEmpty()) {
status = Status.ATTACK;
return;
}
status = Status.COMBAT;
return;
}
}
if (status == Status.KITE) {
UnitInfo closest = getUnitToAttack(mySim.enemies);
if (closest != null) {
double dist = unitInfo.getDistance(closest);
double speed = type.topSpeed();
double timeToEnter = 0.0;
if (speed > .00001)
timeToEnter = Math.max(0.0, dist - type.groundWeapon().maxRange()) / speed;
if (timeToEnter >= cd) {
// status = Status.COMBAT;
status = Status.PATROL;
attackUnit = closest;
return;
}
} else {
status = Status.ATTACK;
return;
}
if (cd == 0)
status = Status.COMBAT;
}
}
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class WraithAgent method runAgent.
@Override
public boolean runAgent() {
// TODO improve
try {
if (!unit.exists() || unitInfo == null)
return true;
actualFrame = getGs().frameCount;
frameLastOrder = unit.getLastCommandFrame();
airAttackers.clear();
if (frameLastOrder == actualFrame)
return false;
Position attack = getBestBaseToHarass();
UnitInfo closestThreat = null;
double bestDist = Double.MAX_VALUE;
SimInfo airSim = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.AIR);
airAttackers = airSim.enemies;
for (UnitInfo u : airAttackers) {
double predictedDist = unitInfo.getPredictedDistance(u);
if (predictedDist < bestDist) {
closestThreat = u;
bestDist = predictedDist;
}
}
Set<UnitInfo> mainTargets = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.MIX).enemies;
UnitInfo harassed = chooseHarassTarget(mainTargets);
if (closestThreat != null) {
Weapon myWeapon = closestThreat.flying ? unit.getAirWeapon() : unit.getGroundWeapon();
double hisAirWeaponRange = closestThreat.airRange;
Position kitePos = UtilMicro.kiteAway(unit, new TreeSet<>(Collections.singleton(closestThreat)));
if (myWeapon.maxRange() > hisAirWeaponRange && bestDist > hisAirWeaponRange) {
if (myWeapon.cooldown() != 0) {
if (kitePos != null) {
UtilMicro.move(unit, kitePos);
return false;
}
} else if (harassed != null && unitInfo.getDistance(harassed) <= myWeapon.maxRange()) {
UtilMicro.attack(unitInfo, harassed);
} else
UtilMicro.attack(unitInfo, closestThreat);
return false;
}
if (kitePos != null) {
UtilMicro.move(unit, kitePos);
return false;
}
}
if (harassed != null) {
UtilMicro.attack(unitInfo, harassed);
return false;
}
UnitInfo target = Util.getRangedTarget(unitInfo, mainTargets);
if (target != null) {
UtilMicro.attack(unitInfo, target);
return false;
}
if (attack != null) {
if (attack.getDistance(myUnit.getPosition()) >= 32 * 5)
UtilMicro.move(unit, attack);
else
UtilMicro.attack(unit, attack);
return false;
}
return false;
} catch (Exception e) {
System.err.println("Exception WraithAgent");
e.printStackTrace();
}
return false;
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class CheckResourcesBuilding method execute.
@Override
public State execute() {
try {
if (gameState.chosenPosition == null) {
gameState.chosenWorker = null;
// ((GameState) gameState).chosenToBuild = UnitType.None;
return State.FAILURE;
}
MutablePair<Integer, Integer> cash = gameState.getCash();
Worker chosen = gameState.chosenWorker;
TilePosition start = chosen.getTilePosition();
TilePosition end = gameState.chosenPosition;
Position realEnd = Util.getUnitCenterPosition(end.toPosition(), gameState.chosenToBuild);
if (gameState.getStrat().name.equals("ProxyBBS") && gameState.chosenToBuild == UnitType.Terran_Barracks) {
if (Util.countBuildingAll(UnitType.Terran_Barracks) < 1) {
if (cash.first + gameState.getMineralsWhenReaching(start, realEnd.toTilePosition()) >= (gameState.chosenToBuild.mineralPrice() * 2 + 40 + gameState.deltaCash.first) && cash.second >= (gameState.chosenToBuild.gasPrice() * 2) + gameState.deltaCash.second) {
return State.SUCCESS;
}
} else if (Util.countBuildingAll(UnitType.Terran_Barracks) == 1)
return State.SUCCESS;
return State.FAILURE;
} else if (cash.first + gameState.getMineralsWhenReaching(start, realEnd.toTilePosition()) >= (gameState.chosenToBuild.mineralPrice() + gameState.deltaCash.first) && cash.second >= (gameState.chosenToBuild.gasPrice()) + gameState.deltaCash.second) {
return State.SUCCESS;
}
gameState.chosenWorker = null;
gameState.chosenPosition = null;
// ((GameState) gameState).chosenToBuild = UnitType.None;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
Aggregations