use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class SimulationTheory method createClusters.
/**
* Using allied and enemy units create the clusters with them
*/
private void createClusters() {
// Friendly Clusters
List<UnitInfo> myUnits = new ArrayList<>();
for (UnitInfo u : getGs().myArmy) {
if (isArmyUnit(u.unit))
myUnits.add(u);
}
// Bunkers
getGs().DBs.keySet().stream().map(b -> getGs().unitStorage.getAllyUnits().get(b)).forEach(myUnits::add);
// Agents
getGs().agents.values().stream().map(g -> g.unitInfo).forEach(myUnits::add);
MeanShift clustering = new MeanShift(myUnits, radius);
friendly = clustering.run(iterations);
// Enemy Clusters
List<UnitInfo> enemyUnits = new ArrayList<>();
for (UnitInfo u : getGs().unitStorage.getEnemyUnits().values()) {
if (getGs().getStrat().proxy && u.unitType.isWorker() && (Util.isInOurBases(u) && !u.unit.isAttacking()))
continue;
if (u.unitType == UnitType.Zerg_Larva || (u.unitType == UnitType.Zerg_Egg && !u.player.isNeutral()))
continue;
if (Util.isStaticDefense(u.unitType) || u.burrowed || u.unitType == UnitType.Terran_Siege_Tank_Siege_Mode || getGs().frameCount - u.lastVisibleFrame <= 24 * 4)
enemyUnits.add(u);
}
clustering = new MeanShift(enemyUnits, radius);
enemies = clustering.run(iterations);
}
use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class Cluster method updateCentroid.
void updateCentroid() {
if (units.isEmpty())
return;
int size = units.size();
int x = 0;
int y = 0;
for (UnitInfo u : units) {
if (u.visible) {
x += u.position.getX();
y += u.position.getY();
} else {
x += u.lastPosition.getX();
y += u.lastPosition.getY();
}
}
modeX = ((double) x) / size;
modeY = ((double) y) / size;
}
use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class Util method getRangedTarget.
// Credits to SH
public static UnitInfo getRangedTarget(UnitInfo rangedUnit, Set<UnitInfo> enemies, Position pos) {
int bestScore = -999999;
UnitInfo bestTarget = null;
if (rangedUnit == null || enemies.isEmpty())
return null;
if (pos == null)
return getRangedTarget(rangedUnit, enemies);
for (UnitInfo enemy : enemies) {
if (enemy.unit == null || ((enemy.unit.isCloaked() || enemy.burrowed) && !enemy.unit.isDetected()))
continue;
if (enemy.flying && !(rangedUnit.unit instanceof AirAttacker))
continue;
if (!enemy.flying && !(rangedUnit.unit instanceof GroundAttacker))
continue;
int priority = getRangedAttackPriority(rangedUnit, enemy);
int distance = rangedUnit.getDistance(enemy);
double closerToGoal = rangedUnit.getDistance(pos) - enemy.getDistance(pos);
if (distance >= 13 * 32)
continue;
int score = 5 * 32 * priority - distance;
if (closerToGoal > 0)
score += 2 * 32;
boolean isThreat = canAttack(enemy, rangedUnit);
boolean canShootBack = isThreat && distance <= 32 + getAttackRange(enemy, rangedUnit);
if (isThreat) {
if (canShootBack)
score += 7 * 32;
else {
double weaponDist = enemy.player.getUnitStatCalculator().weaponMaxRange(getWeapon(enemy, rangedUnit));
if (distance < weaponDist)
score += 6 * 32;
else
score += 5 * 32;
}
} else if (enemy.unit instanceof MobileUnit && !((MobileUnit) enemy.unit).isMoving()) {
if ((enemy.unit instanceof SiegeTank && ((SiegeTank) enemy.unit).isSieged()) || enemy.currentOrder == Order.Sieging || enemy.currentOrder == Order.Unsieging || (enemy.burrowed)) {
score += 48;
} else
score += 24;
} else if (enemy.unit instanceof MobileUnit && ((MobileUnit) enemy.unit).isBraking())
score += 16;
else if (enemy.speed >= rangedUnit.speed) {
score -= 4 * 32;
}
if (enemy.unitType.getRace() == Race.Protoss && enemy.shields <= 5)
score += 32;
if (enemy.health < enemy.unitType.maxHitPoints())
score += 24;
DamageType damage = getWeapon(rangedUnit, enemy).damageType();
if (damage == DamageType.Explosive) {
if (enemy.unitType.size() == UnitSizeType.Large)
score += 32;
} else if (damage == DamageType.Concussive) {
if (enemy.unitType.size() == UnitSizeType.Small)
score += 32;
else if (enemy.unitType.size() == UnitSizeType.Large)
score -= 32;
}
if (score > bestScore) {
bestScore = score;
bestTarget = enemy;
}
}
return bestScore > 0 ? bestTarget : null;
}
use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class UtilMicro method kiteAway.
// Credits to @Yegers for a better kite method
public static Position kiteAway(final Unit unit, final Set<UnitInfo> enemies) {
try {
if (enemies.isEmpty())
return null;
Position ownPosition = unit.getPosition();
List<MutablePair<Double, Double>> vectors = new ArrayList<>();
// double minDistance = Double.MAX_VALUE;
for (final UnitInfo enemy : enemies) {
final Position enemyPosition = enemy.position;
Position sub = ownPosition.subtract(enemyPosition);
MutablePair<Double, Double> unitV = new MutablePair<>((double) sub.getX(), (double) sub.getY());
// final double distance = enemy.getDistance(unit);
/*if (distance < minDistance) {
minDistance = distance;
}*/
/*unitV.first = unitV.first / distance;
unitV.second = unitV.second / distance;*/
vectors.add(unitV);
}
// minDistance *= 2;
/*for (MutablePair<Double, Double> vector : vectors){
vector.first *= minDistance;
vector.second *= minDistance;
}*/
// return GenericMath.add(ownPosition, GenericMath.multiply(1. / vectors.size(), GenericMath.sumAll(vectors)));
MutablePair<Double, Double> sumAll = Util.sumPosition(vectors);
return Util.cropPosition(Util.sumPosition(ownPosition, new Position((int) (sumAll.first / vectors.size()), (int) (sumAll.second / vectors.size()))));
} catch (Exception e) {
System.err.println("KiteAway Exception");
e.printStackTrace();
return null;
}
}
use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class Util method getClosestUnit.
public static UnitInfo getClosestUnit(UnitInfo unit, Set<UnitInfo> enemies, boolean ignoreAir) {
UnitInfo chosen = null;
double minDist = Double.MAX_VALUE;
for (UnitInfo u : enemies) {
if (!u.unit.exists() || (ignoreAir && u.flying))
continue;
double dist = unit.getDistance(u);
if (chosen == null || dist < minDist) {
minDist = dist;
chosen = u;
}
}
return chosen;
}
Aggregations