예제 #1
0
bool GoEyeUtil::IsTreeShape(const SgPointSet& area)
{
    for (SgSetIterator it(area); it; ++it)
    {
        const SgPoint p(*it);
        if (   area.Contains(p + SG_NS)
            && area.Contains(p + SG_WE)
            && area.Contains(p + SG_NS + SG_WE)
           )
           return false;
    }
    return true;
}
예제 #2
0
long GoEyeUtil::DegreeCode8(const SgPointSet& points)
{
    int degrees[9] = {0,0,0,0,0};
    
    for (SgSetIterator it(points); it; ++it)
    {
        const SgPoint p(*it);
        int nbs = 0;
        for (SgNb8Iterator it(p); it; ++it)
        {
            if (points.Contains(*it))
                ++nbs;
        }
        ++(degrees[nbs]);
    }
    return              degrees[0] 
                 + 10 * degrees[1]
                + 100 * degrees[2]
               + 1000 * degrees[3]
              + 10000 * degrees[4]
             + 100000 * degrees[5]
            + 1000000 * degrees[6]
           + 10000000 * degrees[7]
          + 100000000 * degrees[8];
}
예제 #3
0
void GoChain::GetBlocks(const GoRegionBoard* ra, 
                        SgVectorOf<GoBlock>* blocks) const
{
    SgBlackWhite color = Color();
    SgPointSet chainPts = Stones();
    for (SgVectorIteratorOf<GoBlock> it(ra->AllBlocks(color)); it; ++it)
        if (chainPts.Contains((*it)->Anchor()))
            blocks->PushBack(*it);
}
예제 #4
0
bool GoEyeUtil::CheckInterior(const GoBoard& bd, const SgPointSet& area,
                   SgBlackWhite opp, bool checkBlocks)
{
    bool hasSingleNbPoint = false;
    int nuPoints = 0;
    for (SgSetIterator it(area); it; ++it)
    {
        const SgPoint p(*it);
        if (bd.IsEmpty(p))
        {
            int nuNbs = 0;
            if (area.Contains(p + SG_NS))
                ++nuNbs;
            if (area.Contains(p - SG_NS))
                ++nuNbs;
            if (area.Contains(p + SG_WE))
                ++nuNbs;
            if (area.Contains(p - SG_WE))
                ++nuNbs;
            if (nuNbs == 1)
                hasSingleNbPoint = true;
            else if (nuNbs > 2)
                return false;
        }
        else if (p == bd.Anchor(p))
        {
            if (bd.GetColor(p) != opp)
            // if own stones on inside: not a tree shape.
                return false;
            int nuLibs = bd.NumLiberties(p);
            if (nuLibs == 1)
                hasSingleNbPoint = true;
            else if (checkBlocks && nuLibs > 2)
                return false;
        }
        ++nuPoints;
    }
    return nuPoints == 1 || hasSingleNbPoint;
}
예제 #5
0
bool GoEyeUtil::IsLocalSplitPt(SgPoint p, const SgPointSet& set)
{
    int nuNb = 0;
    for (SgNb4Iterator it(p); it; ++it)
    {
        if (set.Contains(*it))
        {
            ++nuNb;
            if (nuNb >= 2)
                break;
        }
    }
    if (nuNb >= 2)
    {
        if (set[p - SG_NS])
        {
            if (set[p - SG_WE] && TestDiagonal(set, p, -SG_NS, -SG_WE))
                return true;
            if (set[p + SG_NS] && TestOpposite(set, p, SG_NS, SG_WE))
                return true;
            if (set[p + SG_WE] && TestDiagonal(set, p, -SG_NS, +SG_WE))
                return true;
        }
        if (set[p + SG_NS])
        {
            if (set[p - SG_WE] && TestDiagonal(set, p, +SG_NS, -SG_WE))
                return true;
            if (set[p + SG_WE] && TestDiagonal(set, p, +SG_NS, +SG_WE))
                return true;
        }
        if (set[p - SG_WE] && set[p + SG_WE]
            && TestOpposite(set, p, SG_WE, SG_NS))
            return true;
    }
    return false; // no local split found.
}