TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
Classes | Enumerations | Functions
cherrypi::bos Namespace Reference

Classes

struct  ModelRunner
 Helper class for running BOS models. More...
 
struct  Sample
 
struct  StaticData
 

Enumerations

enum  BosFeature {
  BosFeature::Undef, BosFeature::Map, BosFeature::MapId, BosFeature::Race,
  BosFeature::Units, BosFeature::BagOfUnitCounts, BosFeature::BagOfUnitCountsAbs5_15_30, BosFeature::Resources5Log,
  BosFeature::TechUpgradeBits, BosFeature::PendingTechUpgradeBits, BosFeature::TimeAsFrame, BosFeature::ActiveBo,
  BosFeature::NextBo
}
 A list of possible features that can be extracted from a Sample. More...
 

Functions

ag::Container modelMakeFromCli (double dropout=0.0)
 Construct a BOS module according to command-line flags. More...
 
std::map< std::string, std::string > modelFlags ()
 
 AUTOGRAD_CONTAINER_CLASS (IdleModel)
 
 AUTOGRAD_CONTAINER_CLASS (MapRaceEcoTimeFeaturize)
 
 AUTOGRAD_CONTAINER_CLASS (LinearModel)
 
 AUTOGRAD_CONTAINER_CLASS (MlpModel)
 
 AUTOGRAD_CONTAINER_CLASS (LstmModel)
 
 AUTOGRAD_CONTAINER_CLASS (ConvEncLstmModel)
 
std::unique_ptr< ModelRunnermakeModelRunner (ag::Container model, std::string modelType)
 
std::map< std::string, int64_t > const & buildOrderMap ()
 
std::vector< std::string > const & targetBuilds ()
 
std::string allowedTargetsAsFlag ()
 
std::string allowedOpeningsAsFlag ()
 
torch::Tensor getBuildOrderMaskByRace (char race)
 
torch::Tensor getBuildOrderMaskByRace (int race)
 
int64_t mapId (torch::Tensor mapFeats)
 
char getOpponentRace (std::string const &opponent)
 
std::string addRacePrefix (std::string buildOrder, char prefix)
 
std::string addRacePrefix (std::string buildOrder, int race)
 
std::string stripRacePrefix (std::string prefixedBo)
 
int64_t buildOrderId (std::string const &bo)
 

Enumeration Type Documentation

A list of possible features that can be extracted from a Sample.

Enumerator
Undef 
Map 

Map features from StaticData.

MapId 

Map "ID" based on sum of map features.

Race 

2-dimensional: our and their race

Units 

Defogger-style pooled unit types.

BagOfUnitCounts 

Bag-of-words unit type counts.

BagOfUnitCountsAbs5_15_30 

Bag-of-words unit type counts in future autobuild states (ours only)

Resources5Log 

Ore/Gas/UsedPsi/TotalPsi: log(x / 5 + 1)

TechUpgradeBits 

142-dim tech/upgrade vector: one bit for each upgrade/level/tech

PendingTechUpgradeBits 

142-dim vector of pending upgrades/techs

TimeAsFrame 

Numerical frame value.

ActiveBo 

Id of active build order.

NextBo 

Id of next build order.

Function Documentation

std::string cherrypi::bos::addRacePrefix ( std::string  buildOrder,
char  prefix 
)
inline
std::string cherrypi::bos::addRacePrefix ( std::string  buildOrder,
int  race 
)
inline
std::string cherrypi::bos::allowedOpeningsAsFlag ( )
std::string cherrypi::bos::allowedTargetsAsFlag ( )
cherrypi::bos::AUTOGRAD_CONTAINER_CLASS ( IdleModel  )
cherrypi::bos::AUTOGRAD_CONTAINER_CLASS ( MapRaceEcoTimeFeaturize  )

Expected input:

  • a Bx1 tensor containing the map ID,
  • a Bx2 tensor containing the races,
  • a Bx4 tensor containing resource features.
  • a Bx142 tensor containing upgrades and techonology features.
  • a Bx142 tensor containing pending upgrades and techonology features.
  • a Bx1 tensor containing the current time (in frames)
  • a Bx1 tensor containing the active build

B can also be TxB.

Returns:

  • a BxN tensor, with N being the sum of all embeddings
cherrypi::bos::AUTOGRAD_CONTAINER_CLASS ( LinearModel  )

Expected input: Dictionary with "features" as tensor vector:

  • a BxF tensor containing the unit type counts (F = n_unit_types)
  • a BxF tensor containing our future unit type counts (F = n_unit_types / 2
  • 3)
  • a Bx1 tensor containing the map ID.
  • a Bx2 tensor containing the races,
  • a Bx4 tensor containing resource features.
  • a Bx142 tensor containing upgrades and techonology features.
  • a Bx142 tensor containing pending upgrades and techonology features.
  • a Bx1 tensor containing the current time (in frames)
  • a Bx1 tensor containing the active build

