예제 #1
0
파일: RlEngine.cpp 프로젝트: muupan/rlgo
void RlEngine::CmdAnalyzeCommands(GtpCommand& cmd)
{
    GoGtpEngine::CmdAnalyzeCommands(cmd);
    m_commands.AddGoGuiAnalyzeCommands(cmd);
    string response = cmd.Response();
    cmd.SetResponse(GoGtpCommandUtil::SortResponseAnalyzeCommands(response));
}
예제 #2
0
void FuegoTestEngine::CmdAnalyzeCommands(GtpCommand& cmd)
{
    GoGtpEngine::CmdAnalyzeCommands(cmd);
    m_extraCommands.AddGoGuiAnalyzeCommands(cmd);
    m_safetyCommands.AddGoGuiAnalyzeCommands(cmd);
    cmd <<
        "param/FuegoTest Param/fuegotest_param\n";
    string response = cmd.Response();
    cmd.SetResponse(GoGtpCommandUtil::SortResponseAnalyzeCommands(response));
}
예제 #3
0
/** Run another GTP command and compare its response against a float value.
    Arguments: float command [arg...] <br>
    Returns: -1 if response is smaller than float; 1 otherwise.
*/
void SgGtpCommands::CmdCompareFloat(GtpCommand& cmd)
{
    double value = cmd.FloatArg(0);
    string response = m_engine.ExecuteCommand(cmd.RemainingLine(0));
    istringstream in(response);
    double responseValue;
    in >> responseValue;
    if (! in)
        throw GtpFailure() << "response '" << response << "' is not a float";
    cmd << (responseValue < value ? "-1" : "1");
}
예제 #4
0
/** 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);
}
예제 #5
0
SgMove GoGtpCommandUtil::MoveArg(const GtpCommand& cmd, std::size_t number,
                                 const GoBoard& board)
{
    if (cmd.ArgToLower(number) == "pass")
        return SG_PASS;
    return PointArg(cmd, number, board);
}
예제 #6
0
/** Switch debug logging on/off. */
void SgGtpCommands::CmdQuiet(GtpCommand& cmd)
{
    if (cmd.BoolArg(0))
        SgDebugToNull();
    else
        SgSwapDebugStr(&cerr);
}
예제 #7
0
void GoBookCommands::CmdMoves(GtpCommand& cmd)
{
    cmd.CheckArgNone();
    vector<SgPoint> active = m_book.LookupAllMoves(m_bd);
    for (vector<SgPoint>::const_iterator it = active.begin();
         it != active.end(); ++it)
        cmd << SgWritePoint(*it) << ' ';
}
예제 #8
0
/** Run another GTP command and compare its response against an integer value.
    Arguments: int command [arg...] <br>
    Returns: -1 if response is smaller than int; 0 if it is equal; 1 if it is
    greater
*/
void SgGtpCommands::CmdCompareInt(GtpCommand& cmd)
{
    int value = cmd.IntArg(0);
    string response = m_engine.ExecuteCommand(cmd.RemainingLine(0));
    istringstream in(response);
    int responseValue;
    in >> responseValue;
    if (! in)
        throw GtpFailure() << "response '" << response
                           << "' is not an integer";
    if (responseValue == value)
        cmd << "0";
    else if (responseValue < value)
        cmd << "-1";
    else
        cmd << "1";
}
예제 #9
0
/** 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;
}
예제 #10
0
SgVector<SgPoint> GoGtpCommandUtil::PointListArg(const GtpCommand& cmd,
                                               std::size_t number,
                                               const GoBoard& board)
{
    SgVector<SgPoint> result;
    for (size_t i = number; i < cmd.NuArg(); ++i)
        result.PushBack(PointArg(cmd, i, board));
    return result;
}
예제 #11
0
/** Return the process ID. */
void SgGtpCommands::CmdPid(GtpCommand& cmd)
{
#if WIN32
    throw GtpFailure("command not implemented on Windows");
#else
    cmd.CheckArgNone();
    cmd << getpid();
#endif
}
예제 #12
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;
}
예제 #13
0
SgBlackWhite GoGtpCommandUtil::BlackWhiteArg(const GtpCommand& cmd,
                                             std::size_t number)
{
    string value = cmd.ArgToLower(number);
    if (value == "b" || value == "black")
        return SG_BLACK;
    if (value == "w" || value == "white")
        return SG_WHITE;
    throw GtpFailure() << "argument " << (number + 1)
                       << " must be black or white";
}
예제 #14
0
/** Return dame points after running static safety algorithm. */
void GoSafetyCommands::CmdDameStatic(GtpCommand& cmd)
{
    cmd.CheckArgNone();
    GoModBoard modBoard(m_bd);
    GoBoard& bd = modBoard.Board();
    GoRegionBoard regionAttachment(bd);
    GoSafetySolver solver(bd, &regionAttachment);
    SgBWSet safe;
    solver.FindSafePoints(&safe);
    SgPointSet dame = GoSafetyUtil::FindDamePoints(bd, m_bd.AllEmpty(), safe);
    cmd << SgWritePointSet(dame, "", false);
}
예제 #15
0
/** 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";
}
예제 #16
0
/** 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";
}
예제 #17
0
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();
    }
}
예제 #18
0
//----------------------------------------------------------------------------
SgUctMoveSelect SgGtpUtil::MoveSelectArg(const GtpCommand& cmd, size_t number)
{
    std::string arg = cmd.ArgToLower(number);
    if (arg == "value")
        return SG_UCTMOVESELECT_VALUE;
    if (arg == "count")
        return SG_UCTMOVESELECT_COUNT;
    if (arg == "bound")
        return SG_UCTMOVESELECT_BOUND;
    if (arg == "estimate")
        return SG_UCTMOVESELECT_ESTIMATE;
    throw GtpFailure() << "unknown move select argument \"" << arg << '"';
}
예제 #19
0
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");
        }
    }
}
예제 #20
0
void GoBookCommands::CmdSave(GtpCommand& cmd)
{
    if (m_engine.MpiSynchronizer()->IsRootProcess())
    {
    cmd.CheckArgNone();
    if (m_fileName == "")
        throw GtpFailure("no filename associated with current book");
    ofstream out(m_fileName.c_str());
    m_book.Write(out);
    if (! out)
    {
        throw GtpFailure() << "error writing to file '" << m_fileName << "'";
    }
    }
}
예제 #21
0
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;
}
예제 #22
0
void GoGtpCommandUtil::ParseMultiStoneArgument(GtpCommand& cmd,
                                               const GoBoard& board,
                                               SgBlackWhite& toPlay,
                                               SgBlackWhite& defender,
                                               SgVector<SgPoint>& crucial)
{
    toPlay = GoGtpCommandUtil::BlackWhiteArg(cmd, 0);
    SgDebug() << "Set " << SgBW(toPlay) << " to play\n";
    SgPoint point = GoGtpCommandUtil::StoneArg(cmd, 1, board);
    defender = board.GetColor(point);
    SG_ASSERT(defender == SG_BLACK || defender == SG_WHITE);
    crucial.PushBack(point);
    for (size_t i = 2; i < cmd.NuArg(); ++i)
    {
        SgPoint p = GoGtpCommandUtil::StoneArg(cmd, i, board);
        if (board.GetColor(p) != defender)
            throw GtpFailure("Crucial stones must be same color");
        else
            crucial.PushBack(p);
    }
}
예제 #23
0
/** Show information about current book. */
void GoBookCommands::CmdInfo(GtpCommand& cmd)
{
    cmd.CheckArgNone();
    cmd << SgWriteLabel("FileName") << m_fileName << '\n';
    m_book.WriteInfo(cmd);
}
예제 #24
0
/** Echo command argument line as response.
    This command is compatible with GNU Go's 'echo' command. */
