#include <SgGtpCommands.h>
Implements generally useful command, which do not require a board or player. Uses functionality from module SmartGo. This class can be used in GTP engines.
Definition at line 24 of file SgGtpCommands.h.
Public Member Functions | |
SgGtpCommands (GtpEngine &engine, const char *programPath=0) | |
Constructor. | |
virtual | ~SgGtpCommands () |
void | AddGoGuiAnalyzeCommands (GtpCommand &cmd) |
void | Register (GtpEngine &engine) |
Register commands at engine. | |
Command Callbacks | |
virtual void | CmdCompareFloat (GtpCommand &) |
Run another GTP command and compare its response against a float value. | |
virtual void | CmdCompareInt (GtpCommand &) |
Run another GTP command and compare its response against an integer value. | |
virtual void | CmdCpuTime (GtpCommand &) |
Return process time. | |
virtual void | CmdCpuTimeReset (GtpCommand &) |
Reset process time. | |
virtual void | CmdDebugger (GtpCommand &) |
Run a debugger and attach it to the current program. | |
virtual void | CmdEcho (GtpCommand &) |
Echo command argument line as response. | |
virtual void | CmdEchoErr (GtpCommand &) |
Echo command argument line to std::cerr. | |
virtual void | CmdExec (GtpCommand &) |
Execute GTP commands from a file. | |
virtual void | CmdGetRandomSeed (GtpCommand &) |
Return the current random seed. | |
virtual void | CmdParam (GtpCommand &) |
Set global parameters used in module SmartGame. | |
virtual void | CmdPid (GtpCommand &) |
Return the process ID. | |
virtual void | CmdSetRandomSeed (GtpCommand &) |
Set and store random seed. | |
virtual void | CmdQuiet (GtpCommand &) |
Switch debug logging on/off. | |
Private Attributes | |
const char * | m_programPath |
GtpEngine & | m_engine |
std::map< std::string, double > | m_cpuTimes |
Cputimes for cputime and cputime_reset commands. |
SgGtpCommands::SgGtpCommands | ( | GtpEngine & | engine, | |
const char * | programPath = 0 | |||
) |
Constructor.
engine | The GTP engine (needed for wrapper commands that invoke arbitrary other engine commands like sg_compare_float) | |
programPath | The path to the executable for the engine for sg_debug, 0 if unknown |
Definition at line 59 of file SgGtpCommands.cpp.
SgGtpCommands::~SgGtpCommands | ( | ) | [virtual] |
Definition at line 65 of file SgGtpCommands.cpp.
void SgGtpCommands::AddGoGuiAnalyzeCommands | ( | GtpCommand & | cmd | ) |
Definition at line 69 of file SgGtpCommands.cpp.
void SgGtpCommands::CmdCompareFloat | ( | GtpCommand & | cmd | ) | [virtual] |
Run another GTP command and compare its response against a float value.
Arguments: float command [arg...]
Returns: -1 if response is smaller than float; 1 otherwise.
Definition at line 79 of file SgGtpCommands.cpp.
References GtpEngine::ExecuteCommand(), GtpCommand::FloatArg(), m_engine, and GtpCommand::RemainingLine().
Referenced by Register().
void SgGtpCommands::CmdCompareInt | ( | GtpCommand & | cmd | ) | [virtual] |
Run another GTP command and compare its response against an integer value.
Arguments: int command [arg...]
Returns: -1 if response is smaller than int; 0 if it is equal; 1 if it is greater
Definition at line 96 of file SgGtpCommands.cpp.
References GtpEngine::ExecuteCommand(), GtpCommand::IntArg(), m_engine, and GtpCommand::RemainingLine().
Referenced by Register().
void SgGtpCommands::CmdCpuTime | ( | GtpCommand & | cmd | ) | [virtual] |
Return process time.
An optional string argument can be used as an ID for a timer. Default ID is "total". Other IDs are only allowed if cputime_reset was called with this ID before.
Definition at line 120 of file SgGtpCommands.cpp.
References SgTime::Get(), m_cpuTimes, ParseCpuTimeId(), and SG_TIME_CPU.
Referenced by Register().
void SgGtpCommands::CmdCpuTimeReset | ( | GtpCommand & | cmd | ) | [virtual] |
Reset process time.
An optional string argument can be used as an ID for a timer. Default ID is "total".
Definition at line 140 of file SgGtpCommands.cpp.
References SgTime::Get(), m_cpuTimes, ParseCpuTimeId(), and SG_TIME_CPU.
Referenced by Register().
void SgGtpCommands::CmdDebugger | ( | GtpCommand & | cmd | ) | [virtual] |
Run a debugger and attach it to the current program.
Arguments: debugger-type
Currently implemented debugger types:
Definition at line 153 of file SgGtpCommands.cpp.
References GtpCommand::Arg(), GtpCommand::CheckNuArg(), m_programPath, and SgDebug().
Referenced by Register().
void SgGtpCommands::CmdEcho | ( | GtpCommand & | cmd | ) | [virtual] |
Echo command argument line as response.
This command is compatible with GNU Go's 'echo' command.
Definition at line 177 of file SgGtpCommands.cpp.
References GtpCommand::ArgLine().
Referenced by Register().
void SgGtpCommands::CmdEchoErr | ( | GtpCommand & | cmd | ) | [virtual] |
Echo command argument line to std::cerr.
This command is compatible with GNU Go's 'echo_err' command.
Definition at line 185 of file SgGtpCommands.cpp.
References GtpCommand::ArgLine().
Referenced by Register().
void SgGtpCommands::CmdExec | ( | GtpCommand & | cmd | ) | [virtual] |
Execute GTP commands from a file.
Argument: filename
Aborts on the first command that fails. Responses to the commands in the file are written to SgDebug()
Definition at line 198 of file SgGtpCommands.cpp.
References GtpCommand::Arg(), GtpCommand::CheckNuArg(), GtpEngine::ExecuteFile(), m_engine, and SgDebug().
Referenced by Register().
void SgGtpCommands::CmdGetRandomSeed | ( | GtpCommand & | cmd | ) | [virtual] |
Return the current random seed.
See SgRandom::SetSeed(int) for the special meaning of zero and negative values.
Definition at line 208 of file SgGtpCommands.cpp.
References GtpCommand::CheckArgNone(), and SgRandom::Seed().
Referenced by Register().
void SgGtpCommands::CmdParam | ( | GtpCommand & | cmd | ) | [virtual] |
Set global parameters used in module SmartGame.
Parameters:
time_mode
cpu|real See SgTime Definition at line 218 of file SgGtpCommands.cpp.
References GtpCommand::Arg(), GtpCommand::CheckNuArgLessEqual(), SgTime::DefaultMode(), GtpCommand::NuArg(), SgTime::SetDefaultMode(), TimeModeArg(), and TimeModeToString().
Referenced by Register().
void SgGtpCommands::CmdPid | ( | GtpCommand & | ) | [virtual] |
Return the process ID.
Definition at line 241 of file SgGtpCommands.cpp.
References GtpCommand::CheckArgNone().
Referenced by Register().
void SgGtpCommands::CmdQuiet | ( | GtpCommand & | ) | [virtual] |
Switch debug logging on/off.
Definition at line 259 of file SgGtpCommands.cpp.
References GtpCommand::BoolArg(), SgDebugToNull(), and SgSwapDebugStr().
Referenced by Register().
void SgGtpCommands::CmdSetRandomSeed | ( | GtpCommand & | cmd | ) | [virtual] |
Set and store random seed.
Arguments: seed
See SgRandom::SetSeed(int) for the special meaning of zero and negative values.
Definition at line 252 of file SgGtpCommands.cpp.
References GtpCommand::CheckNuArg(), GtpCommand::IntArg(), and SgRandom::SetSeed().
Referenced by Register().
void SgGtpCommands::Register | ( | GtpEngine & | engine | ) |
Register commands at engine.
Make sure that this object lives as long as the GtpEngine, for example by making it a member of the engine.
Definition at line 267 of file SgGtpCommands.cpp.
References CmdCompareFloat(), CmdCompareInt(), CmdCpuTime(), CmdCpuTimeReset(), CmdDebugger(), CmdEcho(), CmdEchoErr(), CmdExec(), CmdGetRandomSeed(), CmdParam(), CmdPid(), CmdQuiet(), CmdSetRandomSeed(), and GtpEngine::Register().
std::map<std::string,double> SgGtpCommands::m_cpuTimes [private] |
Cputimes for cputime and cputime_reset commands.
Definition at line 83 of file SgGtpCommands.h.
Referenced by CmdCpuTime(), and CmdCpuTimeReset().
GtpEngine& SgGtpCommands::m_engine [private] |
Definition at line 80 of file SgGtpCommands.h.
Referenced by CmdCompareFloat(), CmdCompareInt(), and CmdExec().
const char* SgGtpCommands::m_programPath [private] |