Find nearby units?

Anything related on how to build / improve your AI using BWAPI, BWTA, BWSAL, etc.
Posts: 3
Joined: Thu Mar 25, 2010 7:03 pm

Find nearby units?

Postby briglass » Mon Jun 07, 2010 8:00 pm

Is there a fast/easy way to find nearby units of a specified unit?

A google search points to a now nonexistent post that mentioned "findNearbyUnit"

User avatar
Posts: 92
Joined: Sat Jun 21, 2008 11:50 pm

Postby lowerlogic » Mon Jun 07, 2010 11:24 pm

You could get the tile position of the unit and then call Game::unitsOnTile for all nearby tiles (this info is cached every frame anyway).

If you are using BWSAL, you could use:

Code: Select all

std::set<Unit*> nearbyUnits(Unit* unit, double radius = 400.0)
  return AllUnits().inRadius(radius,unit->getPosition());

though this checks ever accessible unit to see if it is in range, so it probably isn't fast when lots of units exist.

Return to “AI development (BWAPI Bots)”

Who is online

Users browsing this forum: No registered users and 1 guest