Search in sources :

Example 16 with UnitInfo

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;
}
Also used : UnitInfo(ecgberht.UnitInfo) ChokePoint(bwem.ChokePoint)

Example 17 with UnitInfo

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;
}
Also used : UnitInfo(ecgberht.UnitInfo) ChokePoint(bwem.ChokePoint)

Example 18 with UnitInfo

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;
}
Also used : ChokePoint(bwem.ChokePoint) Area(bwem.Area) UnitInfo(ecgberht.UnitInfo) Set(java.util.Set) org.openbw.bwapi4j(org.openbw.bwapi4j) Collectors(java.util.stream.Collectors) ConfigManager(ecgberht.ConfigManager) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Ecgberht.getGs(ecgberht.Ecgberht.getGs) org.openbw.bwapi4j.unit(org.openbw.bwapi4j.unit) org.openbw.bwapi4j.type(org.openbw.bwapi4j.type) Base(bwem.Base) BaseManager(ecgberht.BaseManager) UnitInfo(ecgberht.UnitInfo) BaseManager(ecgberht.BaseManager)

Example 19 with UnitInfo

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;
}
Also used : UnitInfo(ecgberht.UnitInfo)

Example 20 with UnitInfo

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);
}
Also used : UnitInfo(ecgberht.UnitInfo) Position(org.openbw.bwapi4j.Position)

Aggregations

UnitInfo (ecgberht.UnitInfo)32 Position (org.openbw.bwapi4j.Position)12 ArrayList (java.util.ArrayList)9 Base (bwem.Base)7 Util (ecgberht.Util.Util)7 Collectors (java.util.stream.Collectors)7 Ecgberht.getGs (ecgberht.Ecgberht.getGs)6 MutablePair (ecgberht.Util.MutablePair)6 List (java.util.List)6 Set (java.util.Set)6 org.openbw.bwapi4j.unit (org.openbw.bwapi4j.unit)6 Area (bwem.Area)5 SimInfo (ecgberht.Simulation.SimInfo)5 Squad (ecgberht.Squad)5 ChokePoint (bwem.ChokePoint)4 TreeSet (java.util.TreeSet)4 org.openbw.bwapi4j.type (org.openbw.bwapi4j.type)4 Cluster (ecgberht.Clustering.Cluster)3 ConfigManager (ecgberht.ConfigManager)3 GameState (ecgberht.GameState)3