Skip to content

Latest commit

 

History

History
62 lines (38 loc) · 2.22 KB

connector.md

File metadata and controls

62 lines (38 loc) · 2.22 KB

Connector documentation

Here you will find general information about the VCMI connector, why it is needed and how it works.

What is it?

The connector is the "man-in-the-middle" for all communication between VcmiGym (Python gym environment) and VCMI (C++ library):

components-connector

Internally, the Connector is composed of two parts:

  • PyConnector
  • CppConnector

Together, they form the "link" between the gym env and VCMI.

Why is it needed?

If we take VcmiGym's point of view, communication with VCMI is as simple as calling vcmi.get_state(action) to obtain the new environment state:

connector-pov-gym

Doing the same with VCMI's point of view, communication with VcmiGym (the "AI") is as simple as calling ai.getAction(state) to obtain next action:

connector-pov-vcmi

The problem is: both components assume the role of the caller in this state-action exchange and that simply can't happen in practice without some kind of a buffer in between. That "buffer" is the Connector and here's how it works:

connector-pov

Although more stuff is happening under the hood, in a nutshell, two different threads are synchronized with the help of locks and condvars. Here's the same call to step() with some implementation details:

connector-details-step

There's several more of those diagrams. They really helped me during the connector development phase, so others (and future me) might find them useful as well:

Connector details - VCMI init:

connector-details-init

Connector details - render:

connector-details-render

Connector details - reset (after battle end):

connector-details-reset-endbattle

Connector details - reset (mid-battle):

connector-details-reset-midbattle