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) {
int bestScore = -999999;
UnitInfo bestTarget = null;
if (rangedUnit == null || enemies.isEmpty())
return null;
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);
if (distance >= 13 * 32)
continue;
int score = 5 * 32 * priority - distance;
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 Util method getTankTarget.
public static UnitInfo getTankTarget(UnitInfo t, Set<UnitInfo> tankTargets) {
UnitInfo chosenTarget = null;
int highPriority = 0;
int closestDist = Integer.MAX_VALUE;
for (UnitInfo target : tankTargets) {
if (!target.visible)
continue;
int distance = t.getDistance(target);
int priority = getRangedAttackPriority(t, target);
if (isStaticDefense(t))
priority *= 1.2;
if (chosenTarget == null || (priority > highPriority) || (priority == highPriority && distance < closestDist)) {
closestDist = distance;
highPriority = priority;
chosenTarget = target;
}
}
return chosenTarget;
}
use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class Util method chooseAttackPosition.
public static Position chooseAttackPosition(Position p, boolean flying) {
Position chosen = null;
double maxScore = 0;
for (UnitInfo b : getGs().unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
double influence = getScoreAttackPosition((Building) b.unit);
// double score = influence / (2 * getEuclideanDist(p, b.pos.toPosition()));
double score = influence / (2.5 * (flying ? b.lastPosition.getDistance(p) : Util.getGroundDistance(p, b.lastPosition)));
if (score > maxScore) {
chosen = b.lastPosition;
maxScore = score;
}
}
if (chosen == null && getGs().enemyMainBase == null) {
for (BaseManager.Garrison g : getGs().baseManager.getScoutingBasesSorted()) {
if (!flying && g.island)
continue;
return g.tile.toPosition();
}
}
return chosen;
}
use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class SimulationTheory method simulateHarass.
// TODO improve and search for harasser SimInfo
public boolean simulateHarass(Unit harasser, Set<UnitInfo> enemies, int frames) {
simulator.reset();
simulator.addAgentA(factory.of((PlayerUnit) harasser));
for (UnitInfo u : enemies) simulator.addAgentB(factory.of(u.unit));
int preSimFriendlyUnitCount = simulator.getAgentsA().size();
simulator.simulate(frames);
int postSimFriendlyUnitCount = simulator.getAgentsA().size();
int myLosses = preSimFriendlyUnitCount - postSimFriendlyUnitCount;
return myLosses <= 0;
}
use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class SimulationTheory method drawCluster.
/**
* Draws a cluster on the screen
*
* @param c The cluster to be drawn
* @param ally If true draws the cluster using green lines otherwise red lines
* @param id Cluster identifier
*/
private void drawCluster(Cluster c, boolean ally, int id) {
Color color = Color.RED;
if (ally)
color = Color.GREEN;
Position centroid = new Position((int) c.modeX, (int) c.modeY);
getGs().getGame().getMapDrawer().drawCircleMap(centroid, 4, color, true);
// getGs().getGame().getMapDrawer().drawTextMap(centroid.add(new Position(0, 5)), ColorUtil.formatText(Integer.toString(id), ColorUtil.White));
for (UnitInfo u : c.units) getGs().getGame().getMapDrawer().drawLineMap(u.lastPosition, centroid, color);
}
Aggregations