use of org.openbw.bwapi4j.type.UnitType in project Ecgberht by Jabbo16.
the class MoveIsland method execute.
@Override
public State execute() {
try {
Worker chosen = gameState.chosenWorkerDrop;
UnitType chosenType = UnitType.Terran_Command_Center;
TilePosition chosenTile = gameState.chosenIsland.getLocation();
Position realEnd = Util.getUnitCenterPosition(chosenTile.toPosition(), chosenType);
if (chosen.move(realEnd)) {
gameState.workerBuild.put((SCV) chosen, new MutablePair<>(chosenType, chosenTile));
gameState.deltaCash.first += chosenType.mineralPrice();
gameState.deltaCash.second += chosenType.gasPrice();
gameState.chosenWorkerDrop = null;
gameState.chosenIsland = null;
gameState.islandExpand = false;
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.type.UnitType in project Ecgberht by Jabbo16.
the class TrainUnit method execute.
@Override
public State execute() {
try {
if (gameState.chosenUnit == UnitType.None)
return State.FAILURE;
TrainingFacility chosen = gameState.chosenTrainingFacility;
if (gameState.getStrat().name.equals("ProxyBBS")) {
if (Util.countBuildingAll(UnitType.Terran_Barracks) == 2 && Util.countBuildingAll(UnitType.Terran_Supply_Depot) == 0) {
gameState.chosenTrainingFacility = null;
gameState.chosenToBuild = UnitType.None;
return State.FAILURE;
}
if (gameState.getSupply() > 0) {
chosen.train(gameState.chosenUnit);
return State.SUCCESS;
}
}
if (gameState.getStrat().name.equals("ProxyEightRax")) {
if (Util.countBuildingAll(UnitType.Terran_Barracks) == 0 && gameState.supplyMan.getSupplyUsed() >= 16) {
gameState.chosenTrainingFacility = null;
gameState.chosenToBuild = UnitType.None;
return State.FAILURE;
}
if (gameState.getSupply() > 0) {
chosen.train(gameState.chosenUnit);
return State.SUCCESS;
}
}
if (gameState.getSupply() > 4 || gameState.checkSupply() || gameState.getPlayer().supplyTotal() >= 400) {
if (!gameState.defense && gameState.chosenToBuild == UnitType.Terran_Command_Center) {
boolean found = false;
for (MutablePair<UnitType, TilePosition> w : gameState.workerBuild.values()) {
if (w.first == UnitType.Terran_Command_Center) {
found = true;
break;
}
}
if (!found) {
gameState.chosenTrainingFacility = null;
gameState.chosenUnit = UnitType.None;
return State.FAILURE;
}
}
chosen.train(gameState.chosenUnit);
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.type.UnitType in project Ecgberht by Jabbo16.
the class CheckPerimeter method execute.
@Override
public State execute() {
try {
gameState.enemyInBase.clear();
gameState.defense = false;
Set<Unit> enemyInvaders = new TreeSet<>(gameState.enemyCombatUnitMemory);
for (UnitInfo u : gameState.unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
if (u.unitType.canAttack() || u.unitType == UnitType.Protoss_Pylon || u.unitType.canProduce() || u.unitType.isRefinery()) {
enemyInvaders.add(u.unit);
}
}
for (Unit u : enemyInvaders) {
UnitType uType = u.getType();
if (u instanceof Building || ((uType.canAttack() || uType.isSpellcaster() || u instanceof Loadable) && uType != UnitType.Zerg_Scourge && uType != UnitType.Terran_Valkyrie && uType != UnitType.Protoss_Corsair && !(u instanceof Overlord))) {
Area enemyArea = gameState.bwem.getMap().getArea(u.getTilePosition());
if (enemyArea != null) {
Area myMainArea = gameState.mainCC != null ? gameState.mainCC.first.getArea() : null;
Area myNatArea = gameState.naturalArea;
for (Base b : gameState.CCs.keySet()) {
if (!b.getArea().equals(enemyArea))
continue;
if ((myMainArea != null && !b.getArea().equals(myMainArea) && (myNatArea != null && !b.getArea().equals(myNatArea))))
continue;
gameState.enemyInBase.add(u);
break;
}
}
for (Map.Entry<SCV, Building> c : gameState.workerTask.entrySet()) {
int dist = c.getValue() instanceof CommandCenter ? 500 : 200;
if (Util.broodWarDistance(u.getPosition(), c.getValue().getPosition()) <= dist) {
gameState.enemyInBase.add(u);
break;
}
}
for (Unit c : gameState.CCs.values()) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 500) {
gameState.enemyInBase.add(u);
break;
}
}
for (Unit c : gameState.DBs.keySet()) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
for (Unit c : gameState.SBs) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
for (ResearchingFacility c : gameState.UBs) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
if (!gameState.getStrat().name.equals("ProxyBBS") && !gameState.getStrat().name.equals("ProxyEightRax")) {
for (Unit c : gameState.MBs) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
}
}
}
if (!gameState.enemyInBase.isEmpty()) {
/*if ((((GameState) gameState).getArmySize() >= 50 && ((GameState) gameState).getArmySize() / ((GameState) gameState).enemyInBase.size() > 10)) {
return State.FAILURE;
}*/
gameState.defense = true;
return State.SUCCESS;
}
int cFrame = gameState.frameCount;
List<Worker> toDelete = new ArrayList<>();
for (Worker u : gameState.workerDefenders.keySet()) {
if (u.getLastCommandFrame() == cFrame)
continue;
Position closestDefense;
if (gameState.learningManager.isNaughty()) {
if (!gameState.DBs.isEmpty()) {
closestDefense = gameState.DBs.keySet().iterator().next().getPosition();
u.move(closestDefense);
toDelete.add(u);
continue;
}
}
closestDefense = gameState.getNearestCC(u.getPosition(), false);
if (closestDefense != null) {
u.move(closestDefense);
toDelete.add(u);
}
}
for (Worker u : toDelete) {
u.stop(false);
gameState.workerDefenders.remove(u);
gameState.workerIdle.add(u);
}
for (Squad u : gameState.sqManager.squads.values()) {
if (u.status == Status.DEFENSE) {
Position closestCC = gameState.getNearestCC(u.getSquadCenter(), false);
if (closestCC != null) {
Area squad = gameState.bwem.getMap().getArea(u.getSquadCenter().toTilePosition());
Area regCC = gameState.bwem.getMap().getArea(closestCC.toTilePosition());
if (squad != null && regCC != null) {
if (!squad.equals(regCC)) {
if (!gameState.DBs.isEmpty() && gameState.CCs.size() == 1) {
u.giveMoveOrder(gameState.DBs.keySet().iterator().next().getPosition());
} else {
u.giveMoveOrder(Util.getClosestChokepoint(u.getSquadCenter()).getCenter().toPosition());
}
u.status = Status.IDLE;
u.attack = null;
continue;
}
}
u.status = Status.IDLE;
u.attack = null;
continue;
}
u.status = Status.IDLE;
u.attack = null;
}
}
gameState.defense = false;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.type.UnitType in project Ecgberht by Jabbo16.
the class ChooseExpand method execute.
@Override
public State execute() {
try {
String strat = gameState.getStrat().name;
if (strat.equals("ProxyBBS") || strat.equals("ProxyEightRax") || ((strat.equals("JoyORush") || strat.equals("TheNitekat")) && gameState.getCash().first <= 550))
return State.FAILURE;
if (strat.equals("FullMech") && (gameState.myArmy.stream().noneMatch(u -> u.unit instanceof SiegeTank) || !gameState.getPlayer().hasResearched(TechType.Tank_Siege_Mode)) && gameState.firstExpand)
return State.FAILURE;
for (MutablePair<UnitType, TilePosition> w : gameState.workerBuild.values()) {
if (w.first == UnitType.Terran_Command_Center)
return State.FAILURE;
}
for (Building w : gameState.workerTask.values()) {
if (w instanceof CommandCenter)
return State.FAILURE;
}
if (strat.equals("PlasmaWraithHell") && Util.countUnitTypeSelf(UnitType.Terran_Command_Center) > 2) {
return State.FAILURE;
}
if (gameState.iReallyWantToExpand || (gameState.getCash().first >= 550 && gameState.getArmySize() >= gameState.getStrat().armyForExpand) || (strat.equals("14CC") && gameState.supplyMan.getSupplyUsed() == 28)) {
gameState.chosenToBuild = UnitType.Terran_Command_Center;
return State.SUCCESS;
}
if ((strat.equals("BioGreedyFE") || strat.equals("MechGreedyFE") || strat.equals("BioMechGreedyFE") || strat.equals("PlasmaWraithHell")) && !gameState.MBs.isEmpty() && gameState.CCs.size() == 1) {
gameState.chosenToBuild = UnitType.Terran_Command_Center;
return State.SUCCESS;
}
int workers = gameState.workerIdle.size();
for (Integer wt : gameState.mineralsAssigned.values()) workers += wt;
if (gameState.mineralsAssigned.size() * 2 <= workers - 1 && gameState.getArmySize() >= gameState.getStrat().armyForExpand) {
gameState.chosenToBuild = UnitType.Terran_Command_Center;
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.type.UnitType in project Ecgberht by Jabbo16.
the class ChooseBarracks method execute.
@Override
public State execute() {
try {
String strat = gameState.getStrat().name;
if ((strat.equals("BioGreedyFE") || strat.equals("MechGreedyFE") || strat.equals("BioMechGreedyFE")) && Util.countBuildingAll(UnitType.Terran_Command_Center) == 1 && Util.countBuildingAll(UnitType.Terran_Barracks) > 1 && gameState.frameCount <= 24 * 240) {
return State.FAILURE;
}
if (strat.equals("14CC") && Util.countBuildingAll(UnitType.Terran_Command_Center) < 2)
return State.FAILURE;
if (!gameState.getStrat().techToResearch.contains(TechType.Stim_Packs) && gameState.getStrat().raxPerCC == 1 && gameState.MBs.size() > 0) {
return State.FAILURE;
}
if (gameState.learningManager.isNaughty() && gameState.enemyRace == Race.Zerg && Util.countBuildingAll(UnitType.Terran_Barracks) == 1 && Util.countBuildingAll(UnitType.Terran_Bunker) < 1) {
return State.FAILURE;
}
if (!strat.equals("ProxyBBS") && !strat.equals("ProxyEightRax")) {
if (!gameState.MBs.isEmpty() && Util.countBuildingAll(UnitType.Terran_Barracks) == gameState.getStrat().numRaxForAca && Util.countBuildingAll(UnitType.Terran_Academy) == 0) {
return State.FAILURE;
}
if (Util.countBuildingAll(UnitType.Terran_Barracks) == gameState.getStrat().numRaxForAca && Util.countBuildingAll(UnitType.Terran_Refinery) == 0) {
return State.FAILURE;
}
} else if (gameState.getPlayer().supplyUsed() < 16)
return State.FAILURE;
if (gameState.getStrat().buildUnits.contains(UnitType.Terran_Factory)) {
int count = 0;
boolean found = false;
for (MutablePair<UnitType, TilePosition> w : gameState.workerBuild.values()) {
if (w.first == UnitType.Terran_Barracks)
count++;
if (w.first == UnitType.Terran_Factory)
found = true;
}
for (Building w : gameState.workerTask.values()) {
if (w instanceof Barracks)
count++;
if (w instanceof Factory)
found = true;
}
if (!gameState.Fs.isEmpty())
found = true;
if (count + gameState.MBs.size() > gameState.getStrat().numRaxForFac && !found)
return State.FAILURE;
}
if (Util.countBuildingAll(UnitType.Terran_Academy) == 0 && Util.countBuildingAll(UnitType.Terran_Barracks) >= 2) {
return State.FAILURE;
}
if (Util.countBuildingAll(UnitType.Terran_Barracks) == gameState.MBs.size() && gameState.getPlayer().minerals() >= 600) {
gameState.chosenToBuild = UnitType.Terran_Barracks;
return State.SUCCESS;
}
if (Util.countBuildingAll(UnitType.Terran_Barracks) < gameState.getStrat().raxPerCC * Util.getNumberCCs()) {
gameState.chosenToBuild = UnitType.Terran_Barracks;
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
Aggregations