Search in sources :

Example 1 with Agent

use of org.bk.ass.sim.Agent 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 2 with Agent

use of org.bk.ass.sim.Agent 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)2 MutablePair (ecgberht.Util.MutablePair)2 Agent (org.bk.ass.sim.Agent)2 Cluster (ecgberht.Clustering.Cluster)1 MeanShift (ecgberht.Clustering.MeanShift)1 ConfigManager (ecgberht.ConfigManager)1 Ecgberht.getGs (ecgberht.Ecgberht.getGs)1 IntelligenceAgency (ecgberht.IntelligenceAgency)1 Util (ecgberht.Util.Util)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 ToIntFunction (java.util.function.ToIntFunction)1 Collectors (java.util.stream.Collectors)1 BWAPI4JAgentFactory (org.bk.ass.sim.BWAPI4JAgentFactory)1 Evaluator (org.bk.ass.sim.Evaluator)1 Simulator (org.bk.ass.sim.Simulator)1 BW (org.openbw.bwapi4j.BW)1 Position (org.openbw.bwapi4j.Position)1 org.openbw.bwapi4j.type (org.openbw.bwapi4j.type)1