[go: up one dir, main page]

Menu

[r74]: / trunk / rlgo / RlSetup.h  Maximize  Restore  History

Download this file

214 lines (163 with data), 6.0 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
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//----------------------------------------------------------------------------
/** @file RlSetup.h
Class managing global settings for RLGO
*/
//----------------------------------------------------------------------------
#ifndef RLSETUP_H
#define RLSETUP_H
#include "RlFactory.h"
#include "SgDebug.h"
#include "SgTimeRecord.h"
#include <boost/filesystem/path.hpp>
#include <fstream>
#include <vector>
namespace bfs = boost::filesystem;
class GoGame;
class RlPointIndex;
class RlRealAgent;
class RlSimAgent;
class RlSimulator;
//----------------------------------------------------------------------------
/** Global settings used to set up RLGO infrastructure */
class RlSetup : public RlAutoObject
{
public:
DECLARE_OBJECT(RlSetup);
RlSetup(GoBoard& board, RlRealAgent* agent = 0);
~RlSetup();
virtual void LoadSettings(std::istream& settings);
virtual void Initialise();
/** Set root path of RLGO distribution */
void SetMainPath(const bfs::path& mainpath);
/** Get path to input subdirectory */
bfs::path GetInputPath() const;
/** Get path to output subdirectory */
bfs::path GetOutputPath() const;
int GetBoardSize() const { return m_boardSize; }
std::string GetRules() const { return m_rules; }
int GetRandomSeed() const { return m_randomSeed; }
bool GetDebugOutput() const { return m_debugOutput; }
bool DebugLevel(int level) const { return m_debugLevel >= level; }
void SetDebugLevel(int level) { m_debugLevel = level; }
bool GetVerification() const { return m_verification; }
int GetDefaultTime() const { return m_defaultTime; }
RlRealAgent* GetMainAgent() { return m_mainAgent; }
RlSimAgent* GetSimAgent() { return m_simAgent; }
void SetMainAgent(RlRealAgent* agent) { m_mainAgent = agent; }
void SetSimAgent(RlSimAgent* agent) { m_simAgent = agent; }
void SetGame(GoGame* game) { m_game = game; }
GoGame* GetGame() const { return m_game; }
const SgTimeRecord& GetTimeRecord() { return m_timeRecord; }
void SetTimeRecord(const SgTimeRecord& timerecord) { m_timeRecord = timerecord; }
RlSimulator* GetSelfPlay() { return m_selfPlay; }
void SetSelfPlay(RlSimulator* selfplay) { m_selfPlay = selfplay; }
int GetNumGtpCommands() const
{
return m_gtpCommands.size();
}
const std::string& GetGtpCommand(int index) const
{
return m_gtpCommands[index];
}
/** Accessor to main setup (set during construction) */
static RlSetup* Get()
{
return s_mainSetup;
}
/** Process number during IPC (-1 for single-process) */
int GetProcess() const { return m_process; }
/** DebugOutput options */
enum
{
NONE, // No debug output
STD, // Output to stderr (UNIX) or stdout
FILE // Output to "DebugStr" file
};
/** DebugLevel options */
enum
{
SILENT, // No debug output
QUIET, // Minimal debug output
VOCAL, // Moderate debug output
VERBOSE // All debug output
};
private:
/** Path to root directory of RLGO distribution */
bfs::path m_mainPath;
/** Path to input files used by RLGO, relative to m_mainPath
e.g. weights, share files, book files, etc. */
bfs::path m_inputPath;
/** Path to temporary output files created by RLGO,
relative to m_mainPath */
bfs::path m_outputPath;
/** Path to book file, or empty if no book file,
relative to m_inputPath */
bfs::path m_bookFile;
/** Board size with which to initialise board */
int m_boardSize;
/** Name of rule set to use */
std::string m_rules;
/** Random seed for this run */
int m_randomSeed;
/** Process number during IPC (-1 for single-process) */
int m_process;
/** Top-level simulator used to run in self-play mode */
RlSimulator* m_selfPlay;
/** Debug output (see enum for options) */
int m_debugOutput;
/** Debug level (0 to 3) */
int m_debugLevel;
/** Whether to run slow verification code */
bool m_verification;
/** Default time control (number of seconds per move)
If no GTP time settings are provided
and time settings are used */
int m_defaultTime;
/** Top-level agent used by player */
RlRealAgent* m_mainAgent;
/** Agent used by player to execute simulations (may be NULL) */
RlSimAgent* m_simAgent;
/** The main game record @TODO: remove this altogether */
GoGame* m_game;
/** The current time record (set during GenMove) */
SgTimeRecord m_timeRecord;
/** Any GTP commands used during setup (e.g. time controls) */
std::vector<std::string> m_gtpCommands;
/** Point index utility class */
RlPointIndex* m_pointIndex;
/** Pointer to main setup created during initialisation */
static RlSetup* s_mainSetup;
};
namespace RlPathUtil
{
/** Convenience function for accessing global input path */
inline bfs::path GetInputPath()
{
SG_ASSERT(RlSetup::Get());
return RlSetup::Get()->GetInputPath();
}
/** Convenience function for accessing global output path */
inline bfs::path GetOutputPath()
{
SG_ASSERT(RlSetup::Get());
return RlSetup::Get()->GetOutputPath();
}
/** Convenience function for getting the process number */
inline int GetProcess()
{
if (RlSetup::Get())
return RlSetup::Get()->GetProcess();
else
return -1;
}
}
inline std::ostream& RlDebug(int debuglevel = RlSetup::VERBOSE)
{
static std::ofstream s_rlNullStream;
if (!RlSetup::Get() || RlSetup::Get()->DebugLevel(debuglevel))
return SgDebug();
else
return s_rlNullStream;
}
//----------------------------------------------------------------------------
#endif // RLSETUP_H