TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
Functions
cherrypi::builderhelpers Namespace Reference

Functions

 DEFINE_bool (builderhelper_logfailure, false,"Always log failed placements")
 
std::shared_ptr< UPCTupleupcWithPositionForBuilding (State *state, UPCTuple const &upc, BuildType const *type)
 Refine a building UPC by selecting a dirac location according. More...
 
template<typename ScoreFunc >
Position findBuildLocation (State *state, std::vector< Position > const &seeds, BuildType const *type, UPCTuple const &upc, ScoreFunc &&scoreFunc)
 
Position findBuildLocation (State *state, std::vector< Position > const &seeds, BuildType const *type, UPCTuple const &upc)
 Find location to construct the building. More...
 
Position findBuildLocation (State *state, std::vector< Position > const &seeds, BuildType const *type, UPCTuple const &upc, std::function< double(State *, const BuildType *, const Tile *)> scoreFunc)
 
bool canBuildAt (State *state, const BuildType *type, const Position &pos, bool ignoreReserved=false, bool logFailure=false)
 Check whether the building can be constructed at specified location. More...
 
bool checkCreepAt (State *state, const BuildType *type, const Position &pos)
 Check whether there is enough creep for the building at the specified position. More...
 
UnitfindGeyserForRefinery (State *state, BuildType const *type, UPCTuple const &upc)
 Find a free Vespene Geyser for a refinery. More...
 
Position findRefineryLocation (State *state, BuildType const *type, UPCTuple const &upc)
 Find Vespene Geyser location for a refinery. More...
 
void dumpMap (const std::string &fname, std::function< bool(const Tile *)> predicate, State *state, const std::vector< Position > &candidateLocations)
 
Position findResourceDepotLocation (State *state, const BuildType *type, const std::vector< Position > &candidateLocations, bool isExpansion=true)
 Find location for a new resource depot. More...
 
std::vector< PositioncandidateExpansionResourceDepotLocations (State *state)
 Use map information to produce candidate resource depot locations sorted by their proximity to the main base. More...
 
std::list< std::pair< Position, int > > candidateExpansionResourceDepotLocationsDistances (State *state)
 Use map information to produce candidate resource depot locations sorted by their proximity to the main base. More...
 
std::vector< PositionbuildLocationSeeds (State *state, BuildType const *type, UPCTuple const &upc, Unit *builder=nullptr)
 Produce seed locations for the building. More...
 
std::string buildLocationMasks (State *state, const BuildType *type, const Position &pos)
 Produces string representation of masks (buildable, building, reservedAsUnbuildable, resourceDepotUnbuildable, reservedForResourceDepot) around the provided build location. More...
 
void fullReserve (TilesInfo &tt, BuildType const *type, Position const &pos)
 Sets Tile::reservedAsUnbuildable to reserve the tiles occupied by a given building type when placed at pos. More...
 
void fullUnreserve (TilesInfo &tt, BuildType const *type, Position const &pos)
 Clears Tile::reservedAsUnbuildable to free the tiles occupied by a given building type when placed at pos. More...
 

Function Documentation

std::string cherrypi::builderhelpers::buildLocationMasks ( State state,
const BuildType type,
const Position pos 
)

Produces string representation of masks (buildable, building, reservedAsUnbuildable, resourceDepotUnbuildable, reservedForResourceDepot) around the provided build location.

Used for verbose logs mostly for debugging purposes.

Parameters
stateBot's state
typeBuilding type
posCoordinates of an upper-left corner of the proposed location (in walktiles)
Returns
String containing masks, where '1' (or '+' outside the building area) stands for true, '0' (or '-') for false, 'X' for cells over the map edge
std::vector< Position > cherrypi::builderhelpers::buildLocationSeeds ( State state,
BuildType const *  type,
UPCTuple const &  upc,
Unit builder = nullptr 
)

Produce seed locations for the building.

Parameters
stateBot's state
typeBuilding type
upcUPCTuple with possible restrictions regarding position
builderUnit selected to construct the building, nullptr if not yet selected
Returns
Proposed seed locations (in walktiles)
bool cherrypi::builderhelpers::canBuildAt ( State state,
const BuildType type,
const Position pos,
bool  ignoreReserved = false,
bool  logFailure = false 
)

