TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
cherrypi::UPCTuple Struct Reference

(Unit, Position, Command) tuple. More...

#include <upc.h>

Public Types

using Empty = char
 An empty default item for the variants defined below. More...
 
using UnitMap = std::unordered_map< Unit *, float >
 
using CommandMap = std::unordered_map< Command, float >
 
using BuildTypeMap = std::unordered_map< BuildType const *, float >
 
using SetCreatePriorityState = std::tuple< UpcId, float >
 
using UnitT = UnitMap
 A typedef for the unit distribution. More...
 
using PositionT = mapbox::util::variant< Empty, Position, Area *, UnitMap, torch::Tensor >
 A typedef for the position distribution. More...
 
using CommandT = CommandMap
 A typedef for the command distribution. More...
 
using StateT = mapbox::util::variant< Empty, BuildTypeMap, std::string, Position, SetCreatePriorityState, torch::Tensor >
 A typedef for additional structured information ("state"). More...
 

Public Member Functions

std::pair< Position, float > positionArgMax () const
 Returns argmax and probability of position distribution. More...
 
std::pair< Unit *, float > positionUArgMax () const
 Returns argmax and probability of position distribution over units. More...
 
float positionProb (int x, int y) const
 Returns the probability of a given position. More...
 
float commandProb (Command c) const
 Returns the probability of a given command. More...
 
torch::Tensor positionTensor (State *state) const
 Returns walk tile resolution tensor of position probabilities. More...
 
std::pair< BuildType const *, float > createTypeArgMax () const
 Returns argmax and probability of the BuildTypeMap distribution in the UPC's state field. More...
 

Static Public Member Functions

static CommandT uniformCommand ()
 Creates a uniform distribution over all game commands. More...
 

Public Attributes

UnitT unit
 A distribution over units that we can control. More...
 
PositionT position
 A distribution over positions. More...
 
CommandT command
 A distribution over abstract game commands. More...
 
StateT state
 An auxiliary state that can be used to pass additional information. More...
 
int scale = 1
 Specifies the (inverse) scale of the position tensor or the single sharp position. More...
 

Detailed Description

(Unit, Position, Command) tuple.

Specifies the (who, where, what) of an action

UPCTuples are used for module-to-module communication (via the Blackboard). Posting a UPCTuple to the Blackboard is akin to requesting a specific action from another module, and consuming a UPCTuple from the Blackboard implies that the consumer implements this action. The implementation can also consist of refining the UPCTuple so that a more lower-level module can actually execute it.

For example, a build order module might post a UPCTuple to create a certain unit type, and a builder module might wait until their are sufficient resources before consuming it and then select a worker and a location.

The UPCToCommandModule translates executable UPCTuples (ones with sharp unit, position and command entries) to actual game commands.

Member Typedef Documentation

using cherrypi::UPCTuple::BuildTypeMap = std::unordered_map<BuildType const*, float>
using cherrypi::UPCTuple::CommandMap = std::unordered_map<Command, float>

A typedef for the command distribution.

An empty default item for the variants defined below.

using cherrypi::UPCTuple::PositionT = mapbox::util::variant<Empty, Position, Area*, UnitMap, torch::Tensor>

A typedef for the position distribution.

Possible values:

  • Empty: unspecified position, i.e. uniform over the entire map
  • Position: A single x/y position with probability of one. This is more efficient then having a one-hot position tensor.
  • Area*: An area so that every position in this area has probability 1/(walktiles in area), and every position outside has probability 0.
  • UnitMap: A distribution over units which can be used instead of position. Sometimes it is more efficient to specify target units directly (e.g. for resource mining or for attacks).
  • torch::Tensor: A distribution over the whole map. First dimension is Y, second is X.
using cherrypi::UPCTuple::StateT = mapbox::util::variant< Empty, BuildTypeMap, std::string, Position, SetCreatePriorityState, torch::Tensor>

A typedef for additional structured information ("state").

Possible values:

  • Empty: unspecified state
  • BuildTypeMap: A distribution over unit types. This is useful for UPCs with the "Create" command.
  • std::string: An arbitrary string.
  • Position: An arbitrary position.
  • torch::Tensor: An arbitrary tensor.
using cherrypi::UPCTuple::UnitMap = std::unordered_map<Unit*, float>

A typedef for the unit distribution.

Member Function Documentation

float cherrypi::UPCTuple::commandProb ( Command  c) const

Returns the probability of a given command.

std::pair< BuildType const *, float > cherrypi::UPCTuple::createTypeArgMax ( ) const

Returns argmax and probability of the BuildTypeMap distribution in the UPC's state field.

If the UPC specifies a different type of state, this function will return (nullptr, 0.0f)

std::pair< Position, float > cherrypi::UPCTuple::positionArgMax ( ) const

Returns argmax and probability of position distribution.

float cherrypi::UPCTuple::positionProb ( int  x,
int  y 
) const

Returns the probability of a given position.

torch::Tensor cherrypi::UPCTuple::positionTensor ( State state) const

Returns walk tile resolution tensor of position probabilities.

std::pair< Unit *, float > cherrypi::UPCTuple::positionUArgMax ( ) const

Returns argmax and probability of position distribution over units.

UPCTuple::CommandT cherrypi::UPCTuple::uniformCommand ( )
static

Creates a uniform distribution over all game commands.

Member Data Documentation

CommandT cherrypi::UPCTuple::command

A distribution over abstract game commands.

PositionT cherrypi::UPCTuple::position

A distribution over positions.

int cherrypi::UPCTuple::scale = 1

Specifies the (inverse) scale of the position tensor or the single sharp position.

For efficiency reasons, position tensors can be specified at a coarser resolution.

StateT cherrypi::UPCTuple::state

An auxiliary state that can be used to pass additional information.

Interpretation of this is entirely context-dependent.

UnitT cherrypi::UPCTuple::unit

A distribution over units that we can control.


The documentation for this struct was generated from the following files: