use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class ChooseScout method execute.
@Override
public State execute() {
try {
if (gameState.getStrat().name.equals("PlasmaWraithHell")) {
for (Squad s : gameState.sqManager.squads.values()) {
for (UnitInfo u : s.members) {
if (u.unit instanceof Wraith) {
gameState.chosenScout = (MobileUnit) u.unit;
s.members.remove(u);
return State.SUCCESS;
}
}
}
}
if (!gameState.workerIdle.isEmpty()) {
Worker chosen = gameState.workerIdle.iterator().next();
gameState.chosenScout = chosen;
gameState.workerIdle.remove(chosen);
}
if (gameState.chosenScout == null) {
for (Worker u : gameState.workerMining.keySet()) {
if (!u.isCarryingMinerals()) {
gameState.chosenScout = u;
MineralPatch mineral = gameState.workerMining.get(u);
if (gameState.mineralsAssigned.containsKey(mineral)) {
gameState.mining--;
gameState.mineralsAssigned.put(mineral, gameState.mineralsAssigned.get(mineral) - 1);
}
gameState.workerMining.remove(u);
break;
}
}
}
if (gameState.chosenScout != null)
return State.SUCCESS;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class WraithAgent method chooseHarassTarget.
private UnitInfo chooseHarassTarget(Set<UnitInfo> mainTargets) {
UnitInfo chosen = null;
double maxScore = Double.MIN_VALUE;
for (UnitInfo u : mainTargets) {
// if (!u.unit.exists()) continue;
double dist = unitInfo.getDistance(u);
double score = u.unitType.isWorker() ? 5 : (u.unitType == UnitType.Zerg_Overlord ? 8 : 1);
WeaponType weapon = Util.getWeapon(unitInfo, u);
score *= dist <= weapon.maxRange() ? 1.4 : 0.9;
score *= (double) u.unitType.maxHitPoints() / (double) u.health;
if (chosen == null || maxScore < score) {
chosen = u;
maxScore = score;
}
}
return chosen;
}
use of ecgberht.UnitInfo 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();
}
}
}
use of ecgberht.UnitInfo in project Ecgberht by Jabbo16.
the class SimulationTheory method createSimInfos.
/**
* Using the clusters creates different SimInfos based on distance between them
*/
private void createSimInfos() {
for (Cluster friend : friendly) {
if (friend.units.isEmpty())
continue;
SimInfo aux = new SimInfo(friend);
for (Cluster enemy : enemies) {
if (enemy.units.isEmpty())
continue;
if (closeClusters(friend, enemy))
aux.enemies.addAll(enemy.units);
}
aux.allies.addAll(friend.units);
simulations.add(aux);
}
List<SimInfo> newSims = new ArrayList<>();
for (SimInfo s : simulations) {
SimInfo air = new SimInfo();
SimInfo ground = new SimInfo();
for (UnitInfo u : s.allies) {
if (u.flying)
air.allies.add(u);
else
ground.allies.add(u);
}
boolean emptyAir = air.allies.isEmpty();
boolean emptyGround = ground.allies.isEmpty();
if (emptyAir && emptyGround)
continue;
for (UnitInfo u : s.enemies) {
if (u.unit instanceof AirAttacker || u.unitType == UnitType.Terran_Bunker)
air.enemies.add(u);
if (u.unit instanceof GroundAttacker || u.unitType == UnitType.Terran_Bunker || u.unitType == UnitType.Zerg_Creep_Colony)
ground.enemies.add(u);
}
air.type = SimInfo.SimType.AIR;
newSims.add(air);
ground.type = SimInfo.SimType.GROUND;
newSims.add(ground);
}
if (!newSims.isEmpty())
simulations.addAll(newSims);
}
use of ecgberht.UnitInfo 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;
}
Aggregations