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; }
bool GoLadderUtil::IsLadderCaptureMove(const GoBoard& constBd, SgPoint prey, SgPoint firstMove) { SG_ASSERT(constBd.NumLiberties(prey) == 2); SG_ASSERT(constBd.IsLibertyOfBlock(firstMove, constBd.Anchor(prey))); GoModBoard mbd(constBd); GoBoard& bd = mbd.Board(); const SgBlackWhite defender = bd.GetStone(prey); const SgBlackWhite attacker = SgOppBW(defender); GoRestoreToPlay r(bd); bd.SetToPlay(attacker); if (PlayIfLegal(bd, firstMove, attacker)) { GoLadder ladder; bool isCapture = ladder.Ladder(bd, prey, defender, 0, false/*twoLibIsEscape*/ ) < 0; bd.Undo(); return isCapture; } else return false; }