Check whether the building can be constructed at specified location.

Parameters
stateBot's state
typeType of the building
posLocation to be checked
std::vector< Position > cherrypi::builderhelpers::candidateExpansionResourceDepotLocations ( State state)

Use map information to produce candidate resource depot locations sorted by their proximity to the main base.

std::list< std::pair< Position, int > > cherrypi::builderhelpers::candidateExpansionResourceDepotLocationsDistances ( State state)

Use map information to produce candidate resource depot locations sorted by their proximity to the main base.

bool cherrypi::builderhelpers::checkCreepAt ( State state,
const BuildType type,
const Position pos 
)

Check whether there is enough creep for the building at the specified position.

If the building does not require creep, checks that there isn't any. Does not anticipate creep.

Parameters
stateBot's state
typeType of the building
posLocation to be checked
cherrypi::builderhelpers::DEFINE_bool ( builderhelper_logfailure  ,
false  ,
"Always log failed placements"   
)
void cherrypi::builderhelpers::dumpMap ( const std::string &  fname,
std::function< bool(const Tile *)>  predicate,
State state,
const std::vector< Position > &  candidateLocations 
)
template<typename ScoreFunc >
Position cherrypi::builderhelpers::findBuildLocation ( State state,
std::vector< Position > const &  seeds,
BuildType const *  type,
UPCTuple const &  upc,
ScoreFunc &&  scoreFunc 
)
Position cherrypi::builderhelpers::findBuildLocation ( State state,
std::vector< Position > const &  seeds,
BuildType const *  type,
UPCTuple const &  upc 
)

Find location to construct the building.

Parameters
stateBot's state
seedsSeed locations for building location search
typeType of the building
upcUPCTuple with possible restrictions regarding position
Returns
Location to construct the building; (-1, -1) if no suitable location was found
Position cherrypi::builderhelpers::findBuildLocation ( State state,
std::vector< Position > const &  seeds,
BuildType const *  type,
UPCTuple const &  upc,
std::function< double(State *, const BuildType *, const Tile *)>  scoreFunc 
)
Unit * cherrypi::builderhelpers::findGeyserForRefinery ( State state,
BuildType const *  type,
UPCTuple const &  upc 
)

Find a free Vespene Geyser for a refinery.

Parameters
stateBot's state
typeBuilding type of the refinery
upcUPCTuple with possible restrictions regarding position
Returns
Unit that corresponds to the Vespene Geyser on which to build the refinery; nullptr if no suitable Vespene Geyser could be found
Position cherrypi::builderhelpers::findRefineryLocation ( State state,
BuildType const *  type,
UPCTuple const &  upc 
)

Find Vespene Geyser location for a refinery.

Parameters
stateBot's state
typeBuilding type of the refinery
upcUPCTuple with possible restrictions regarding position
Returns
Location that corresponds to the Vespene Geyser on which to build the refinery; (-1, -1) if no suitable location could be found
Position cherrypi::builderhelpers::findResourceDepotLocation ( State state,
const BuildType type,
const std::vector< Position > &  candidateLocations,
bool  isExpansion = true 
)

Find location for a new resource depot.

Parameters
stateBot's state
typeType of the building
candidateLocationsCandidate locations for resource depots, sorted in the order of location preference - the most preferred comes first
Returns
Proposed resource depot location (in walktiles) or (-1, -1), if no suitable location was found
void cherrypi::builderhelpers::fullReserve ( TilesInfo tt,
BuildType const *  type,
Position const &  pos 
)

Sets Tile::reservedAsUnbuildable to reserve the tiles occupied by a given building type when placed at pos.

void cherrypi::builderhelpers::fullUnreserve ( TilesInfo tt,
BuildType const *  type,
Position const &  pos 
)

Clears Tile::reservedAsUnbuildable to free the tiles occupied by a given building type when placed at pos.

std::shared_ptr< UPCTuple > cherrypi::builderhelpers::upcWithPositionForBuilding ( State state,
UPCTuple const &  upc,
BuildType const *  type 
)

Refine a building UPC by selecting a dirac location according.

This will use a combination of the individual rules defined in this namespace.

Parameters
upcSource UPC
typeA concrete building type selected from the source UPC