Skip to content

Commit 75e2254

Browse files
committed
Update example 6
1 parent afd6688 commit 75e2254

File tree

1 file changed

+80
-29
lines changed

1 file changed

+80
-29
lines changed

examples/example_6/example_6.cpp

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

2-
#include "bitrl/envs/gymnasium/classic_control/pendulum_env.h"
2+
//#include "bitrl/envs/gymnasium/classic_control/pendulum_env.h"
3+
//#include "bitrl/envs/gymnasium/classic_control/vector/acrobot_vec_env.h"
4+
#include "bitrl/envs/gymnasium/classic_control/cart_pole_env.h"
35
#include "bitrl/network/rest_rl_env_client.h"
46
#include "bitrl/bitrl_types.h"
57
#include "bitrl/bitrl_consts.h"
@@ -14,42 +16,91 @@
1416
#include <random>
1517
#include <unordered_map>
1618

17-
19+
namespace example
20+
{
21+
using namespace bitrl;
22+
using namespace bitrl::envs::gymnasium;
23+
using bitrl::network::RESTRLEnvClient;
24+
25+
void test_cart_pole(RESTRLEnvClient& server)
26+
{
27+
// the environment is not registered with the server
28+
std::cout<<"Is environment registered: "<<server.is_env_registered(CartPole::name)<<std::endl;
29+
30+
// create the environment
31+
CartPole env(server);
32+
33+
std::cout<<"Name: "<<env.name<<std::endl;
34+
std::cout<<"Number of actions: "<<env.n_actions()<<std::endl;
35+
36+
// make the environment
37+
std::unordered_map<std::string, std::any> options;
38+
std::unordered_map<std::string, std::any> reset_ops;
39+
reset_ops.insert({"seed", static_cast<uint_t>(42)});
40+
env.make("v1", options, reset_ops);
41+
42+
auto time_step = env.reset();
43+
std::cout<<"Time step: "<<time_step<<std::endl;
44+
45+
// step in the environment
46+
time_step = env.step(0);
47+
std::cout<<"Time step after action: "<<time_step<<std::endl;
48+
49+
env.close();
50+
}
51+
// void test_pendulum(RESTRLEnvClient& server)
52+
// {
53+
//
54+
// // the environment is not registered with the server
55+
// std::cout<<"Is environment registered: "<<server.is_env_registered(Pendulum::name)<<std::endl;
56+
//
57+
// // create the environment
58+
// Pendulum env(server);
59+
//
60+
// std::cout<<"Name: "<<env.name<<std::endl;
61+
// std::cout<<"Number of actions: "<<env.n_actions()<<std::endl;
62+
//
63+
// // make the environment
64+
// std::unordered_map<std::string, std::any> options;
65+
// std::unordered_map<std::string, std::any> reset_ops;
66+
// reset_ops.insert({"seed", static_cast<uint_t>(42)});
67+
// env.make("v1", options, reset_ops);
68+
//
69+
// auto time_step = env.reset();
70+
// std::cout<<"Time step: "<<time_step<<std::endl;
71+
//
72+
// // step in the environment
73+
// time_step = env.step(0.0);
74+
// std::cout<<"Time step after action: "<<time_step<<std::endl;
75+
//
76+
// env.close();
77+
// }
78+
79+
}
1880

1981

2082
int main(){
2183

22-
using namespace bitrl;
23-
using namespace bitrl::envs::gymnasium;
24-
using bitrl::network::RESTRLEnvClient;
84+
using namespace example;
2585

2686
const std::string SERVER_URL = "http://0.0.0.0:8001/api";
2787

2888
RESTRLEnvClient server(SERVER_URL, true);
89+
90+
std::cout<<"Testing FrozenLake..."<<std::endl;
91+
example::test_cart_pole(server);
92+
std::cout<<"===================="<<std::endl;
93+
std::cout<<"Testing Taxi..."<<std::endl;
94+
//example::test_pendulum(server);
95+
std::cout<<"===================="<<std::endl;
96+
// std::cout<<"Testing BlackJack..."<<std::endl;
97+
// example_1::test_black_jack(server);
98+
// std::cout<<"===================="<<std::endl;
99+
// std::cout<<"Testing CliffWorld..."<<std::endl;
100+
// example_1::test_cliff_world(server);
101+
// std::cout<<"===================="<<std::endl;
102+
return 0;
29103

30-
Pendulum env(server);
31-
32-
std::cout<<"Name: "<<env.name<<std::endl;
33-
std::cout<<"Number of actions: "<<env.n_actions()<<std::endl;
34-
35-
// make the environment
36-
std::unordered_map<std::string, std::any> options;
37-
std::unordered_map<std::string, std::any> reset_ops;
38-
reset_ops.insert({"seed", static_cast<uint_t>(42)});
39-
env.make("v1", options, reset_ops);
40-
41-
auto time_step = env.reset();
42-
43-
std::cout<<"Time step: "<<time_step<<std::endl;
44-
45-
// step in the environment
46-
time_step = env.step(0.0);
47-
48-
std::cout<<"Time step after action: "<<time_step<<std::endl;
49-
50-
env.close();
51-
52-
std::cout<<"Is active? "<<env.is_alive()<<std::endl;
53-
104+
54105
return 0;
55106
}

0 commit comments

Comments
 (0)