use of org.bk.ass.sim.Agent 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 org.bk.ass.sim.Agent 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