void SgGtpCommands::CmdEcho(GtpCommand& cmd)
{
    cmd << cmd.ArgLine();
}
예제 #25
0
/** Echo command argument line to std::cerr.
    This command is compatible with GNU Go's 'echo_err' command. */
void SgGtpCommands::CmdEchoErr(GtpCommand& cmd)
{
    string line = cmd.ArgLine();
    cerr << line << endl;
    cmd << line;
}
예제 #26
0
SgPoint GoGtpCommandUtil::PointArg(const GtpCommand& cmd,
                                   const GoBoard& board)
{
    cmd.CheckNuArg(1);
    return PointArg(cmd, 0, board);
}
예제 #27
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)
{
    m_engine.ExecuteFile(cmd.Arg(), SgDebug());
}
예제 #28
0
/** Return the current random seed.
    See SgRandom::SetSeed(int) for the special meaning of zero and negative
    values. */
void SgGtpCommands::CmdGetRandomSeed(GtpCommand& cmd)
{
    cmd.CheckArgNone();
    cmd << SgRandom::Seed();
}
예제 #29
0
void GoBookCommands::CmdClear(GtpCommand& cmd)
{
    cmd.CheckArgNone();
    m_book.Clear();
}
예제 #30
0
/** Show book information for current positions.
    This command is compatible with the GoGui analyze command type "gfx".
    Moves in the book for the current position are marked with a green
    color (active moves), moves that lead to a known position in the book
    with yellow (other moves). The status line shows the line number of the
    position in the file (0, if unknown) and the number of active and other
    moves. */
void GoBookCommands::CmdPosition(GtpCommand& cmd)
{
    cmd.CheckArgNone();
    PositionInfo(cmd);
}