Search in sources :

Example 1 with MutablePair

use of ecgberht.Util.MutablePair in project Ecgberht by Jabbo16.

the class Ecgberht method onUnitComplete.

@Override
public void onUnitComplete(Unit arg0) {
    try {
        if (arg0 instanceof MineralPatch || arg0 instanceof VespeneGeyser || arg0 instanceof SpecialBuilding || arg0 instanceof Critter || arg0 instanceof ScannerSweep) {
            return;
        }
        skycladObserver.moveCameraUnitCompleted(arg0);
        PlayerUnit pU = (PlayerUnit) arg0;
        UnitType type = arg0.getType();
        if (!type.isNeutral() && pU.getPlayer().getId() == self.getId()) {
            gs.unitStorage.onUnitComplete(arg0);
            if (gs.ih.getFrameCount() > 0)
                gs.supplyMan.onComplete(arg0);
            if (type.isBuilding()) {
                gs.builtBuildings++;
                if (type.isRefinery()) {
                    for (Entry<VespeneGeyser, Boolean> r : gs.vespeneGeysers.entrySet()) {
                        if (r.getKey().getTilePosition().equals(arg0.getTilePosition())) {
                            gs.vespeneGeysers.put(r.getKey(), true);
                            break;
                        }
                    }
                    for (Entry<SCV, Building> u : gs.workerTask.entrySet()) {
                        if (u.getValue().equals(arg0)) {
                            gs.workerGas.put(u.getKey(), (GasMiningFacility) arg0);
                            gs.workerTask.remove(u.getKey());
                            break;
                        }
                    }
                    gs.refineriesAssigned.put((GasMiningFacility) arg0, 1);
                    gs.builtRefinery++;
                } else {
                    if (type == UnitType.Terran_Command_Center) {
                        Base ccBase = Util.getClosestBaseLocation(arg0.getPosition());
                        if (!gs.islandBases.isEmpty() && gs.islandBases.contains(ccBase))
                            gs.islandCCs.put(ccBase, (CommandCenter) arg0);
                        else
                            gs.CCs.put(ccBase, (CommandCenter) arg0);
                        if (gs.getStrat().name.equals("BioMechGreedyFE") && Util.getNumberCCs() > 2)
                            gs.getStrat().raxPerCC = 3;
                        else if (gs.getStrat().name.equals("BioMechGreedyFE") && Util.getNumberCCs() < 3)
                            gs.getStrat().raxPerCC = 2;
                        gs.addNewResources(ccBase);
                        if (gs.frameCount != 0 && gs.firstExpand && ccBase.getArea().equals(gs.naturalArea) && !gs.defense)
                            gs.workerTransfer();
                        if (gs.frameCount != 0 && gs.firstExpand) {
                            gs.firstExpand = false;
                            if (gs.getStrat().name.equals("14CC")) {
                                gs.scipio.choose14CCTransition();
                                transition();
                            }
                            if (gs.naturalChoke != null)
                                gs.defendPosition = gs.naturalChoke.getCenter().toPosition();
                        }
                        if (((CommandCenter) arg0).getAddon() != null && !gs.CSs.contains(((CommandCenter) arg0).getAddon())) {
                            gs.CSs.add((ComsatStation) ((CommandCenter) arg0).getAddon());
                        }
                        if (gs.frameCount == 0)
                            gs.mainCC = new MutablePair<>(ccBase, arg0);
                    }
                    if (type == UnitType.Terran_Comsat_Station)
                        gs.CSs.add((ComsatStation) arg0);
                    if (type == UnitType.Terran_Bunker)
                        gs.DBs.put((Bunker) arg0, new TreeSet<>());
                    if (type == UnitType.Terran_Engineering_Bay || type == UnitType.Terran_Academy) {
                        gs.UBs.add((ResearchingFacility) arg0);
                    }
                    if (type == UnitType.Terran_Barracks)
                        gs.MBs.add((Barracks) arg0);
                    if (type == UnitType.Terran_Factory)
                        gs.Fs.add((Factory) arg0);
                    if (type == UnitType.Terran_Starport)
                        gs.Ps.add((Starport) arg0);
                    if (type == UnitType.Terran_Science_Facility)
                        gs.UBs.add((ResearchingFacility) arg0);
                    if (type == UnitType.Terran_Control_Tower)
                        gs.UBs.add((ResearchingFacility) arg0);
                    if (type == UnitType.Terran_Armory)
                        gs.UBs.add((ResearchingFacility) arg0);
                    if (type == UnitType.Terran_Supply_Depot)
                        gs.SBs.add((SupplyDepot) arg0);
                    if (type == UnitType.Terran_Machine_Shop)
                        gs.UBs.add((ResearchingFacility) arg0);
                    if (type == UnitType.Terran_Missile_Turret)
                        gs.Ts.add((MissileTurret) arg0);
                    for (Entry<SCV, Building> u : gs.workerTask.entrySet()) {
                        if (u.getValue().equals(arg0)) {
                            gs.workerIdle.add(u.getKey());
                            gs.workerTask.remove(u.getKey());
                            break;
                        }
                    }
                }
            } else if (type.isWorker())
                gs.workerIdle.add((Worker) arg0);
            else if (type == UnitType.Terran_Vulture && !gs.getStrat().name.equals("TheNitekat") && !bw.getBWMap().mapHash().equals("666dd28cd3c85223ebc749a481fc281e58221e4a"))
                gs.agents.put(arg0, new VultureAgent(arg0));
            else if (type == UnitType.Terran_Dropship) {
                DropShipAgent d = new DropShipAgent(arg0);
                gs.agents.put(arg0, d);
            } else if (type == UnitType.Terran_Science_Vessel) {
                VesselAgent v = new VesselAgent(arg0);
                gs.agents.put(arg0, v);
            } else if (type == UnitType.Terran_Wraith) {
                if (!gs.getStrat().name.equals("PlasmaWraithHell")) {
                    String name = gs.pickShipName();
                    gs.agents.put(arg0, new WraithAgent(arg0, name));
                }
            } else {
                gs.myArmy.add(gs.unitStorage.getAllyUnits().get(arg0));
                if (gs.enemyMainBase != null && gs.silentCartographer.mapCenter.getDistance(gs.enemyMainBase.getLocation()) < arg0.getTilePosition().getDistance(gs.enemyMainBase.getLocation())) {
                    ((MobileUnit) arg0).move(gs.silentCartographer.mapCenter.toPosition());
                }
            }
        }
    } catch (Exception e) {
        System.err.println("onUnitComplete exception");
        e.printStackTrace();
    }
}
Also used : FinishBuilding(ecgberht.BehaviourTrees.BuildingLot.FinishBuilding) MutablePair(ecgberht.Util.MutablePair) TreeSet(java.util.TreeSet) VesselAgent(ecgberht.Agents.VesselAgent) VultureAgent(ecgberht.Agents.VultureAgent) WraithAgent(ecgberht.Agents.WraithAgent) Base(bwem.Base) FileNotFoundException(java.io.FileNotFoundException) DropShipAgent(ecgberht.Agents.DropShipAgent)

