use of org.openbw.bwapi4j.unit.SCV in project BWAPI4J by OpenBW.
the class MainTest method testMineralMining.
private void testMineralMining() throws AssertionError {
boolean commandSuccessful = false;
Player self = this.bw.getInteractionHandler().self();
Collection<Unit> allUnits = this.bw.getAllUnits();
MineralPatch patch = null;
for (Unit unit : allUnits) {
if (unit instanceof MineralPatch) {
patch = (MineralPatch) unit;
}
}
List<PlayerUnit> units = this.bw.getUnits(self);
SCV scv = null;
for (PlayerUnit unit : units) {
if (unit instanceof SCV) {
scv = (SCV) unit;
}
}
if (patch != null && scv != null) {
commandSuccessful = scv.gather(patch);
} else {
logger.error("no scv and patch found.");
}
assertTrue("gather command failed.", commandSuccessful);
}
use of org.openbw.bwapi4j.unit.SCV 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;
}
}
use of org.openbw.bwapi4j.unit.SCV 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;
}
}
use of org.openbw.bwapi4j.unit.SCV in project Ecgberht by Jabbo16.
the class CheckMineralWalkGoldRush method getCloserMineral.
private MineralPatch getCloserMineral(Map.Entry<SCV, MutablePair<UnitType, TilePosition>> entry) {
double bestDist = Double.MAX_VALUE;
MineralPatch closerMineral = null;
SCV scv = entry.getKey();
Position buildTarget = entry.getValue().second.toPosition();
for (MineralPatch mineralPatch : gameState.walkingMinerals) {
if (!mineralPatch.isVisible() || scv.getDistance(mineralPatch) <= 32 * 4)
continue;
double dist = mineralPatch.getDistance(buildTarget) * 1.2;
if (dist > scv.getDistance(buildTarget))
continue;
Area mineralArea = gameState.bwem.getMap().getArea(mineralPatch.getTilePosition());
Area workerArea = gameState.bwem.getMap().getArea(scv.getTilePosition());
if (mineralPatch.equals(scv.getTargetUnit()) && mineralArea != null && mineralArea.equals(workerArea))
continue;
if (dist < bestDist) {
bestDist = dist;
closerMineral = mineralPatch;
}
}
return closerMineral;
}
use of org.openbw.bwapi4j.unit.SCV in project Ecgberht by Jabbo16.
the class CheckMineralWalkGoldRush method execute.
@Override
public State execute() {
try {
if (gameState.walkingMinerals.isEmpty())
return State.SUCCESS;
for (Map.Entry<SCV, MutablePair<UnitType, TilePosition>> u : gameState.workerBuild.entrySet()) {
if (u.getValue().first != UnitType.Terran_Command_Center)
continue;
SCV scv = u.getKey();
Unit movingMineral = u.getKey().getTargetUnit();
if (movingMineral == null) {
MineralPatch target = getCloserMineral(u);
if (target == null) {
if (scv.getOrderTarget() != null && scv.getOrder() != Order.Move) {
scv.move(u.getValue().second.toPosition());
}
continue;
}
if (!target.equals(scv.getTargetUnit()))
scv.rightClick(target, false);
} else if (scv.getDistance(movingMineral) < 32) {
scv.move(u.getValue().second.toPosition());
}
}
return State.SUCCESS;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
Aggregations