How do you build a refinery???

107 views
Skip to first unread message

Panagiotis Peikidis

unread,
May 7, 2010, 5:23:21 AM5/7/10
to BWAPI JBridge
Ermmmmm.... I tried building a terran refinery as follows:

Unit worker = UnitUtils.getUnitType(game, UnitType.TERRAN_SCV);
Unit gas = ResourceManager.getClosestGas(game, worker);
worker.build(new TilePosition(gas.getPosition()),
UnitType.TERRAN_REFINERY);

But nothing happens. I think the problem relies on the new
TilePosition(gas.getPosition()) part, but I don't know the solution!

Any help?

Thank you.

Panagiotis Peikidis

unread,
May 7, 2010, 5:40:30 AM5/7/10
to BWAPI JBridge
OK... After many hours of digging, I finally found that the
getClosestGas returned a geyser that was not visible......
Here is the code:

public static Unit getClosestGas(Game game, Unit unit) {
Unit patch = null;
double closest = Double.MAX_VALUE;

for (Unit gas : game.getGeysers()) {
if (!gas.isVisible()) continue; // this fixed it
double dx = unit.getPosition().x() - gas.getPosition().x();
double dy = unit.getPosition().y() - gas.getPosition().y();
double dist = Math.sqrt(dx*dx + dy*dy);

if (dist < closest) {
patch = gas;
closest = dist;
}
}

return patch;
}

But still, I don't understand why wasn't the geyser next to the base
the closest... Is there something wrong with my code?
Reply all
Reply to author
Forward
0 new messages