本文整理汇总了C++中SgPointSet类的典型用法代码示例。如果您正苦于以下问题:C++ SgPointSet类的具体用法?C++ SgPointSet怎么用?C++ SgPointSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SgPointSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PreviousBlocksAt
void GoRegionBoard::MergeAdjacentAndAddBlock(SgPoint move,
SgBlackWhite capturedColor)
{
SgVector<SgPoint> nb;
for (GoNbIterator it(Board(), move); it; ++it)
if (Board().IsEmpty(*it))
nb.PushBack(*it);
SgVectorOf<GoBlock> captures;
PreviousBlocksAt(nb, capturedColor, &captures);
SG_ASSERT(captures.NonEmpty());
SgPointSet captured;
{for (SgVectorIteratorOf<GoBlock> it(captures); it; ++it)
captured |= (*it)->Stones();
}
SgVectorOf<GoRegion> adj;
const int size = Board().Size();
RegionsAt(captured.Border(size), capturedColor, &adj);
SG_ASSERT(adj.NonEmpty());
GoRegion* r = MergeAll(adj, captured, capturedColor);
SG_UNUSED(r);
for (SgVectorIteratorOf<GoBlock> it(captures); it; ++it)
RemoveBlock(*it, true, false);
// don't remove from regions; already gone.
}
示例2: SgDebug
void GoRegionBoard::OnExecutedUncodedMove(int move, SgBlackWhite moveColor)
{
if (DEBUG_REGION_BOARD)
SgDebug() << "OnExecutedUncodedMove " << SgWritePoint(move) << '\n';
{
m_stack.StartMoveInfo();
if (move != SG_PASS)
{
SG_ASSERT(! Board().LastMoveInfo(GO_MOVEFLAG_SUICIDE));
// can't handle yet,
// should be forbidden anyway. @todo allowed in Chinese rules.
bool fWasCapture = Board().LastMoveInfo(GO_MOVEFLAG_CAPTURING);
UpdateBlock(move, moveColor);
{
GoRegion* r = PreviousRegionAt(move, moveColor);
bool split = GoEyeUtil::IsSplitPt(move, r->Points());
r->OnAddStone(move);
PushStone(r, move);
SgPointSet points = r->Points();
// needed even after RemoveRegion(r).
if (split || points.IsEmpty())
// must remove old region before generating new ones,
// because removing clears m_anchor[]
RemoveRegion(r);
if (split) // find new regions
{
for (SgConnCompIterator it(points, Board().Size());
it; ++it)
GenRegion(*it, moveColor);
}
}
if (fWasCapture)
{
// FindNewNeighborRegions(move, moveColor);
MergeAdjacentAndAddBlock(move, SgOppBW(moveColor));
}
m_code = Board().GetHashCode();
if (HEAVYCHECK)
CheckConsistency();
}
}
{
for (SgBWIterator it; it; ++it)
{
SgBlackWhite color(*it);
for (SgVectorIteratorOf<GoRegion> it(AllRegions(color)); it; ++it)
{ GoRegion* r1 = *it;
if (! r1->IsValid())
r1->ComputeBasicFlags();
}
}
}
}
示例3: FindGlobalPatternAndAtariMoves
/** Find global moves that match a playout pattern or set a block into atari.
@param[out] pattern
@param[out] atari
@param[out] empty As a side effect, this function finds all empty points
on the board
@return @c true if any such moves was found
*/
bool GoUctDefaultPriorKnowledge::FindGlobalPatternAndAtariMoves(
SgPointSet& pattern,
SgPointSet& atari,
GoPointList& empty) const
{
SG_ASSERT(empty.IsEmpty());
const GoUctPatterns<GoBoard>& patterns = m_policy.Patterns();
bool result = false;
for (GoBoard::Iterator it(m_bd); it; ++it)
if (m_bd.IsEmpty(*it))
{
empty.PushBack(*it);
if (patterns.MatchAny(*it))
{
pattern.Include(*it);
result = true;
}
if (SetsAtari(m_bd, *it))
{
atari.Include(*it);
result = true;
}
}
return result;
}
示例4: FindGlobalPatternAndAtariMoves
/** Find global moves that match a playout pattern or set a block into atari.
@param[out] pattern
@param[out] atari
@param[out] empty As a side effect, this function finds all empty points
on the board
@return @c true if any such moves was found */
bool GoUctDefaultPriorKnowledge::FindGlobalPatternAndAtariMoves(
SgPointSet& pattern,
SgPointSet& atari,
GoPointList& empty)
{
// Minimum value for pattern gamma to be used.
static const float EPSILON = 0.00000000001;
const GoBoard& bd = Board();
SG_ASSERT(empty.IsEmpty());
const GoUctPatterns<GoBoard>& patterns = m_policy.GlobalPatterns();
bool result = false;
m_maxPatternGamma = -1.f;
for (GoBoard::Iterator it(bd); it; ++it)
if (bd.IsEmpty(*it))
{
empty.PushBack(*it);
float gamma = patterns.GetPatternGamma(bd, *it, bd.ToPlay());
if (gamma > EPSILON)
{
pattern.Include(*it);
result = true;
m_patternGammas[*it] = gamma;
if (gamma > m_maxPatternGamma)
m_maxPatternGamma = gamma;
}
if (SetsAtari(bd, *it))
{
atari.Include(*it);
result = true;
}
}
return result;
}
示例5: safetySolver
SgPointSet SpUtil::GetRelevantMoves(GoBoard& bd, SgBlackWhite toPlay,
bool useFilter)
{
SgPointSet legal;
for (SgSetIterator it(bd.AllEmpty()); it; ++it)
if (bd.IsLegal(*it))
legal.Include(*it);
if (! useFilter)
return legal;
GoSafetySolver safetySolver(bd);
SgBWSet safe;
safetySolver.FindSafePoints(&safe);
SgBlackWhite opp = SgOppBW(toPlay);
SgPointSet moves;
const GoRules& rules = bd.Rules();
const bool captureDead = rules.CaptureDead();
//const bool japaneseScoring = rules.JapaneseScoring();
for (SgSetIterator it(legal); it; ++it)
{
SgPoint p = *it;
const bool isSafe = safe[toPlay].Contains(p);
const bool isSafeOpp = safe[opp].Contains(p);
const bool hasOppNeighbors = bd.HasNeighbors(p, opp);
if ( (! isSafe && ! isSafeOpp)
|| (isSafe && captureDead && hasOppNeighbors)
// || (isSafeOpp && ! japaneseScoring)
)
moves.Include(p);
}
return moves;
}
示例6: Color
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);
}
示例7: SG_ASSERT
void GoBlock::CheckConsistency() const
{
SG_ASSERT(Stones().SubsetOf(m_bd.All(Color())));
SgPoint anchor = Anchor();
SG_ASSERT(m_bd.Anchor(anchor) == Anchor());
SgPointSet stones;
for (GoBoard::StoneIterator it(m_bd, anchor); it; ++it)
stones.Include(*it);
SG_ASSERT(Stones() == stones);
}
示例8: Points
void GoRegion::Find2FreeLibs(const GoChain* c1, const GoChain* c2,
SgPoint* lib1, SgPoint* lib2) const
{
SgPointSet libs = Points() & c1->FreeLiberties() & c2->FreeLiberties();
if (CHECK)
SG_ASSERT(libs.MinSetSize(2));
SgSetIterator it(libs);
*lib1 = *it;
++it;
*lib2 = *it;
}
示例9: GetSafe
/** 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);
}
示例10: IsTreeShape
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;
}
示例11: p
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];
}
示例12: Magenta
/** 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;
}
示例13: CheckInterior
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;
}
示例14: IsNakadeShape
bool GoEyeUtil::IsNakadeShape(const SgPointSet& area)
{
switch (area.Size())
{
case 1:
case 2:
case 3: return true;
case 4: return IsBulkyFour(area) || IsTShape(area);
case 5: return IsBulkyFive(area) || IsCross(area);
case 6: return IsRabbitySix(area);
default: // too big
return false;
}
}
示例15: IsLocalSplitPt
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.
}