/** Player selection. This command is compatible with the GoGui analyze command type "param". Parameters: @arg @c player Player id as in FuegoTestEngine::SetPlayer */ void FuegoTestEngine::CmdParam(GtpCommand& cmd) { cmd.CheckNuArgLessEqual(2); if (cmd.NuArg() == 0) { cmd << "[list/<none>/average/capture/dumbtactic/greedy/influence/" "ladder/liberty/maxeye/minlib/no-search/random/safe] player " << (m_playerId == "" ? "<none>" : m_playerId) << '\n'; } else if (cmd.NuArg() >= 1 && cmd.NuArg() <= 2) { string name = cmd.Arg(0); if (name == "player") { try { string id = trim_copy(cmd.RemainingLine(0)); if (id == "<none>") id = ""; SetPlayer(id); } catch (const SgException& e) { throw GtpFailure(e.what()); } } else throw GtpFailure() << "unknown parameter: " << name; } else throw GtpFailure() << "need 0 or 2 arguments"; }
/** Information about safe points optimized for graphical display in GoGui. This command is compatible with GoGui's analyze command type "gfx". Arguments: benson|static <br> Returns: GoGui gfx commands to display safe points and additional information in the status line - black and white territory: safe points - Color Magenta (#980098): dame points - Color Red: safe for black and white (should not happen) - Circle: unsurroundable - Status line: point counts, percentage of safe points */ void GoSafetyCommands::CmdGfx(GtpCommand& cmd) { cmd.CheckNuArg(1); string type = cmd.Arg(0); int totalRegions = 0; SgBWSet safe = GetSafe(totalRegions, type); SgPointSet dame; SgPointSet unsurroundable; GoSafetyUtil::FindDameAndUnsurroundablePoints(m_bd, m_bd.AllEmpty(), safe, &dame, &unsurroundable); cmd << "BLACK"; for (SgSetIterator it(safe[SG_BLACK]); it; ++it) cmd << ' ' << SgWritePoint(*it); cmd << '\n'; cmd << "WHITE"; for (SgSetIterator it(safe[SG_WHITE]); it; ++it) cmd << ' ' << SgWritePoint(*it); cmd << '\n'; cmd << "COLOR #980098"; for (SgSetIterator it(dame); it; ++it) cmd << ' ' << SgWritePoint(*it); cmd << '\n'; cmd << "CIRCLE"; for (SgSetIterator it(unsurroundable); it; ++it) cmd << ' ' << SgWritePoint(*it); cmd << '\n'; SgPointSet blackAndWhite = safe[SG_WHITE] & safe[SG_BLACK]; if (blackAndWhite.Size() > 0) { // Shouldn't happen cmd << "COLOR red "; for (SgSetIterator it(blackAndWhite); it; ++it) cmd << ' ' << SgWritePoint(*it); cmd << '\n'; } int nuBlack = safe[SG_BLACK].Size(); int nuWhite = safe[SG_WHITE].Size(); int nuPoints = m_bd.AllPoints().Size(); cmd << "TEXT Solver: " << cmd.Arg(0) << " B: " << nuBlack << " (" << (100 * nuBlack / nuPoints) << " %)" << " W: " << nuWhite << " (" << (100 * nuWhite / nuPoints) << " %)" << " Both: " << (nuBlack + nuWhite) << " (" << (100 * (nuBlack + nuWhite) / nuPoints) << " %)" << " Regions: " << totalRegions; }
/** List of safe points. If no color is given, safe points of both colors are listed. Arguments: benson|static [black|white]<br> Returns: number of point followed bu list of points in one line. */ void GoSafetyCommands::CmdSafe(GtpCommand& cmd) { cmd.CheckNuArgLessEqual(2); string type = cmd.Arg(0); int totalRegions = 0; SgBWSet safe = GetSafe(totalRegions, type); SgPointSet set = (cmd.NuArg() == 2 ? safe[BlackWhiteArg(cmd, 1)] : safe.Both()); cmd << set.Size(); for (SgSetIterator it(set); it; ++it) cmd << ' ' << SgWritePoint(*it); }
void GoBookCommands::CmdLoad(GtpCommand& cmd) { m_fileName = cmd.Arg(); try { m_book.Read(m_fileName); } catch (const SgException& e) { m_fileName = ""; throw GtpFailure() << "loading opening book failed: " << e.what(); } }
void GoBookCommands::CmdSaveAs(GtpCommand& cmd) { if (m_engine.MpiSynchronizer()->IsRootProcess()) { m_fileName = cmd.Arg(); ofstream out(m_fileName.c_str()); m_book.Write(out); if (! out) { m_fileName = ""; throw GtpFailure("write error"); } } }
SgPoint GoGtpCommandUtil::PointArg(const GtpCommand& cmd, std::size_t number, const GoBoard& board) { string arg = cmd.Arg(number); istringstream in(arg); SgPoint p; in >> SgReadPoint(p); if (! in) throw GtpFailure() << "invalid point " << arg; if (p == SG_PASS) throw GtpFailure("expected point, not pass"); if (SgMoveUtil::IsCouponMove(p)) throw GtpFailure("expected point, not coupon move"); if (! board.IsValidPoint(p)) throw GtpFailure() << "point outside board " << arg; return p; }
/** Run a debugger and attach it to the current program. Arguments: debugger-type <br> Currently implemented debugger types: - gdb_kde GDB in KDE terminal - gdb_gnome GDB in GNOME terminal */ void SgGtpCommands::CmdDebugger(GtpCommand& cmd) { cmd.CheckNuArg(1); string type = cmd.Arg(0); const char* path = m_programPath; if (path == 0) throw GtpFailure("location of executable unknown"); pid_t pid = getpid(); ostringstream s; if (type == "gdb_kde") s << "konsole -e gdb " << path << ' ' << pid << " &"; else if (type == "gdb_gnome") s << "gnome-terminal -e 'gdb " << path << ' ' << pid << "' &"; else throw GtpFailure() << "unknown debugger: " << type; SgDebug() << "Executing: " << s.str() << '\n'; int retval = system(s.str().c_str()); if (retval != 0) throw GtpFailure() << "command returned " << retval; }
/** Set global parameters used in module SmartGame. Parameters: @arg @c time_mode cpu|real See SgTime */ void SgGtpCommands::CmdParam(GtpCommand& cmd) { cmd.CheckNuArgLessEqual(2); if (cmd.NuArg() == 0) { // Boolean parameters first for better layout of GoGui parameter // dialog, alphabetically otherwise cmd << "[list/cpu/real] time_mode " << TimeModeToString(SgTime::DefaultMode()) << '\n'; } else if (cmd.NuArg() >= 1 && cmd.NuArg() <= 2) { string name = cmd.Arg(0); if (name == "time_mode") SgTime::SetDefaultMode(TimeModeArg(cmd, 1)); else throw GtpFailure() << "unknown parameter: " << name; } else throw GtpFailure() << "need 0 or 2 arguments"; }
/** Execute GTP commands from a file. Argument: filename <br> Aborts on the first command that fails. Responses to the commands in the file are written to SgDebug() @see GtpEngine::ExecuteFile */ void SgGtpCommands::CmdExec(GtpCommand& cmd) { m_engine.ExecuteFile(cmd.Arg(), SgDebug()); }
/** Execute GTP commands from a file. Argument: filename <br> Aborts on the first command that fails. Responses to the commands in the file are written to SgDebug() @see GtpEngine::ExecuteFile */ void SgGtpCommands::CmdExec(GtpCommand& cmd) { cmd.CheckNuArg(1); m_engine.ExecuteFile(cmd.Arg(0), SgDebug()); }