Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
Implements an interface providing fundamental capabilities required for reinforcement learning (over HTTP). More...
#include <RLInterface.h>
Public Member Functions | |
Interface (const char *server_address) | |
~Interface () | |
void | TryApplyMessage () |
Non-blocking call to process any pending messages from the RL client. More... | |
Private Member Functions | |
NONCOPYABLE (Interface) | |
std::string | Step (std::vector< GameCommand > &&commands) |
Process commands, update the simulation by one turn. More... | |
std::string | Reset (ScenarioConfig &&scenario) |
Reset the game state according to scenario, cleaning up existing games if required. More... | |
std::string | Evaluate (std::string &&code) |
Evaluate JS code in the engine such as applying arbitrary modifiers. More... | |
std::vector< std::string > | GetTemplates (const std::vector< std::string > &names) const |
bool | IsGameRunning () const |
std::string | SendGameMessage (GameMessage &&msg) |
Internal helper. More... | |
bool | TryGetGameMessage (GameMessage &msg) |
Internal helper. More... | |
void | ApplyMessage (const GameMessage &msg) |
Process any pending messages from the RL client. More... | |
std::string | GetGameState () const |
Static Private Member Functions | |
static void * | MgCallback (mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) |
static std::string | GetRequestContent (struct mg_connection *conn) |
Private Attributes | |
GameMessage | m_GameMessage {GameMessageType::None} |
ScenarioConfig | m_ScenarioConfig |
std::string | m_ReturnValue |
bool | m_NeedsGameState = false |
std::mutex | m_Lock |
std::mutex | m_MsgLock |
std::condition_variable | m_MsgApplied |
std::string | m_Code |
mg_context * | m_Context |
Implements an interface providing fundamental capabilities required for reinforcement learning (over HTTP).
This consists of enabling an external script to configure the scenario (via Reset) and then step the game engine manually and apply player actions (via Step). The interface also supports querying unit templates to provide information about max health and other potentially relevant game state information.
See source/tools/rlclient/ for the external client code.
The HTTP server is threaded. Flow of data (with the interface active): 0. The game/main thread calls TryApplyMessage()
TryApplyMessage locks m_MsgLock, pulls the message, processes it, advances the simulation, and sets m_ReturnValue.
RL::Interface::Interface | ( | const char * | server_address | ) |
RL::Interface::~Interface | ( | ) |
|
private |
Process any pending messages from the RL client.
Updates m_ReturnValue to the gamestate after messages have been processed.
|
private |
Evaluate JS code in the engine such as applying arbitrary modifiers.
|
private |
|
staticprivate |
|
private |
names. |
|
private |
|
staticprivate |
|
private |
|
private |
Reset the game state according to scenario, cleaning up existing games if required.
|
private |
Internal helper.
Move
msg | into m_GameMessage, wait until it has been processed by the main thread, and |
|
private |
Process commands, update the simulation by one turn.
void RL::Interface::TryApplyMessage | ( | ) |
Non-blocking call to process any pending messages from the RL client.
Updates m_ReturnValue to the gamestate after messages have been processed.
|
private |
Internal helper.
msg,false | otherwise (msg is then unchanged). |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |