Search in sources :

Example 1 with Player

use of org.openbw.bwapi4j.Player in project Ecgberht by Jabbo16.

the class ChooseMarineRange method execute.

@Override
public State execute() {
    try {
        if (gameState.UBs.isEmpty())
            return State.FAILURE;
        String strat = gameState.getStrat().name;
        if (strat.equals("BioMech") || strat.equals("BioMechGreedyFE") || strat.equals("BioMechFE")) {
            Player self = gameState.getPlayer();
            if (!self.isResearching(TechType.Tank_Siege_Mode) && !self.hasResearched(TechType.Tank_Siege_Mode)) {
                return State.FAILURE;
            }
        }
        for (ResearchingFacility u : gameState.UBs) {
            if (!(u instanceof Academy))
                continue;
            if (gameState.getPlayer().hasResearched(TechType.Stim_Packs) && gameState.getPlayer().getUpgradeLevel(UpgradeType.U_238_Shells) < 1 && u.canUpgrade(UpgradeType.U_238_Shells) && !u.isResearching() && !u.isUpgrading()) {
                gameState.chosenUnitUpgrader = u;
                gameState.chosenUpgrade = UpgradeType.U_238_Shells;
                return State.SUCCESS;
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Player(org.openbw.bwapi4j.Player) Academy(org.openbw.bwapi4j.unit.Academy) ResearchingFacility(org.openbw.bwapi4j.unit.ResearchingFacility)

Example 2 with Player

use of org.openbw.bwapi4j.Player in project Ecgberht by Jabbo16.

the class IntelligenceAgency method onDestroy.

static void onDestroy(Unit unit, UnitType type) {
    Integer value = mainEnemyUnitTypeAmount.get(type);
    if (value != null)
        mainEnemyUnitTypeAmount.put(type, value - 1);
    else
        mainEnemyUnitTypeAmount.put(type, 0);
    Player player = ((PlayerUnit) unit).getPlayer();
    if (type.isResourceDepot() && enemyBases.containsKey(player))
        enemyBases.get(player).remove(getGs().unitStorage.getEnemyUnits().get(unit));
    if (getGs().enemyRace == Race.Zerg && unit instanceof Drone)
        enemyWorkers.remove(unit);
}
Also used : Player(org.openbw.bwapi4j.Player)

Example 3 with Player

use of org.openbw.bwapi4j.Player in project BWAPI4J by OpenBW.

the class TestListenerBwem method onStart.

@Override
public void onStart() {
    try {
        System.out.println("onStart");
        // Hello World!
        bw.getInteractionHandler().sendText("hello, world");
        // Print the map name.
        bw.getInteractionHandler().printf("The map is " + bw.getBWMap().mapName() + "! Size: " + bw.getBWMap().mapWidth() + "x" + bw.getBWMap().mapHeight());
        // Enable the UserInput flag, which allows us to manually control units and type messages.
        bw.getInteractionHandler().enableUserInput();
        // Uncomment the following line and the bot will know about everything through the fog of war (cheat).
        // bw.getInteractionHandler().enableCompleteMapInformation();
        self = bw.getInteractionHandler().self();
        // Initialize BWEM.
        System.out.println("BWEM initialization started.");
        // Instantiate the BWEM object.
        bwem = new BWEM(bw);
        // Initialize and pre-calculate internal data.
        bwem.initialize();
        // This option requires "bwem.getMap().onUnitDestroyed(unit);" in the "onUnitDestroy" callback.
        bwem.getMap().enableAutomaticPathAnalysis();
        try {
            // Throws an exception on failure.
            bwem.getMap().assignStartingLocationsToSuitableBases();
        } catch (final Exception e) {
            e.printStackTrace();
            if (bwem.getMap().getUnassignedStartingLocations().size() > 0) {
                throw new IllegalStateException("Failed to find suitable bases for the following starting locations: " + bwem.getMap().getUnassignedStartingLocations().toString());
            }
        }
        System.out.println("BWEM initialization completed.");
        // BWEM's map printer example. Generates a "map.bmp" image file.
        bwem.getMap().getMapPrinter().initialize(bw, bwem.getMap());
        final MapPrinterExample example = new MapPrinterExample(bwem.getMap().getMapPrinter());
        example.printMap(bwem.getMap());
        example.pathExample(bwem.getMap());
        /* Print player info to console. */
        {
            final StringBuilder sb = new StringBuilder("Players: ").append(System.lineSeparator());
            for (final Player player : bw.getAllPlayers()) {
                sb.append("  ").append(player.getName()).append(", ID=").append(player.getId()).append(", race=").append(player.getRace()).append(System.lineSeparator());
            }
            System.out.println(sb.toString());
        }
        // Compile list of workers.
        for (final PlayerUnit u : bw.getUnits(self)) {
            if (u instanceof Worker) {
                final Worker worker = (Worker) u;
                if (!workers.contains(worker)) {
                    workers.add(worker);
                }
            }
        }
        /* Basic gamestart worker auto-mine */
        {
            final List<MineralPatch> unassignedMineralPatches = bw.getMineralPatches();
            final List<Worker> unassignedWorkers = new ArrayList<>(workers);
            unassignedMineralPatches.sort(new UnitDistanceComparator(self.getStartLocation().toPosition()));
            while (!unassignedWorkers.isEmpty() && !unassignedMineralPatches.isEmpty()) {
                final Worker unassignedWorker = unassignedWorkers.remove(0);
                final MineralPatch unassignedMineralPatch = unassignedMineralPatches.remove(0);
                unassignedWorker.gather(unassignedMineralPatch);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : Player(org.openbw.bwapi4j.Player) MapPrinterExample(bwem.example.MapPrinterExample) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) Worker(org.openbw.bwapi4j.unit.Worker) ArrayList(java.util.ArrayList) List(java.util.List) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit)

Example 4 with Player

use of org.openbw.bwapi4j.Player in project Ecgberht by Jabbo16.

the class ChoosePosition method execute.

@Override
public State execute() {
    try {
        if (gameState.chosenToBuild == UnitType.None)
            return State.FAILURE;
        Player self = gameState.getPlayer();
        TilePosition origin;
        if (gameState.chosenToBuild.isRefinery()) {
            if (!gameState.vespeneGeysers.isEmpty()) {
                for (Entry<VespeneGeyser, Boolean> g : gameState.vespeneGeysers.entrySet()) {
                    if (!g.getValue()) {
                        gameState.chosenPosition = g.getKey().getTilePosition();
                        return State.SUCCESS;
                    }
                }
            }
        } else if (gameState.chosenToBuild == UnitType.Terran_Command_Center) {
            if (!gameState.islandBases.isEmpty() && gameState.islandCCs.size() < gameState.islandBases.size()) {
                if (gameState.islandExpand)
                    return State.FAILURE;
                for (Agent u : gameState.agents.values()) {
                    if (u instanceof DropShipAgent && u.statusToString().equals("IDLE")) {
                        gameState.islandExpand = true;
                        return State.FAILURE;
                    }
                }
            }
            TilePosition main;
            if (gameState.mainCC != null)
                main = gameState.mainCC.second.getTilePosition();
            else
                main = gameState.getPlayer().getStartLocation();
            List<Base> valid = new ArrayList<>();
            if (gameState.getStrat().name.equals("PlasmaWraithHell")) {
                for (Base b : gameState.specialBLs) {
                    if (!gameState.CCs.containsKey(b)) {
                        gameState.chosenPosition = b.getLocation();
                        return State.SUCCESS;
                    }
                }
            }
            for (Base b : gameState.BLs) {
                if (!gameState.CCs.containsKey(b) && Util.isConnected(b.getLocation(), main))
                    valid.add(b);
            }
            List<Base> remove = new ArrayList<>();
            for (Base b : valid) {
                if (gameState.getGame().getBWMap().isVisible(b.getLocation()) && !gameState.getGame().getBWMap().isBuildable(b.getLocation(), true)) {
                    remove.add(b);
                    continue;
                }
                if (b.getArea() != gameState.naturalArea) {
                    for (Unit u : gameState.enemyCombatUnitMemory) {
                        if (gameState.bwem.getMap().getArea(u.getTilePosition()) == null || !(u instanceof Attacker) || u instanceof Worker) {
                            continue;
                        }
                        if (gameState.bwem.getMap().getArea(u.getTilePosition()).equals(b.getArea())) {
                            remove.add(b);
                            break;
                        }
                    }
                    for (UnitInfo u : gameState.unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
                        if (gameState.bwem.getMap().getArea(u.tileposition) == null)
                            continue;
                        if (gameState.bwem.getMap().getArea(u.tileposition).equals(b.getArea())) {
                            remove.add(b);
                            break;
                        }
                    }
                }
            }
            valid.removeAll(remove);
            if (valid.isEmpty())
                return State.FAILURE;
            gameState.chosenPosition = valid.get(0).getLocation();
            return State.SUCCESS;
        } else {
            if (!gameState.workerBuild.isEmpty()) {
                for (MutablePair<UnitType, TilePosition> w : gameState.workerBuild.values()) {
                    gameState.testMap.updateMap(w.second, w.first, false);
                }
            }
            if (!gameState.chosenToBuild.equals(UnitType.Terran_Bunker) && !gameState.chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
                if (gameState.getStrat().proxy && gameState.chosenToBuild == UnitType.Terran_Barracks) {
                    origin = gameState.mapCenter.toTilePosition();
                } else if (gameState.mainCC != null && gameState.mainCC.first != null) {
                    origin = gameState.mainCC.first.getLocation();
                } else
                    origin = self.getStartLocation();
            } else if (gameState.chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
                if (gameState.defendPosition != null)
                    origin = gameState.defendPosition.toTilePosition();
                else if (gameState.DBs.isEmpty()) {
                    origin = Util.getClosestChokepoint(self.getStartLocation().toPosition()).getCenter().toTilePosition();
                } else {
                    origin = gameState.DBs.keySet().stream().findFirst().map(UnitImpl::getTilePosition).orElse(null);
                }
            } else if (gameState.learningManager.isNaughty() && gameState.enemyRace == Race.Zerg) {
                origin = gameState.getBunkerPositionAntiPool();
                if (origin != null) {
                    gameState.testMap = gameState.map.clone();
                    gameState.chosenPosition = origin;
                    return State.SUCCESS;
                } else {
                    origin = gameState.testMap.findBunkerPositionAntiPool();
                    if (origin != null) {
                        gameState.testMap = gameState.map.clone();
                        gameState.chosenPosition = origin;
                        return State.SUCCESS;
                    } else if (gameState.mainCC != null)
                        origin = gameState.mainCC.second.getTilePosition();
                    else
                        origin = gameState.getPlayer().getStartLocation();
                }
            } else if (gameState.Ts.isEmpty()) {
                if (gameState.defendPosition != null && gameState.naturalChoke != null && gameState.defendPosition.equals(gameState.naturalChoke.getCenter().toPosition())) {
                    origin = gameState.testMap.findBunkerPosition(gameState.naturalChoke);
                    if (origin != null) {
                        gameState.testMap = gameState.map.clone();
                        gameState.chosenPosition = origin;
                        return State.SUCCESS;
                    }
                }
                if (gameState.mainChoke != null && !gameState.getStrat().name.equals("MechGreedyFE") && !gameState.getStrat().name.equals("BioGreedyFE") && !gameState.getStrat().name.equals("14CC") && !gameState.getStrat().name.equals("BioMechGreedyFE")) {
                    origin = gameState.testMap.findBunkerPosition(gameState.mainChoke);
                    if (origin != null) {
                        gameState.testMap = gameState.map.clone();
                        gameState.chosenPosition = origin;
                        return State.SUCCESS;
                    } else
                        origin = gameState.mainChoke.getCenter().toTilePosition();
                } else if (gameState.naturalChoke != null) {
                    origin = gameState.testMap.findBunkerPosition(gameState.naturalChoke);
                    if (origin != null) {
                        gameState.testMap = gameState.map.clone();
                        gameState.chosenPosition = origin;
                        return State.SUCCESS;
                    } else
                        origin = gameState.mainChoke.getCenter().toTilePosition();
                } else {
                    origin = gameState.testMap.findBunkerPosition(gameState.mainChoke);
                    if (origin != null) {
                        gameState.testMap = gameState.map.clone();
                        gameState.chosenPosition = origin;
                        return State.SUCCESS;
                    } else
                        origin = gameState.mainChoke.getCenter().toTilePosition();
                }
            } else
                origin = gameState.Ts.stream().findFirst().map(UnitImpl::getTilePosition).orElse(null);
            TilePosition position = gameState.testMap.findPositionNew(gameState.chosenToBuild, origin);
            gameState.testMap = gameState.map.clone();
            if (position != null) {
                gameState.chosenPosition = position;
                return State.SUCCESS;
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Agent(ecgberht.Agents.Agent) DropShipAgent(ecgberht.Agents.DropShipAgent) Player(org.openbw.bwapi4j.Player) Base(bwem.Base) UnitInfo(ecgberht.UnitInfo) MutablePair(ecgberht.Util.MutablePair) DropShipAgent(ecgberht.Agents.DropShipAgent) TilePosition(org.openbw.bwapi4j.TilePosition) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with Player

use of org.openbw.bwapi4j.Player in project Ecgberht by Jabbo16.

the class IntelligenceAgency method onShow.

static void onShow(Unit unit, UnitType type) {
    Integer value = mainEnemyUnitTypeAmount.get(type);
    if (value != null)
        mainEnemyUnitTypeAmount.put(type, value + 1);
    else
        mainEnemyUnitTypeAmount.put(type, 0);
    Player player = ((PlayerUnit) unit).getPlayer();
    if (unit instanceof Worker)
        enemyWorkers.add(unit);
    // Bases
    if (type.isResourceDepot()) {
        // If base and player known skip
        if (enemyBases.containsKey(player) && enemyBases.get(player).contains(getGs().unitStorage.getEnemyUnits().get(unit)))
            return;
        for (Base b : getGs().BLs) {
            if (b.getLocation().equals(unit.getTilePosition())) {
                enemyBases.get(player).add(getGs().unitStorage.getEnemyUnits().get(unit));
                break;
            }
        }
    }
    // If player and type known skip
    if (enemyTypes.containsKey(player) && enemyTypes.get(player).contains(type))
        return;
    // Normal units
    if (!(unit instanceof Egg))
        enemyTypes.get(player).add(type);
    // Eggs
    if (type == UnitType.Zerg_Lurker_Egg)
        enemyTypes.get(player).add(UnitType.Zerg_Lurker);
    else // Buildings
    if (type.isBuilding()) {
        // Protoss tech
        if (type == UnitType.Protoss_Arbiter_Tribunal)
            enemyTypes.get(player).add(UnitType.Protoss_Arbiter);
        else if (type == UnitType.Protoss_Templar_Archives) {
            enemyTypes.get(player).add(UnitType.Protoss_Dark_Templar);
            enemyTypes.get(player).add(UnitType.Protoss_High_Templar);
        } else if (type == UnitType.Protoss_Fleet_Beacon)
            enemyTypes.get(player).add(UnitType.Protoss_Carrier);
        else if (type == UnitType.Protoss_Robotics_Support_Bay)
            enemyTypes.get(player).add(UnitType.Protoss_Reaver);
        else // Zerg tech
        if (type == UnitType.Zerg_Spawning_Pool)
            enemyTypes.get(player).add(UnitType.Zerg_Zergling);
        else if (type == UnitType.Zerg_Spire)
            enemyTypes.get(player).add(UnitType.Zerg_Mutalisk);
        else if (type == UnitType.Zerg_Hydralisk_Den)
            enemyTypes.get(player).add(UnitType.Zerg_Hydralisk);
        else if (type == UnitType.Zerg_Queens_Nest)
            enemyTypes.get(player).add(UnitType.Zerg_Queen);
        else if (type == UnitType.Zerg_Defiler_Mound)
            enemyTypes.get(player).add(UnitType.Zerg_Defiler);
    }
}
Also used : Player(org.openbw.bwapi4j.Player) Base(bwem.Base)

Aggregations

Player (org.openbw.bwapi4j.Player)6 Base (bwem.Base)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MapPrinterExample (bwem.example.MapPrinterExample)1 Agent (ecgberht.Agents.Agent)1 DropShipAgent (ecgberht.Agents.DropShipAgent)1 UnitInfo (ecgberht.UnitInfo)1 MutablePair (ecgberht.Util.MutablePair)1 TilePosition (org.openbw.bwapi4j.TilePosition)1 Academy (org.openbw.bwapi4j.unit.Academy)1 Barracks (org.openbw.bwapi4j.unit.Barracks)1 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)1 PlayerUnit (org.openbw.bwapi4j.unit.PlayerUnit)1 ResearchingFacility (org.openbw.bwapi4j.unit.ResearchingFacility)1 Worker (org.openbw.bwapi4j.unit.Worker)1