00001
00002
00003
00004
00005
00006
00007 #include "SgSystem.h"
00008 #include "FuegoTestEngine.h"
00009
00010 #include <boost/preprocessor/stringize.hpp>
00011 #include <boost/algorithm/string.hpp>
00012 #include "GoGtpCommandUtil.h"
00013 #include "GoGtpExtraCommands.h"
00014 #include "SpAveragePlayer.h"
00015 #include "SpCapturePlayer.h"
00016 #include "SpDumbTacticalPlayer.h"
00017 #include "SpGreedyPlayer.h"
00018 #include "SpInfluencePlayer.h"
00019 #include "SpLadderPlayer.h"
00020 #include "SpLibertyPlayer.h"
00021 #include "SpMaxEyePlayer.h"
00022 #include "SpMinLibPlayer.h"
00023 #include "SpRandomPlayer.h"
00024 #include "SpSafePlayer.h"
00025
00026 using namespace std;
00027 using boost::trim_copy;
00028
00029
00030
00031 FuegoTestEngine::FuegoTestEngine(GtpInputStream& in, GtpOutputStream& out,
00032 int fixedBoardSize,
00033 const char* programPath,
00034 const string& player)
00035 : GoGtpEngine(in, out, fixedBoardSize, programPath),
00036 m_extraCommands(Board()),
00037 m_safetyCommands(Board())
00038 {
00039 Register("fuegotest_param", &FuegoTestEngine::CmdParam, this);
00040 m_extraCommands.Register(*this);
00041 m_safetyCommands.Register(*this);
00042 SetPlayer(player);
00043 }
00044
00045 FuegoTestEngine::~FuegoTestEngine()
00046 {
00047 }
00048
00049 void FuegoTestEngine::CmdAnalyzeCommands(GtpCommand& cmd)
00050 {
00051 GoGtpEngine::CmdAnalyzeCommands(cmd);
00052 m_extraCommands.AddGoGuiAnalyzeCommands(cmd);
00053 m_safetyCommands.AddGoGuiAnalyzeCommands(cmd);
00054 cmd <<
00055 "param/FuegoTest Param/fuegotest_param\n";
00056 string response = cmd.Response();
00057 cmd.SetResponse(GoGtpCommandUtil::SortResponseAnalyzeCommands(response));
00058 }
00059
00060 void FuegoTestEngine::CmdName(GtpCommand& cmd)
00061 {
00062 if (m_playerId == "")
00063 cmd << "FuegoTest";
00064 else
00065 GoGtpEngine::CmdName(cmd);
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 void FuegoTestEngine::CmdParam(GtpCommand& cmd)
00075 {
00076 cmd.CheckNuArgLessEqual(2);
00077 if (cmd.NuArg() == 0)
00078 {
00079 cmd <<
00080 "[list/<none>/average/capture/dumbtactic/greedy/influence/"
00081 "ladder/liberty/maxeye/minlib/no-search/random/safe] player "
00082 << (m_playerId == "" ? "<none>" : m_playerId) << '\n';
00083 }
00084 else if (cmd.NuArg() >= 1 && cmd.NuArg() <= 2)
00085 {
00086 string name = cmd.Arg(0);
00087 if (name == "player")
00088 {
00089 try
00090 {
00091 string id = trim_copy(cmd.RemainingLine(0));
00092 if (id == "<none>")
00093 id = "";
00094 SetPlayer(id);
00095 }
00096 catch (const SgException& e)
00097 {
00098 throw GtpFailure(e.what());
00099 }
00100 }
00101 else
00102 throw GtpFailure() << "unknown parameter: " << name;
00103 }
00104 else
00105 throw GtpFailure() << "need 0 or 2 arguments";
00106 }
00107
00108 void FuegoTestEngine::CmdVersion(GtpCommand& cmd)
00109 {
00110 #ifdef VERSION
00111 cmd << BOOST_PP_STRINGIZE(VERSION);
00112 #else
00113 cmd << "(" __DATE__ ")";
00114 #endif
00115 #ifndef NDEBUG
00116 cmd << " (dbg)";
00117 #endif
00118 }
00119
00120 GoPlayer* FuegoTestEngine::CreatePlayer(const string& playerId)
00121 {
00122 GoBoard& bd = Board();
00123 if (playerId == "")
00124 return 0;
00125 if (playerId == "average")
00126 return new SpAveragePlayer(bd);
00127 if (playerId == "capture")
00128 return new SpCapturePlayer(bd);
00129 if (playerId == "dumbtactic")
00130 return new SpDumbTacticalPlayer(bd);
00131 if (playerId == "greedy")
00132 return new SpGreedyPlayer(bd);
00133 if (playerId == "influence")
00134 return new SpInfluencePlayer(bd);
00135 if (playerId == "ladder")
00136 return new SpLadderPlayer(bd);
00137 if (playerId == "liberty")
00138 return new SpLibertyPlayer(bd);
00139 if (playerId == "maxeye")
00140 return new SpMaxEyePlayer(bd, true);
00141 if (playerId == "minlib")
00142 return new SpMinLibPlayer(bd);
00143 if (playerId == "random")
00144 return new SpRandomPlayer(bd);
00145 if (playerId == "safe")
00146 return new SpSafePlayer(bd);
00147 throw SgException("unknown player " + playerId);
00148 }
00149
00150 void FuegoTestEngine::SetPlayer(const string& playerId)
00151 {
00152 GoPlayer* player = CreatePlayer(playerId);
00153 GoGtpEngine::SetPlayer(player);
00154 m_playerId = playerId;
00155 }
00156
00157