-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_6.cpp
52 lines (31 loc) · 1.05 KB
/
example_6.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "rlenvs/envs/gymnasium/classic_control/pendulum_env.h"
#include "rlenvs/envs/api_server/apiserver.h"
#include "rlenvs/rlenvs_types_v2.h"
#include "rlenvs/rlenvs_consts.h"
#ifdef RLENVSCPP_DEBUG
#include <cassert>
#endif
#include <iostream>
#include <string>
#include <random>
#include <unordered_map>
int main(){
using namespace rlenvscpp::envs::gymnasium;
using rlenvscpp::envs::RESTApiServerWrapper;
const std::string SERVER_URL = "http://0.0.0.0:8001/api";
RESTApiServerWrapper server(SERVER_URL, true);
Pendulum env(server);
std::cout<<"Name: "<<env.name<<std::endl;
std::cout<<"Number of actions: "<<env.n_actions()<<std::endl;
// make the environment
std::unordered_map<std::string, std::any> options;
env.make("v1", options);
auto time_step = env.reset();
std::cout<<"Time step: "<<time_step<<std::endl;
// step in the environment
time_step = env.step(0.0);
std::cout<<"Time step after action: "<<time_step<<std::endl;
env.close();
std::cout<<"Is active? "<<env.is_alive()<<std::endl;
return 0;
}