/** 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;
}
Exemple #2
0
/** 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;
}
SgPoint GoGtpCommandUtil::PointArg(const GtpCommand& cmd,
                                   const GoBoard& board)
{
    cmd.CheckNuArg(1);
    return PointArg(cmd, 0, board);
}
Exemple #4
0
/** Set and store random seed.
    Arguments: seed <br>
    See SgRandom::SetSeed(int) for the special meaning of zero and negative
    values.
*/
void SgGtpCommands::CmdSetRandomSeed(GtpCommand& cmd)
{
    cmd.CheckNuArg(1);
    SgRandom::SetSeed(cmd.IntArg(0));
}
Exemple #5
0
/** 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());
}