Search in sources :

Example 6 with UnitInfo

use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.

the class ChooseScout method execute.

@Override
public State execute() {
    try {
        if (gameState.getStrat().name.equals("PlasmaWraithHell")) {
            for (Squad s : gameState.sqManager.squads.values()) {
                for (UnitInfo u : s.members) {
                    if (u.unit instanceof Wraith) {
                        gameState.chosenScout = (MobileUnit) u.unit;
                        s.members.remove(u);
                        return State.SUCCESS;
                    }
                }
            }
        }
        if (!gameState.workerIdle.isEmpty()) {
            Worker chosen = gameState.workerIdle.iterator().next();
            gameState.chosenScout = chosen;
            gameState.workerIdle.remove(chosen);
        }
        if (gameState.chosenScout == null) {
            for (Worker u : gameState.workerMining.keySet()) {
                if (!u.isCarryingMinerals()) {
                    gameState.chosenScout = u;
                    MineralPatch mineral = gameState.workerMining.get(u);
                    if (gameState.mineralsAssigned.containsKey(mineral)) {
                        gameState.mining--;
                        gameState.mineralsAssigned.put(mineral, gameState.mineralsAssigned.get(mineral) - 1);
                    }
                    gameState.workerMining.remove(u);
                    break;
                }
            }
        }
        if (gameState.chosenScout != null)
            return State.SUCCESS;
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : UnitInfo(ecgberht.UnitInfo) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) Worker(org.openbw.bwapi4j.unit.Worker) Squad(ecgberht.Squad) Wraith(org.openbw.bwapi4j.unit.Wraith)

Example 7 with UnitInfo

use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.

the class WraithAgent method chooseHarassTarget.

private UnitInfo chooseHarassTarget(Set<UnitInfo> mainTargets) {
    UnitInfo chosen = null;
    double maxScore = Double.MIN_VALUE;
    for (UnitInfo u : mainTargets) {
        // if (!u.unit.exists()) continue;
        double dist = unitInfo.getDistance(u);
        double score = u.unitType.isWorker() ? 5 : (u.unitType == UnitType.Zerg_Overlord ? 8 : 1);
        WeaponType weapon = Util.getWeapon(unitInfo, u);
        score *= dist <= weapon.maxRange() ? 1.4 : 0.9;
        score *= (double) u.unitType.maxHitPoints() / (double) u.health;
        if (chosen == null || maxScore < score) {
            chosen = u;
            maxScore = score;
        }
    }
    return chosen;
}
Also used : UnitInfo(ecgberht.UnitInfo) WeaponType(org.openbw.bwapi4j.type.WeaponType)

Example 8 with UnitInfo

use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.

the class SimulationTheory method doSimASS.

/**
 * Updates the SimInfos created with the results of the ASS simulations
 */
private void doSimASS() {
    int energy = getGs().CSs.stream().filter(s -> s.getOrder() != Order.CastScannerSweep).mapToInt(s -> s.getEnergy() / 50).sum();
    for (SimInfo s : simulations) {
        try {
            simulator.reset();
            if (s.enemies.isEmpty())
                continue;
            for (UnitInfo u : s.allies) {
                Agent jU = factory.of(u.unit);
                simulator.addAgentA(jU);
                s.stateBefore.first.add(jU);
            }
            for (UnitInfo u : s.enemies) {
                if (u.unitType.isWorker() && u.visible && !u.unit.isAttacking())
                    continue;
                if (u.unitType.isBuilding() && !u.completed)
                    continue;
                if (u.unitType == UnitType.Zerg_Creep_Colony || (!Util.isStaticDefense(u) && !u.unitType.canAttack()))
                    continue;
                if (!u.unit.isDetected() && (u.unit instanceof DarkTemplar || u.burrowed)) {
                    if (energy >= 1)
                        energy -= 1;
                    else {
                        s.lose = true;
                        break;
                    }
                }
                Agent jU = factory.of(u.unit);
                simulator.addAgentB(jU);
                s.stateBefore.second.add(jU);
            }
            if (s.lose)
                continue;
            s.preSimScore = scores();
            double estimate = evaluator.evaluate(s.stateBefore.first, s.stateBefore.second);
            if (estimate < 0.1) {
                s.lose = true;
                continue;
            }
            if (estimate > 0.6)
                continue;
            simulator.simulate(simFrames);
            s.postSimScore = scores();
            s.stateAfter = new MutablePair<>(simulator.getAgentsA(), simulator.getAgentsB());
            int ourLosses = s.preSimScore.first - s.postSimScore.first;
            int enemyLosses = s.preSimScore.second - s.postSimScore.second;
            if (s.stateAfter.first.isEmpty()) {
                s.lose = true;
                continue;
            }
            if (enemyLosses > ourLosses * 1.35)
                continue;
            simulator.simulate(simFrames);
            s.postSimScore = scores();
            s.stateAfter = new MutablePair<>(simulator.getAgentsA(), simulator.getAgentsB());
            // Bad lose sim logic, testing
            if (s.stateAfter.first.isEmpty())
                s.lose = true;
            else if (getGs().getStrat().name.equals("ProxyBBS"))
                s.lose = !scoreCalcASS(s, 1.2);
            else if (getGs().getStrat().name.equals("ProxyEightRax"))
                s.lose = !scoreCalcASS(s, 1.35);
            else
                s.lose = !scoreCalcASS(s, 2);
        } catch (Exception e) {
            System.err.println("Simulator ASS exception");
            e.printStackTrace();
        }
    }
}
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) Agent(org.bk.ass.sim.Agent)

