/** Return true, if point is on edge line and no stone is within a Manhattan distance of 4. */ bool IsEmptyEdge(const GoBoard& bd, SgPoint p) { SG_ASSERT (bd.IsEmpty(p)); SG_ASSERT (bd.Line(p) == 1); if (bd.Num8EmptyNeighbors(p) < 5) return false; const SgPoint pUp = p + bd.Up(p); SG_ASSERT(bd.Line(pUp) == 2); SG_ASSERT(bd.Pos(pUp) >= 2); // (1,1) goes to (2,2) if (bd.Num8EmptyNeighbors(pUp) < 8) return false; switch (bd.Pos(p)) { case 1: // (1,1) point case 2: // (1,2) point case 3: return IsEmptyOrInCorner(bd, p, bd.Left(p)) && IsEmptyOrInCorner(bd, p, bd.Right(p)); // assume in empty corner, 1st line is always // dominated bymove on 2nd line above default: // > 3, can test both sides easily return IsEmpty2x3Box(bd, p + 2*bd.Left(p)) && IsEmpty2x3Box(bd, p + 2*bd.Right(p)) ; } }
bool GoEyeUtil::NumberOfMoveToEye(const GoBoard& board, SgBlackWhite color, SgPoint p, int& number) { SG_ASSERT(board.IsEmpty(p)); SgBlackWhite att = SgOppBW(color); // attacker if ( board.Line(p) == 1) // corner or edge { if ( board.Num8Neighbors(p, att) > 0 ) return false; else { number = board.Num8EmptyNeighbors(p); return true; } } else // in center { if ( board.Num8Neighbors(p, att) >= 2 ) return false; else if ( board.NumNeighbors(p, att) > 0 ) return false; else // only 0 or 1 attacker point and not in NB4 { number = board.Num8EmptyNeighbors(p); return true; } } }
bool GoEyeUtil::IsPossibleEye(const GoBoard& board, SgBlackWhite color, SgPoint p) { bool isPossibleEye = false; SG_ASSERT(board.GetColor(p) != color); const SgBlackWhite opp = SgOppBW(color); if (board.Line(p) == 1) // corner or edge { const int nuOwn = (board.Pos(p) == 1) ? 2 : 4; if ( board.Num8Neighbors(p, color) == nuOwn && board.Num8EmptyNeighbors(p) == 1 ) { isPossibleEye = true; } } else // in center { // have all neighbors, and 2 diagonals, and can get a third if ( board.NumNeighbors(p, color) == 4 && board.NumDiagonals(p, color) == 2 && board.NumEmptyDiagonals(p) > 0 ) { isPossibleEye = true; } // have 3 of 4 neighbors, can get the 4th, and have enough diagonals else if ( board.NumNeighbors(p, color) == 3 && board.NumNeighbors(p, opp) == 0 && board.NumDiagonals(p, color) >= 3 ) { isPossibleEye = true; } } return isPossibleEye; }
//---------------------------------------------------------------------------- inline bool IsEmpty2x3Box(const GoBoard& bd, SgPoint p) { SG_ASSERT (bd.Line(p) == 1); SG_ASSERT (bd.Pos(p) > 1); return bd.IsEmpty(p) && bd.Num8EmptyNeighbors(p) == 5; }