[solved]Colonizing Mexes with java wrapper
Posted: 23 May 2014, 00:27
This is a (dysfunctional) method that should return the closest AIFloat3 with a metal spot on it that is not already taken (assuming no enemies). I've been debugging it for like 3 days, but I still haven't found the cause.
locs is an arrayList of all the metal locations. manage.getAllUnitPos() is a method that returns all the locations of my units.
This method is supposed to traverse through all the locations, then see if the location is shorter than the current location, and if it is already occupied.
locs is an arrayList of all the metal locations. manage.getAllUnitPos() is a method that returns all the locations of my units.
This method is supposed to traverse through all the locations, then see if the location is shorter than the current location, and if it is already occupied.
Code: Select all
public AIFloat3 getClosestMetalSpot(Unit uni){
AIFloat3 ans = locs.get(0);
float minDistance = getDistancebetween(uni.getPos(), locs.get(0));
for(AIFloat3 loc: locs){
boolean collision = false;
if(getDistancebetween(uni.getPos(), loc)<minDistance){
for(AIFloat3 occuLoc:manage.getAllUnitPos()){
if(loc.equals(occuLoc)){
collision = true;
}
}
if(!collision){
ans = loc;
minDistance = getDistancebetween(uni.getPos(), loc);
}
}
}
return ans;
}