Grail (C++)  1.2.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
OfflineLearner.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_OFFLINE_LEARNER_H
4 #define GRAIL_OFFLINE_LEARNER_H
5 
6 #include <memory>
7 #include <unordered_map>
8 #include <vector>
9 
10 namespace grail
11 {
12 namespace simgames
13 {
14  class ISimulatedGameUnit;
15  class SimulatedGameNode;
16  class SimulatedGameThinkingUnit;
17 
18 namespace learn
19 {
20  struct IVectorizer;
21  class UniqueTreeDataset;
22 
28  {
29  public:
34  OfflineLearner(std::unique_ptr<IVectorizer> vectorizer);
35 
37  void ClearData();
38 
46  std::unique_ptr<UniqueTreeDataset> GetSamplesDataset(double minFractionOfSimulationsThreshold = 0.7);
47 
55  void FillSamplesDataset(UniqueTreeDataset& dataset, double minFractionOfSimulationsThreshold = 0.7);
56 
57  private:
58  double GetSampleMaxVisits() const;
59  void ObserveNode(const SimulatedGameNode* node);
60  bool IsLearnableSituation(const ISimulatedGameUnit& unit);
61 
62  std::unique_ptr<IVectorizer> stateObserver;
63  std::unordered_map<const SimulatedGameNode*, std::vector<float>> capturedData = {};
64 
66  };
67 }
68 }
69 }
70 
71 #endif //GRAIL_OFFLINE_LEARNER_H
grail::simgames::learn::OfflineLearner::ClearData
void ClearData()
Clears all data gathered for the game. You may want to call it after you already use the data but you...
Definition: OfflineLearner.cpp:20
grail::simgames::learn::OfflineLearner::FillSamplesDataset
void FillSamplesDataset(UniqueTreeDataset &dataset, double minFractionOfSimulationsThreshold=0.7)
Gets data gathered by OfflineLearner and adds it to dataset. Pass the container you want to add data ...
Definition: OfflineLearner.cpp:52
grail::simgames::learn::OfflineLearner
This is the main class you will use to peform the offline learning process. Assign it to the unit of ...
Definition: OfflineLearner.hh:27
grail::simgames::SimulatedGameThinkingUnit
A base class of a unit related to a rational/intelligent player. MCTS chooses actions for this kind o...
Definition: SimulatedGameThinkingUnit.hh:26
grail::simgames::learn::OfflineLearner::OfflineLearner
OfflineLearner(std::unique_ptr< IVectorizer > vectorizer)
Constructs a new OfflineLearner object.
Definition: OfflineLearner.cpp:15
grail::simgames::learn::OfflineLearner::GetSamplesDataset
std::unique_ptr< UniqueTreeDataset > GetSamplesDataset(double minFractionOfSimulationsThreshold=0.7)
Gets data gathered by OfflineLearner in the form of UniqueTreeDataset.
Definition: OfflineLearner.cpp:44
grail::simgames::ISimulatedGameUnit
Base class of a unit in the SimulatedGame framework. A unit represents part of the game-state and pef...
Definition: ISimulatedGameUnit.hh:28
grail::simgames::SimulatedGameNode
This class should not be visible to developers at all.
Definition: SimulatedGameNode.h:25
grail::simgames::learn::UniqueTreeDataset
Definition: UniqueTreeDataset.hh:23