-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_7.cpp
91 lines (66 loc) · 2.15 KB
/
example_7.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "rlenvs/rlenvs_types_v2.h"
#include "rlenvs/envs/connect2/connect2_env.h"
#include "rlenvs/rlenvs_consts.h"
#include "rlenvs/utils/io/io_utils.h"
#include <iostream>
#include <string>
#include <unordered_map>
#include <any>
#include <vector>
#include <ios>
int main(){
using namespace rlenvscpp::utils::io;
using namespace rlenvscpp::envs::connect2;
using rlenvscpp::uint_t;
Connect2 env;
std::cout<<"Name: "<<env.name<<std::endl;
std::cout<<"Number of actions: "<<env.n_actions()<<std::endl;
std::unordered_map<std::string, std::any> options;
// make the environment
env.make("v1", options);
std::cout<<"Is active? "<<env.is_created()<<std::noboolalpha <<std::endl;
std::cout<<"Reseting the environment... "<<std::endl;
auto time_step = env.reset();
std::cout<<"Time step after reset: "<<std::endl;
std::cout<<time_step<<std::endl;
std::cout<<"Acting on the environment... "<<std::endl;
time_step = env.step(0);
std::cout<<"Observation vector..."<<time_step.observation()<<std::endl;
// what are the valid moves remaining?
auto val_moves = time_step.template get_extra<std::vector<int>>("valid_moves");
std::cout<<"Valid moves remaining..."<<val_moves<<std::endl;
try{
// invalid action
env.step(5);
}
catch(std::logic_error& e){
std::cout<<e.what()<<std::endl;
}
//trying to step again on the same spot
// is an error
try{
env.step(0);
}
catch(std::logic_error& e){
std::cout<<e.what()<<std::endl;
}
std::cout<<"Winning the game..."<<std::endl;
time_step = env.step(1);
// this means that we have won
std::cout<<time_step<<std::endl;
time_step = env.reset();
std::cout<<"Starting the game..."<<std::endl;
std::cout<<time_step.observation()<<std::endl;
std::cout<<"Player 1 moves..."<<std::endl;
time_step = env.move(1 , 2);
std::cout<<time_step.observation()<<std::endl;
std::cout<<"Player 2 moves..."<<std::endl;
time_step = env.move(2 , 3);
std::cout<<time_step.observation()<<std::endl;
std::cout<<"Player 1 moves..."<<std::endl;
time_step = env.move(1 , 1);
std::cout<<time_step.observation()<<std::endl;
std::cout<<"Closing the environment... "<<std::endl;
env.close();
return 0;
}