Returns an unordered_map:

  • "vHeads": predicted values p(win) for all builds, masked wrt opponent race
  • "Pi": softmax over p(win), masked wrt opponent race
  • "V": overall value function – currently just zeros
cherrypi::bos::AUTOGRAD_CONTAINER_CLASS ( MlpModel  )

Expected input: Dictionary with "features" as tensor vector:

  • a BxF tensor containing the unit type counts (F = n_unit_types)
  • a BxF tensor containing our future unit type counts (F = n_unit_types / 2
  • 3)
  • a Bx1 tensor containing the map ID.
  • a Bx2 tensor containing the races,
  • a Bx4 tensor containing resource features.
  • a Bx142 tensor containing upgrades and techonology features.
  • a Bx142 tensor containing pending upgrades and techonology features.
  • a Bx1 tensor containing the current time (in frames)
  • a Bx1 tensor containing the active build

Returns an unordered_map:

  • "vHeads": predicted values p(win) for all builds, masked wrt opponent race
  • "Pi": softmax over p(win), masked wrt opponent race
  • "V": overall value function – currently just zeros
cherrypi::bos::AUTOGRAD_CONTAINER_CLASS ( LstmModel  )

Expected input: Dictionary with "features" as tensor vector:

  • a TxBxF tensor containing the unit type counts (F = n_unit_types)
  • a TxBxF tensor containing our future unit type counts (F = n_unit_types / 2 * 3)
  • a TxBx1 tensor containing the map ID.
  • a 1xBx2 tensor containing the races,
  • a TxBx4 tensor containing resource features.
  • a TxBx142 tensor containing upgrades and techonology features.
  • a TxBx142 tensor containing pending upgrades and techonology features.
  • a TxBx1 tensor containing the current time (in frames)
  • a TxBx1 tensor containing the active build And optionally
  • "hidden": hidden activations for the LSTMs

The 'T' dimension may be omitted.

Returns an unordered_map:

  • "vHeads": predicted values p(win) for all builds, masked wrt opponent race
  • "Pi": softmax over p(win), masked wrt opponent race
  • "V": overall value function – currently just zeros
  • "hidden": the hidden state
cherrypi::bos::AUTOGRAD_CONTAINER_CLASS ( ConvEncLstmModel  )

Expected input: Dictionary with "features" as tensor vector:

  • a 1xBxCxhxw tensor containing the map features,
  • a TxBx1 tensor containing the map ID.
  • a 1xBx2 tensor containing the races,
  • a TxBxFxHxW tensor containing the units features,
  • a TxBxF tensor containing the unit type counts (F = n_unit_types)
  • a TxBxF tensor containing our future unit type counts (F = n_unit_types / 2 * 3)
  • a TxBx4 tensor containing resource features.
  • a TxBx142 tensor containing upgrades and techonology features.
  • a TxBx142 tensor containing pending upgrades and techonology features.
  • a TxBx1 tensor containing the current frame number
  • a TxBx1 tensor containing the active build And optionally
  • "hidden": hidden activations for the LSTMs

The 'T' dimension may be omitted.

Returns an unordered_map:

  • "vHeads": predicted values p(win) for all builds, masked wrt opponent race
  • "Pi": softmax over p(win), masked wrt opponent race
  • "V": overall value function – currently just zeros
  • "hidden": the hidden state
int64_t cherrypi::bos::buildOrderId ( std::string const &  bo)
inline
std::map< std::string, int64_t > const & cherrypi::bos::buildOrderMap ( )
torch::Tensor cherrypi::bos::getBuildOrderMaskByRace ( char  race)
torch::Tensor cherrypi::bos::getBuildOrderMaskByRace ( int  race)
char cherrypi::bos::getOpponentRace ( std::string const &  opponent)
inline
std::unique_ptr< ModelRunner > cherrypi::bos::makeModelRunner ( ag::Container  model,
std::string  modelType 
)
int64_t cherrypi::bos::mapId ( torch::Tensor  mapFeats)
std::map< std::string, std::string > cherrypi::bos::modelFlags ( )
ag::Container cherrypi::bos::modelMakeFromCli ( double  dropout)

Construct a BOS module according to command-line flags.

std::string cherrypi::bos::stripRacePrefix ( std::string  prefixedBo)
inline
std::vector< std::string > const & cherrypi::bos::targetBuilds ( )