Example 2 with MutablePair

use of ecgberht.Util.MutablePair in project Ecgberht by Jabbo16.

the class WorkerWalkBuild method execute.

@Override
public State execute() {
    try {
        for (Entry<SCV, MutablePair<UnitType, TilePosition>> u : gameState.workerBuild.entrySet()) {
            SCV chosen = u.getKey();
            if (u.getValue().first != UnitType.Terran_Command_Center || gameState.getGame().getBWMap().isVisible(u.getValue().second) || !gameState.fortressSpecialBLsTiles.contains(u.getValue().second))
                continue;
            Base myBase = Util.getClosestBaseLocation(u.getValue().second.toPosition());
            MutablePair<MineralPatch, MineralPatch> minerals = gameState.fortressSpecialBLs.get(myBase);
            Area scvArea = gameState.bwem.getMap().getArea(chosen.getTilePosition());
            if (!u.getValue().second.equals(new TilePosition(7, 118))) {
                if (scvArea != null && scvArea.equals(myBase.getArea())) {
                    if (chosen.getDistance(minerals.first) > 3 * 32) {
                        chosen.move(u.getValue().second.toPosition());
                        continue;
                    }
                    if (minerals.second.isVisible()) {
                        chosen.gather(minerals.second);
                        continue;
                    }
                }
                if (minerals.second.isVisible()) {
                    chosen.gather(minerals.second);
                    continue;
                }
                if (minerals.first.isVisible()) {
                    chosen.gather(minerals.first);
                }
            } else {
                // Weird logic :/
                if (scvArea != null && scvArea.equals(myBase.getArea())) {
                    if (chosen.getDistance(minerals.first) > 3 * 32) {
                        chosen.move(u.getValue().second.toPosition());
                        continue;
                    } else {
                        chosen.gather(minerals.second);
                        continue;
                    }
                }
                chosen.gather(minerals.first);
            }
        }
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : MutablePair(ecgberht.Util.MutablePair) Area(bwem.Area) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) SCV(org.openbw.bwapi4j.unit.SCV) TilePosition(org.openbw.bwapi4j.TilePosition) Base(bwem.Base)

Example 3 with MutablePair

use of ecgberht.Util.MutablePair in project Ecgberht by Jabbo16.

the class Build method execute.

@Override
public State execute() {
    try {
        List<SCV> toRemove = new ArrayList<>();
        for (Entry<SCV, MutablePair<UnitType, TilePosition>> u : gameState.workerBuild.entrySet()) {
            if (u.getKey().getOrder() != Order.PlaceBuilding && gameState.getGame().getBWMap().isVisible(u.getValue().second) && gameState.canAfford(u.getValue().first)) {
                SCV chosen = u.getKey();
                if (u.getValue().first == UnitType.Terran_Bunker) {
                    if (!chosen.build(u.getValue().second, u.getValue().first)) {
                        gameState.deltaCash.first -= u.getValue().first.mineralPrice();
                        gameState.deltaCash.second -= u.getValue().first.gasPrice();
                        toRemove.add(chosen);
                        chosen.stop(false);
                        gameState.workerIdle.add(chosen);
                    }
                } else if (u.getKey().getOrder() == Order.PlayerGuard) {
                    if (Math.random() < 0.8)
                        chosen.build(u.getValue().second, u.getValue().first);
                    else
                        chosen.move(u.getKey().getPosition().add(new Position(32, 0)));
                } else
                    chosen.build(u.getValue().second, u.getValue().first);
            }
        }
        for (SCV s : toRemove) gameState.workerBuild.remove(s);
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : MutablePair(ecgberht.Util.MutablePair) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) SCV(org.openbw.bwapi4j.unit.SCV) ArrayList(java.util.ArrayList)

Example 4 with MutablePair

use of ecgberht.Util.MutablePair 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 5 with MutablePair

use of ecgberht.Util.MutablePair 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

MutablePair (ecgberht.Util.MutablePair)9 Base (bwem.Base)4 UnitInfo (ecgberht.UnitInfo)4 ArrayList (java.util.ArrayList)3 Position (org.openbw.bwapi4j.Position)3 TilePosition (org.openbw.bwapi4j.TilePosition)3 SCV (org.openbw.bwapi4j.unit.SCV)3 DropShipAgent (ecgberht.Agents.DropShipAgent)2 List (java.util.List)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 Agent (org.bk.ass.sim.Agent)2 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)2 Area (bwem.Area)1 ChokePoint (bwem.ChokePoint)1 Mineral (bwem.Mineral)1 Agent (ecgberht.Agents.Agent)1 VesselAgent (ecgberht.Agents.VesselAgent)1 VultureAgent (ecgberht.Agents.VultureAgent)1 WraithAgent (ecgberht.Agents.WraithAgent)1