Creating Environment
Now we are going to create an Environment.
In Godot Gym API Environment (RLEnvironment node) is assumed as top node that manage communication and game loop.
World and Agent is considered as Environment children. Environment can have only one Agent and only one World.
Open
Environment.tscnfile.Change
Environmentnode type fromSpatialtoRLEnvironmnt.Open
Agentnode Inspector tab and selectEnvironmnet/World/AppleinTarget Node Pathfield.Attach a new scipt to
Environmentnode and paste the following code:extends RLEnvironment func _ready(): world = $World agent = $Agent communication.start_server(9090, "127.0.0.1") func _reset(): world.reset() agent.reset()
Let’s examine what we added.
RLEnvironmentclass requires variablesworldandagentto be set...code-block:: gdscript
- func _ready():
world = $World agent = $Agent
We start our TCP server (already defined in
RLEnvironmentclass ascommunication) at specific address and port:..code-block:: gdscript
communication.start_server(9090, “127.0.0.1”)
3. RLEnvironment class required method reset do be implemented.
In the method we define what should be done during environment reset:
..code-block:: gdscript
- func _reset():
world.reset() agent.reset()
The reset logic can be more complex. E.g. our World can generate position to place the agent at in the begging of an episode:
..code-block:: gdscript
- func _reset():
world.reset() agent.reset(world._sample_initial_position())
Thats’s it for Environment! Let’s summarize:
RLEnvironmentmust haveresetmethod implemented.RLEnvironmentmust haveagentandworldproperties defined.
That’s it for Godot part!