Search in sources :

Example 11 with UnitInfo

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);
}
Also used : MeanShift(ecgberht.Clustering.MeanShift) Cluster(ecgberht.Clustering.Cluster) Util(ecgberht.Util.Util) UnitInfo(ecgberht.UnitInfo) Simulator(org.bk.ass.sim.Simulator) BW(org.openbw.bwapi4j.BW) ToIntFunction(java.util.function.ToIntFunction) Agent(org.bk.ass.sim.Agent) Set(java.util.Set) BWAPI4JAgentFactory(org.bk.ass.sim.BWAPI4JAgentFactory) IntelligenceAgency(ecgberht.IntelligenceAgency) Collectors(java.util.stream.Collectors) ConfigManager(ecgberht.ConfigManager) ArrayList(java.util.ArrayList) List(java.util.List) Ecgberht.getGs(ecgberht.Ecgberht.getGs) org.openbw.bwapi4j.unit(org.openbw.bwapi4j.unit) MutablePair(ecgberht.Util.MutablePair) org.openbw.bwapi4j.type(org.openbw.bwapi4j.type) Evaluator(org.bk.ass.sim.Evaluator) Position(org.openbw.bwapi4j.Position) UnitInfo(ecgberht.UnitInfo) ArrayList(java.util.ArrayList) MeanShift(ecgberht.Clustering.MeanShift)

Example 12 with UnitInfo

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

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

Example 14 with UnitInfo

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

Example 15 with UnitInfo

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

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