SC2API
An API for AI for StarCraft II
Public Member Functions | List of all members
sc2::Coordinator Class Reference

Coordinator of one or more clients. Used to start, step and stop games and replays. More...

#include <sc2_coordinator.h>

Public Member Functions

bool LoadSettings (int argc, char **argv)
 
void SetMultithreaded (bool value)
 
void SetRealtime (bool value)
 
void SetStepSize (int step_size)
 
void SetProcessPath (const std::string &path)
 
void SetDataVersion (const std::string &version)
 
void SetTimeoutMS (uint32_t timeout_ms=kDefaultProtoInterfaceTimeout)
 
void SetPortStart (int port_start)
 
void SetFeatureLayers (const FeatureLayerSettings &settings)
 
void SetRender (const RenderSettings &settings)
 
void SetWindowSize (int width, int height)
 
void SetWindowLocation (int x, int y)
 
void SetUseGeneralizedAbilityId (bool value)
 
void AddCommandLine (const std::string &option)
 Appends a command line argument to be fed to StarCraft II when starting.
 
void SetParticipants (const std::vector< PlayerSetup > &participants)
 Sets up the bots and whether they are controlled by in-built AI, human or a custom bot.
 
void SetReplayRecovery (bool value)
 
void AddReplayObserver (ReplayObserver *replay_observer)
 Add an instance of ReplayObserver, each ReplayObserver will run a separate StarCraft II client.
 
void LaunchStarcraft ()
 Uses settings gathered from LoadSettings, specifically the path to the executable, to run StarCraft II.
 
void Connect (int port)
 Attaches to a running Starcraft.
 
bool StartGame (const std::string &map_path=std::string())
 
bool CreateGame (const std::string &map_path=std::string())
 
bool JoinGame ()
 
void SetupPorts (size_t num_agents, int port_start, bool check_single=true)
 
bool Update ()
 
void LeaveGame ()
 Requests for the currently running game to end.
 
bool AllGamesEnded () const
 Returns true if all running games have ended.
 
bool SetReplayPath (const std::string &path)
 Sets the path for to a folder of replays to analyze.
 
bool LoadReplayList (const std::string &file_path)
 Loads replays from a file.
 
void SaveReplayList (const std::string &file_path)
 Saves replays to a file.
 
bool HasReplays () const
 
void WaitForAllResponses ()
 Blocks for all bots to receive any pending responses.
 
bool RemoteSaveMap (const void *data, int data_size, std::string remote_path)
 Saves a binary blob as a map to a remote location. More...
 
std::string GetExePath () const
 

Detailed Description

Coordinator of one or more clients. Used to start, step and stop games and replays.

Member Function Documentation

bool sc2::Coordinator::CreateGame ( const std::string &  map_path = std::string())

Creates a game but does not join the agents to the game

Parameters
map_pathPath to the map to run. Returns true if the game was successfully created
std::string sc2::Coordinator::GetExePath ( ) const

Gets the game executable path.

Returns
The game executable path.
bool sc2::Coordinator::HasReplays ( ) const

Determines if there are unprocessed replays.

Returns
Is true if there are replays left.
bool sc2::Coordinator::JoinGame ( )

Joins agents to the game Returns true if the agents were successfully connected to the game

bool sc2::Coordinator::LoadSettings ( int  argc,
char **  argv 
)

Used to load settings. Settings will be discovered in the following order:

  1. If command line arguments are provided it will use them. Invoke binary with –help to see expected arguments.
  2. (Recommended) If the StarCraft II binary has been run the function will auto discover its location.
    Parameters
    argcProvided in main signature.
    argvProvided in main signature.
    game_settingsThe name of the settings file.
    Returns
    True if settings were found or discovered, false otherwise.
bool sc2::Coordinator::RemoteSaveMap ( const void *  data,
int  data_size,
std::string  remote_path 
)

Saves a binary blob as a map to a remote location.

<

Returns
Is true if the save is successful.
void sc2::Coordinator::SetDataVersion ( const std::string &  version)

