-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv_actor.h
More file actions
68 lines (51 loc) · 1.58 KB
/
Copy pathenv_actor.h
File metadata and controls
68 lines (51 loc) · 1.58 KB
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
#ifndef RLCC_ENV_ACTOR_H
#define RLCC_ENV_ACTOR_H
#include <memory>
#include <string>
#include "rela/logging.h"
#include "rlcc/bridge_actor.h"
#include "rlcc/env.h"
namespace rlcc {
struct EnvActorOptions {
bool eval = false;
};
class EnvActor {
public:
EnvActor(std::vector<std::shared_ptr<Actor>> actors,
const EnvActorOptions& options)
: actors_(actors), options_(options) {}
virtual void Reset() {}
virtual void ObserveBeforeAct() {}
virtual void Act() {}
virtual void ObserveAfterAct() {}
virtual void SendExperience() {}
virtual void PostSendExperience() {}
void CheckValid(const rlcc::GameEnv& env) const {
RELA_CHECK_EQ(env.Spec().num_players, actors_.size());
}
const std::vector<std::vector<float>>& HistoryRewards() const {
return history_rewards_;
}
const std::vector<std::string>& HistoryInfo() const {
return history_info_;
}
int TerminalCount() const { return terminal_count_; }
virtual const std::shared_ptr<GameEnv>& GetEnv() const = 0;
protected:
void EnvTerminate(const std::vector<float>* rewards = nullptr,
const std::string& info = "") {
++terminal_count_;
if (rewards != nullptr && options_.eval) {
history_rewards_.push_back(*rewards);
history_info_.push_back(info);
}
}
int terminal_count_ = 0;
std::vector<std::shared_ptr<Actor>> actors_;
// Reward of each player in each game.
std::vector<std::vector<float>> history_rewards_;
std::vector<std::string> history_info_;
const EnvActorOptions options_;
};
} // namespace rlcc
#endif /* RLCC_ENV_ACTOR_H */