Example 9 with UnitInfo

use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.

the class SimulationTheory method createSimInfos.

/**
 * Using the clusters creates different SimInfos based on distance between them
 */
private void createSimInfos() {
    for (Cluster friend : friendly) {
        if (friend.units.isEmpty())
            continue;
        SimInfo aux = new SimInfo(friend);
        for (Cluster enemy : enemies) {
            if (enemy.units.isEmpty())
                continue;
            if (closeClusters(friend, enemy))
                aux.enemies.addAll(enemy.units);
        }
        aux.allies.addAll(friend.units);
        simulations.add(aux);
    }
    List<SimInfo> newSims = new ArrayList<>();
    for (SimInfo s : simulations) {
        SimInfo air = new SimInfo();
        SimInfo ground = new SimInfo();
        for (UnitInfo u : s.allies) {
            if (u.flying)
                air.allies.add(u);
            else
                ground.allies.add(u);
        }
        boolean emptyAir = air.allies.isEmpty();
        boolean emptyGround = ground.allies.isEmpty();
        if (emptyAir && emptyGround)
            continue;
        for (UnitInfo u : s.enemies) {
            if (u.unit instanceof AirAttacker || u.unitType == UnitType.Terran_Bunker)
                air.enemies.add(u);
            if (u.unit instanceof GroundAttacker || u.unitType == UnitType.Terran_Bunker || u.unitType == UnitType.Zerg_Creep_Colony)
                ground.enemies.add(u);
        }
        air.type = SimInfo.SimType.AIR;
        newSims.add(air);
        ground.type = SimInfo.SimType.GROUND;
        newSims.add(ground);
    }
    if (!newSims.isEmpty())
        simulations.addAll(newSims);
}
Also used : UnitInfo(ecgberht.UnitInfo) ArrayList(java.util.ArrayList) Cluster(ecgberht.Clustering.Cluster)

Example 10 with UnitInfo

use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.

the class SimulationTheory method simulateDefenseBattle.

// TODO improve and search for bunkers SimInfos
public MutablePair<Boolean, Boolean> simulateDefenseBattle(Set<UnitInfo> friends, Set<Unit> enemies, int frames, boolean bunker) {
    simulator.reset();
    MutablePair<Boolean, Boolean> result = new MutablePair<>(true, false);
    for (UnitInfo u : friends) simulator.addAgentA(factory.of(u.unit));
    for (Unit u : enemies) simulator.addAgentB(factory.of((PlayerUnit) u));
    MutablePair<Integer, Integer> presim_scores = scores();
    simulator.simulate(frames);
    MutablePair<Integer, Integer> postsim_scores = scores();
    int my_score_diff = presim_scores.first - postsim_scores.first;
    int enemy_score_diff = presim_scores.second - postsim_scores.second;
    if (enemy_score_diff * 2 < my_score_diff)
        result.first = false;
    if (bunker) {
        boolean bunkerDead = true;
        for (Agent unit : simulator.getAgentsA()) {
            if (unit == null || unit.getUserObject() == null)
                continue;
            if (((Unit) unit.getUserObject()).getType() == UnitType.Terran_Bunker) {
                bunkerDead = false;
                break;
            }
        }
        if (bunkerDead)
            result.second = true;
    }
    return result;
}
Also used : MutablePair(ecgberht.Util.MutablePair) UnitInfo(ecgberht.UnitInfo) Agent(org.bk.ass.sim.Agent)

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