Search in sources :

Example 1 with Simulator

use of org.bk.ass.sim.Simulator 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)

Aggregations

Cluster (ecgberht.Clustering.Cluster)1 MeanShift (ecgberht.Clustering.MeanShift)1 ConfigManager (ecgberht.ConfigManager)1 Ecgberht.getGs (ecgberht.Ecgberht.getGs)1 IntelligenceAgency (ecgberht.IntelligenceAgency)1 UnitInfo (ecgberht.UnitInfo)1 MutablePair (ecgberht.Util.MutablePair)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 Agent (org.bk.ass.sim.Agent)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