Set the correct data version of a replay to allow faster replay loading. Saves a few seconds if replay is not up to date. Works only in combination with correct process path set by "SetProcessPath".

Parameters
versionLook in "protocol/buildinfo/versions.json" for the property "data-hash". Or read it from "ReplayInfo.data_version".
void sc2::Coordinator::SetFeatureLayers ( const FeatureLayerSettings settings)

Indicates whether feature layers should be provided in the observation.

Parameters
settingsConfiguration of feature layer settings.
See also
FeatureLayerSettings
void sc2::Coordinator::SetMultithreaded ( bool  value)

Specifies whether bots or replays OnStep function should be run in parallel. If set to true make sure your bots are thread-safe if they reach into shared code.

Parameters
valueTrue to multithread, false otherwise.
void sc2::Coordinator::SetPortStart ( int  port_start)

Sets the first port number to use. Subsequent port assignments are sequential.

Parameters
port_startFirst port number.
void sc2::Coordinator::SetProcessPath ( const std::string &  path)

Sets the path to the StarCraft II binary.

Parameters
pathAbsolute file path.
void sc2::Coordinator::SetRealtime ( bool  value)

Specifies whether the game should run in realtime or not. If the game is running in real time that means the coordinator is not stepping it forward. The game is running and your bot reaches into it asynchronously to read state.

Parameters
valueTrue to be realtime, false otherwise.
void sc2::Coordinator::SetRender ( const RenderSettings settings)
See also
RenderSettings
void sc2::Coordinator::SetStepSize ( int  step_size)

Sets the number of game loops to run for each step.

Parameters
step_sizeNumber of gameloops to run for each step.
void sc2::Coordinator::SetTimeoutMS ( uint32_t  timeout_ms = kDefaultProtoInterfaceTimeout)

Sets the timeout for network operations.

Parameters
valuetimeout_ms in milliseconds.
void sc2::Coordinator::SetupPorts ( size_t  num_agents,
int  port_start,
bool  check_single = true 
)

Sets up the sc2 game ports to use param num_agents Number of agents in the game param port_start Starting port number param check_single Checks if the game is a single player or multiplayer game

void sc2::Coordinator::SetUseGeneralizedAbilityId ( bool  value)

Uses generalized abilities where possible. Example: BUILD_TECHLAB_BARRACKS, BUILD_TECHLAB_FACTORY, BUILD_TECHLAB_STARPORT ability ids are generalized to BUILD_TECHLAB ability id in the observation.

void sc2::Coordinator::SetWindowLocation ( int  x,
int  y 
)

Sets the game window location.

Parameters
xX position of game window.
yy position of game window.
void sc2::Coordinator::SetWindowSize ( int  width,
int  height 
)

Sets the game window dimensions.

Parameters
widthWidth of game window.
heightHeight of game window.
bool sc2::Coordinator::StartGame ( const std::string &  map_path = std::string())

Starts a game on a certain map. There are multiple ways to specify a map: Absolute path: Any .SC2Map file. Relative path: Any .SC2Map file relative to either the library or installation maps folder. Map name: Any BattleNet published map that has been locally cached.

Parameters
map_pathPath to the map to run.
Returns
True if the game started, false if there was errors or the game didn't start, override OnError callback to see the exact errors.
bool sc2::Coordinator::Update ( )

Helper function used to actually run a bot. This function will behave differently in real-time compared to non real-time. In real-time there is no step sent over the wire but instead will request and read observations as the game runs.

  • For non-real time Update will perform the following:
    1. Step the simulation forward by a certain amount of game steps, this essentially moves the game loops forward.
    2. Wait for the step to complete, the step is completed when a response is received and read from the StarCraft II binary.
      • When the step is completed an Observation has been received. It is parsed and various client events are dispatched.
    3. Call the user's OnStep function.
  • Real time applications will perform the following:
    1. The Observation is directly requested. The process will block while waiting for it.
    2. The Observation is parsed and client events are dispatched.
    3. Unit actions batched from the ActionInterface are dispatched.
      Returns
      False if the game has ended, true otherwise.

The documentation for this class was generated from the following file: