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;
}
Beispiel #2
0
GoLadderStatus GoLadderUtil::LadderStatus(const GoBoard& bd, SgPoint prey,
                                          bool twoLibIsEscape,
                                          SgPoint* toCapture,
                                          SgPoint* toEscape)
{
    SG_ASSERT(bd.IsValidPoint(prey));
    SG_ASSERT(bd.Occupied(prey));
#ifndef NDEBUG
    SgHashCode oldHash = bd.GetHashCode();
#endif
    // Unsettled only if can capture when hunter plays first, and can escape
    // if prey plays first.
    GoLadder ladder;
    SgBlackWhite preyColor = bd.GetStone(prey);
    SgVector<SgPoint> captureSequence;
    GoLadderStatus status = GO_LADDER_ESCAPED;
    if (ladder.Ladder(bd, prey, SgOppBW(preyColor), &captureSequence,
                      twoLibIsEscape) < 0)
    {
        SgVector<SgPoint> escapeSequence;
        if (ladder.Ladder(bd, prey, preyColor, &escapeSequence,
                          twoLibIsEscape) < 0)
            status = GO_LADDER_CAPTURED;
        else
        {
            status = GO_LADDER_UNSETTLED;
            // Unsettled = ladder depends on who plays first, so there must
            // be a move that can be played.
            SG_ASSERT(captureSequence.NonEmpty());
            // escapeSequence can be empty in 2 libs, prey to play case
            SG_ASSERT(twoLibIsEscape || escapeSequence.NonEmpty());
            if (toCapture)
                *toCapture = captureSequence.Front();
            if (toEscape)
                *toEscape = escapeSequence.IsEmpty() ? SG_PASS :
                                                       escapeSequence.Front();
        }
    }
#ifndef NDEBUG
    // Make sure Ladder didn't change the board position.
    SG_ASSERT(oldHash == bd.GetHashCode());
#endif
    return status;
}
Beispiel #3
0
bool GoLadderUtil::Ladder(const GoBoard& bd, SgPoint prey,
                          SgBlackWhite toPlay, bool twoLibIsEscape,
                          SgVector<SgPoint>* sequence)
{
    SG_ASSERT(bd.IsValidPoint(prey));
    SG_ASSERT(bd.Occupied(prey));
    // @todo for an unsettled block with 2 liberties, it
    // immediately says it can escape, but does not return a move.
    // Sequence is empty.  Have to special case this and look for
    // moves that escape from ladder myself.
#ifndef NDEBUG
    SgHashCode oldHash = bd.GetHashCode();
#endif
    GoLadder ladder;
    int result = ladder.Ladder(bd, prey, toPlay, sequence, twoLibIsEscape);
#ifndef NDEBUG
    // Make sure Ladder didn't change the board position.
    SG_ASSERT(oldHash == bd.GetHashCode());
#endif
    SG_ASSERT(result != 0);
    return (result < 0);
}