The TorchCraft replayer is a C++ library with Lua bindings for manipulating StarCraft game state storage.
Here we describe the Lua replayer API; however, the replayer can also be used directly from C++.
The file init.cpp registers the c++ functions to be exposed to Lua.
The torchcraft.Frame
is the basic element of game storage in torchcraft:
it stores a single frame of a game. It contains the full state of the game:
players, units, actions, bullets. It may also contain reward information to
be used for a reinforcement learning algorithm.
Returns a torchcraft.Frame
from a Lua table that has the following
structure:
Insert description here
Returns a torchcraft.Frame
from unserializing a string. This is used
primarily by TorchCraft for receiving data from starcraft.exe
.
Returns a Lua table containing all the frame information
(see replayer.frameFromTable
).
Returns a Lua table containing all the units of the given player.
The table is indexed by unit ID (uid
).
Return the number of players participating in the game.
Returns the total number of units in the frame.
Return the number of units in the frame belonging to given player.
Combine the next_frame
with the current frame. This is useful when frame-
skipping to avoid missing valuable information during the frames you skip.
Effectively, commands and units are accumulated (so we retrieve all the orders
received during the both frames). Please beware that if a unit of current frame
is dead in next_frame
, it will still be present in the combined frame (with its
last known stats). If you want to remove the dead units, you have to filter
them by hand afterward (using torchcraft.state.deaths
)
Reward, bullets, actions and terminal state are NOT accumulated (we keep the value of the next frame).
The torchcraft.Replayer
class is meant to contain sequences of frames,
storing a whole game or only part of it. It also optionally stores map
data for the game.
Creates empty replayer containing no frames.
Loads replayer from file, restoring whole game state.
Saves whole game state from replayer to file.
Returns number of frames in the game.
Returns frame n
, as a torchcraft.Frame
Returns the map data for the game (a 2D Torch ByteTensor). The map contains height information as follows:
- 0: Low ground
- 1: Low ground doodad
- 2: High ground
- 3: High ground doodad
- 4: Very high ground
- 5: Very high ground doodad
A "doodad" is simply a special object in this position. It is purely graphical, and no interaction is possible with it. Sometimes, the tile is still walkable.
If the tile is not walkable, then the corresponding cell contains 255 (aka -1 with an underflow)
Set the map data for the game (a 2D Torch ByteTensor).
Append a torchcraft.Frame
to the replayer.
The torchcraft.GameStore
class is meant to store many replays, categorized
as either "won" or "lost". This class is used in reinforcement learning
algorithms to do experience replay.
Creates a new empty game store, preallocating space for a given number of won and lost games.
Load gamestore from file.
Save gamestore to file.
Add game to gamestore, either in the won set if won is true or in the lost
set otherwise. The game must be a torchcraft.Replayer
.
Sample a game from the gamestore, with probability prop_won
of selecting
a won game. Returns a torchcraft.Replayer
.
Return the number of lost games in the gamestore.
Return the n
last lost battles in the gamestore.
Return the last battle in the gamestore, taking it from the lost or won set accordingly.