TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
|
An access-aware blackboard. More...
#include <blackboard.h>
Public Types | |
using | Data = mapbox::util::variant< bool, int, float, double, std::string, Position, std::shared_ptr< SharedController >, std::unordered_map< int, int >> |
A variant of types that are allowed in the Blackboard's key-value storage. More... | |
using | UPCMap = std::map< UpcId, std::shared_ptr< UPCTuple >> |
using | TaskTimeStats = std::tuple< UpcId, std::string, std::chrono::milliseconds > |
Public Member Functions | |
Blackboard (State *state) | |
virtual | ~Blackboard () |
void | init () |
void | clearCommands () |
Clears the queue of commands. More... | |
void | update () |
Updates internal mappings after the torchcraft state has been updated. More... | |
void | post (std::string const &key, Data const &data) |
bool | hasKey (std::string const &key) |
Data const & | get (std::string const &key) const |
template<typename T > | |
T const & | get (std::string const &key) const |
template<typename T > | |
T const & | get (std::string const &key, T const &defaultValue) const |
void | remove (std::string const &key) |
template<typename T > | |
void | iterValues (T f_do) const |
bool | isTracked (UnitId uid) const |
void | track (UnitId uid) |
void | untrack (UnitId uid) |
UpcId | postUPC (std::shared_ptr< UPCTuple > &&upc, UpcId sourceId, Module *origin, std::shared_ptr< UpcPostData > data=nullptr) |
Post a UPC tuple. More... | |
void | consumeUPCs (std::vector< UpcId > const &ids, Module *consumer) |
void | consumeUPC (UpcId id, Module *consumer) |
void | removeUPCs (std::vector< UpcId > const &ids) |
UPCMap | upcs () const |
Returns all non-consumed UPCs. More... | |
UPCMap | upcsFrom (Module *origin) const |
Returns all non-consumed UPCs from a given module. More... | |
UPCMap | upcsFrom (std::shared_ptr< Module > origin) const |
Returns all non-consumed UPCs from a given module. More... | |
UPCMap | upcsWithSharpCommand (Command cmd) const |
Returns all non-consumed UPCs with a Dirac command distribution on cmd. More... | |
UPCMap | upcsWithCommand (Command cmd, float minProb) const |
Returns all non-consumed UPCs with a command distribution where cmd has at least a probability of minProb. More... | |
std::shared_ptr< UPCTuple > | upcWithId (UpcId id) const |
Returns the non-consumed UPC with the given ID. More... | |
UpcStorage * | upcStorage () const |
void | addUPCFilter (std::shared_ptr< UPCFilter > filter) |
void | removeUPCFilter (std::shared_ptr< UPCFilter > filter) |
void | postTask (std::shared_ptr< Task > task, Module *owner, bool autoRemove=false) |
std::shared_ptr< Task > | taskForId (UpcId id) const |
std::vector< std::shared_ptr< Task > > | tasksOfModule (Module *module) const |
std::shared_ptr< Task > | taskWithUnit (Unit *unit) const |
TaskData | taskDataWithUnit (Unit *unit) const |
std::shared_ptr< Task > | taskWithUnitOfModule (Unit *unit, Module *module) const |
void | markTaskForRemoval (UpcId upcId) |
void | markTaskForRemoval (std::shared_ptr< Task > task) |
TaskStatus | lastStatusOfTask (UpcId id) const |
This will return Unknown for tasks that were never registered. More... | |
void | updateUnitAccessCounts (tc::Client::Command const &command) |
void | postCommand (tc::Client::Command const &command, UpcId sourceId) |
std::vector< tc::Client::Command > | commands (int stepsBack=0) const |
size_t | pastCommandsAvailable () const |
void | updateTasksByUnit (Task *task) |
Updates the taskByUnit mapping, should be called after setUnits on a task. More... | |
void | checkPostStep () |
UPC consistency checks Calling this only makes sense in the player's postStep function, once all the UPCs have been converted into commands to be posted to the game. More... | |
std::vector< TaskTimeStats > | getTaskTimeStats () const |
void | setCollectTimers (bool collect) |
void | setTraceDumper (std::shared_ptr< CherryVisDumperModule > tracer) |
std::shared_ptr< CherryVisDumperModule > | getTraceDumper () |
Static Public Attributes | |
static char const * | kEnemyRaceKey = "enemy_race" |
static char const * | kEnemyNameKey = "enemy_name" |
static char const * | kBuildOrderKey = "buildorder" |
static char const * | kBuildOrderSwitchEnabledKey |
static char const * | kOpeningBuildOrderKey = "opening_buildorder" |
static char const * | kMinScoutFrameKey = "scout_min_frame" |
static char const * | kMaxScoutWorkersKey = "scout_max_workers" |
static char const * | kMaxScoutExplorersKey = "scout_max_explorers" |
static char const * | kGameUidKey = "game_uid" |
static char const * | kMineralsPerFramePerGatherer |
static char const * | kGasPerFramePerGatherer = "gas_per_frame_per_gatherer" |
static char const * | kGathererMinGasWorkers = "gatherer_min_gas_workers" |
static char const * | kGathererMaxGasWorkers = "gatherer_max_gas_workers" |
static char const * | kBanditRootKey = "bandit_root" |
An access-aware blackboard.
The blackboard provides a means for modules to exchange UPCTuples while keeping track of producers and consumers.
Furthermore, there is functionality for holding global state via a simple key-value store (post(), hasKey(), get() and remove()).
The blackboard itself will only store active UPCTuple objects, i.e. UPCs that have not been consumed and UPCs (as well as their sources) for which there are active tasks.
using cherrypi::Blackboard::Data = mapbox::util::variant< bool, int, float, double, std::string, Position, std::shared_ptr<SharedController>, std::unordered_map<int, int>> |
A variant of types that are allowed in the Blackboard's key-value storage.
using cherrypi::Blackboard::TaskTimeStats = std::tuple<UpcId, std::string, std::chrono::milliseconds> |
using cherrypi::Blackboard::UPCMap = std::map<UpcId, std::shared_ptr<UPCTuple>> |
cherrypi::Blackboard::Blackboard | ( | State * | state | ) |
|
virtual |
void cherrypi::Blackboard::addUPCFilter | ( | std::shared_ptr< UPCFilter > | filter | ) |
void cherrypi::Blackboard::checkPostStep | ( | ) |
UPC consistency checks Calling this only makes sense in the player's postStep function, once all the UPCs have been converted into commands to be posted to the game.
void cherrypi::Blackboard::clearCommands | ( | ) |
Clears the queue of commands.
std::vector< tc::Client::Command > cherrypi::Blackboard::commands | ( | int | stepsBack = 0 | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void cherrypi::Blackboard::init | ( | ) |
bool cherrypi::Blackboard::isTracked | ( | UnitId | uid | ) | const |
|
inline |
TaskStatus cherrypi::Blackboard::lastStatusOfTask | ( | UpcId | id | ) | const |
This will return Unknown
for tasks that were never registered.
void cherrypi::Blackboard::markTaskForRemoval | ( | UpcId | upcId | ) |
|
inline |
|
inline |
|
inline |
void cherrypi::Blackboard::postCommand | ( | tc::Client::Command const & | command, |
UpcId | sourceId | ||
) |
void cherrypi::Blackboard::postTask | ( | std::shared_ptr< Task > | task, |
Module * | owner, | ||
bool | autoRemove = false |
||
) |
UpcId cherrypi::Blackboard::postUPC | ( | std::shared_ptr< UPCTuple > && | upc, |
UpcId | sourceId, | ||
Module * | origin, | ||
std::shared_ptr< UpcPostData > | data = nullptr |
||
) |
Post a UPC tuple.
The UPC tuple will be subject to filtering via UPCFilter objects. The filtered UPCTuple object will end up in the Blackboard, and the function will return a resulting UPC ID that is unique for this Blackboard instance. If the UPCTuple was rejected by a filter, kFilteredUpcId will be returned.
The signature of this function enforces posting UPC tuples via move() as UPC filters modify UPC tuples by creating a copy of them. Hence, the UPCTuple instance ending up in the Blackboard might be different from the one provided to this function.
|
inline |
void cherrypi::Blackboard::removeUPCFilter | ( | std::shared_ptr< UPCFilter > | filter | ) |
void cherrypi::Blackboard::removeUPCs | ( | std::vector< UpcId > const & | ids | ) |
void cherrypi::Blackboard::setCollectTimers | ( | bool | collect | ) |
|
inline |
std::shared_ptr< Task > cherrypi::Blackboard::taskWithUnitOfModule | ( | Unit * | unit, |
Module * | module | ||
) | const |
void cherrypi::Blackboard::track | ( | UnitId | uid | ) |
void cherrypi::Blackboard::untrack | ( | UnitId | uid | ) |
Blackboard::UPCMap cherrypi::Blackboard::upcs | ( | ) | const |
Returns all non-consumed UPCs.
Blackboard::UPCMap cherrypi::Blackboard::upcsFrom | ( | Module * | origin | ) | const |
Returns all non-consumed UPCs from a given module.
Returns all non-consumed UPCs from a given module.
UpcStorage * cherrypi::Blackboard::upcStorage | ( | ) | const |
Blackboard::UPCMap cherrypi::Blackboard::upcsWithCommand | ( | Command | cmd, |
float | minProb | ||
) | const |
Returns all non-consumed UPCs with a command distribution where cmd has at least a probability of minProb.
Blackboard::UPCMap cherrypi::Blackboard::upcsWithSharpCommand | ( | Command | cmd | ) | const |
Returns all non-consumed UPCs with a Dirac command distribution on cmd.
Returns the non-consumed UPC with the given ID.
void cherrypi::Blackboard::update | ( | ) |
Updates internal mappings after the torchcraft state has been updated.
void cherrypi::Blackboard::updateTasksByUnit | ( | Task * | task | ) |
Updates the taskByUnit mapping, should be called after setUnits on a task.
void cherrypi::Blackboard::updateUnitAccessCounts | ( | tc::Client::Command const & | command | ) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |