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?