本文整理汇总了C++中GoBoard类的典型用法代码示例。如果您正苦于以下问题:C++ GoBoard类的具体用法?C++ GoBoard怎么用?C++ GoBoard使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GoBoard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindInfluence
void GoInfluence::FindInfluence(const GoBoard& board,
int nuExpand,
int nuShrink,
SgBWSet* influence)
{
SgBWSet result = SgBWSet(board.All(SG_BLACK), board.All(SG_WHITE));
SgBWSet next;
const int size = board.Size();
for (int i = 1; i <= nuExpand; ++i)
{
for (SgBlackWhite c = SG_BLACK; c <= SG_WHITE; ++c)
{
SgBlackWhite opp = SgOppBW(c);
next[c] = result[c].Border(size) - result[opp];
}
result[SG_BLACK] |= (next[SG_BLACK] - next[SG_WHITE]);
result[SG_WHITE] |= (next[SG_WHITE] - next[SG_BLACK]);
}
for (int i = 1; i <= nuShrink; ++i)
{
result[SG_BLACK] = result[SG_BLACK].Kernel(size);
result[SG_WHITE] = result[SG_WHITE].Kernel(size);
}
*influence = result;
}
示例2: DrawPieces
void Mesh::DrawPieces(GoBoard &board) {
glTranslatef(PIECE_OFFSET, BOARD_HEIGHT, PIECE_OFFSET);
glScalef(PIECE_X_SCALE, PIECE_Y_SCALE, PIECE_Z_SCALE);
//glTranslatef(0.5f, 0.5f, 0.5f);
for (int x = 0; x < 9; x++) {
for (int y = 0; y < 9; y++) {
char space = board.getPiece(x, y);
if (space != 0) {
float color = (space + 1) / 2 + 0.2;
glColor3f(color, color, color);
DrawMesh(piece, piece_tri_verts_VBO);
//glutSolidSphere(0.5, 10, 10);
}
glTranslatef(0, 0, BOARD_GRID_SPACING);
}
glTranslatef(0, 0, -BOARD_MAX/PIECE_Z_SCALE);
glTranslatef(BOARD_GRID_SPACING, 0, 0);
}
glTranslatef(-BOARD_MAX/PIECE_X_SCALE, 0, 0);
auto sP = board.getSpeculativePiece();
//if (board.legalMove(sP.second, sP.first.first, sP.first.second)) {
glTranslatef(BOARD_GRID_SPACING*sP.first.x, 0, BOARD_GRID_SPACING*sP.first.y);
float color = (sP.second + 1) / 2 + 0.2;
glColor3f(color, 0, color);
//glutSolidSphere(0.5, 10, 10);
DrawMesh(piece, piece_tri_verts_VBO);
//}
//endTranslate();
}
示例3: SgException
void GoBook::Add(const GoBoard& bd, SgPoint move)
{
if (move != SG_PASS && bd.Occupied(move))
throw SgException("point is not empty");
if (! bd.IsLegal(move))
throw SgException("move is not legal");
const GoBook::MapEntry* mapEntry = LookupEntry(bd);
if (mapEntry == 0)
{
vector<SgPoint> moves;
moves.push_back(move);
GoBoard tempBoard;
InsertEntry(GetSequence(bd), moves, bd.Size(), tempBoard, 0);
}
else
{
size_t id = mapEntry->m_id;
SG_ASSERT(id < m_entries.size());
Entry& entry = m_entries[id];
int invRotation = SgPointUtil::InvRotation(mapEntry->m_rotation);
SgPoint rotMove = SgPointUtil::Rotate(invRotation, move, bd.Size());
if (! Contains(entry.m_moves, rotMove))
entry.m_moves.push_back(rotMove);
}
}
示例4: ProtectedCuts
bool GoRegion::ProtectedCuts(const GoBoard& board) const
{
if (! GetFlag(GO_REGION_CORRIDOR))
return false;
if (m_blocks.IsLength(2))
/* */ return Safe2Cuts(board); /* */ // easy case of only 2 blocks
bool prot = true;
SgPointSet allCuts;
const int size = board.Size();
GoBlock* block1, *block2;
for (SgVectorPairIteratorOf<GoBlock> it(m_blocks);
it.NextPair(block1, block2);)
{
SgPointSet lib1(block1->Stones().Border(size));
SgPointSet lib2(block2->Stones().Border(size));
SgPointSet cuts(lib1 & lib2 & Points());
if (! cuts.SubsetOf(board.AllEmpty()))
// cut occupied by opponent. Bad for us.
return false;
else
allCuts |= cuts;
}
// no eye space left ? hard to distinguish false eyes from ok
// AR why must this be checked??? Should not matter for flat regions.
// Try to take it out.
//if (Points().SubsetOf(allCuts | allCuts.Border()))
// prot = false;
return prot;
}
示例5: IsVitalPt
bool GoEyeUtil::IsVitalPt(const SgPointSet& points, SgPoint p,
SgBlackWhite opp,
const GoBoard& bd)
{
// in corridors a vital point has 2 nbs, in big ones it may have 3 or 4.
// but: 2 in following
// example: unsettled nakade, non-flat points are all occupied by opp.
// .a a is vital Point.
// o.
// .
int numNb = bd.NumEmptyNeighbors(p) + bd.NumNeighbors(p, opp);
if (numNb >= 2)
{
if (numNb >= 4)
/* */ return true; /* */
int nu = IsTreeShape(points) ? 2 : 3;
if (numNb >= nu)
{
if (numNb == 2 && bd.IsEmpty(p))
return IsSplitPt(p, points);
else
return true;
}
}
return false;
}
示例6: SgOppBW
bool GoEyeUtil::IsSinglePointEye2(const GoBoard& board, SgPoint p,
SgBlackWhite color, SgVector<SgPoint>& eyes)
{
// Must be an empty point
if (! board.IsColor(p, SG_EMPTY))
return false;
// All adjacent neighbours must be friendly
SgBoardColor opp = SgOppBW(color);
for (SgNb4Iterator adj(p); adj; ++adj)
{
SgBoardColor adjColor = board.GetColor(*adj);
if (adjColor == opp || adjColor == SG_EMPTY)
return false;
}
// All diagonals (with up to one exception) must be friendly or an eye
int baddiags = 0;
int maxbaddiags = (board.Line(p) == 1 ? 0 : 1);
for (SgNb4DiagIterator it(p); it; ++it)
{
if (board.IsColor(*it, opp))
++baddiags;
if (board.IsColor(*it, SG_EMPTY) && ! eyes.Contains(*it))
{
// Assume this point is an eye and recurse
eyes.PushBack(p);
if (! IsSinglePointEye2(board, *it, color, eyes))
++baddiags;
eyes.PopBack();
}
if (baddiags > maxbaddiags)
return false;
}
return true;
}
示例7: GetRelevantMoves
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;
}
示例8: GoBoardSynchronizer
GoPlayer::GoPlayer(const GoBoard& bd)
: GoBoardSynchronizer(bd),
m_currentNode(0),
m_bd(bd.Size(), GoSetup(), bd.Rules()),
m_variant(0)
{
SetSubscriber(m_bd);
ClearSearchTraces();
}
示例9: GoBoard
GoBoard* GoBoard::copyBoard() const
{
GoBoard* nBoard = new GoBoard(Size());
for(int i = 0; i<movePointer; ++i)
{
nBoard->Play(moves[i]->Point);
}
return nBoard;
}
示例10: LibertyAveragex10
int LibertyAveragex10(const GoBoard& board, SgBlackWhite color)
{
int nuLibs = 0, nuBlocks = 0;
const int size = board.Size();
for (SgConnCompIterator it(board.All(color), board.Size()); it; ++it)
{
++nuBlocks;
nuLibs += ((*it).Border(size) & board.AllEmpty()).Size();
}
return (nuBlocks == 0) ? 0 : 10 * nuLibs / nuBlocks;
}
示例11:
void GoBook::Entry::ApplyTo(GoBoard& bd) const
{
if (bd.Size() != m_size)
bd.Init(m_size);
GoBoardUtil::UndoAll(bd);
for (vector<SgPoint>::const_iterator it = m_sequence.begin();
it != m_sequence.end(); ++it)
{
SG_ASSERT(bd.IsLegal(*it));
bd.Play(*it);
}
}
示例12: CurrentPosSetup
GoSetup GoSetupUtil::CurrentPosSetup(const GoBoard& bd)
{
GoSetup setup;
setup.m_player = bd.ToPlay();
for (GoBoard::Iterator it2(bd); it2; ++it2)
{
SgPoint p = *it2;
if (bd.Occupied(p))
setup.m_stones[bd.GetColor(p)].Include(p);
}
return setup;
}
示例13: cuts
bool GoRegion::Safe2Cuts(const GoBoard& board) const
{
SG_ASSERT(m_blocks.IsLength(2));
const int size = board.Size();
GoBlock* block1 = m_blocks.Front();
GoBlock* block2 = m_blocks.Back();
SgPointSet cuts(Points());
cuts -= board.AllEmpty();
if (cuts.IsEmpty())
/* */ return true; /* */
cuts &= block1->Stones().Border(size);
cuts &= block2->Stones().Border(size);
return cuts.IsEmpty();
}
示例14: CanBecomeSinglePointEye
bool GoEyeUtil::CanBecomeSinglePointEye (const GoBoard& board, SgPoint p,
const SgPointSet& oppSafe)
{
SG_ASSERT(! oppSafe[p]);
for (SgNb4Iterator it(p); it; ++it)
{
if (oppSafe[*it])
return false;
}
int nu = 0;
for (SgNb4DiagIterator dit(p); dit; ++dit)
{
if (oppSafe[*dit])
{
if (board.Line(p) == 1)
return false;
++nu;
if (nu > 1)
return false;
}
}
return true;
}
示例15:
int GoEyeUtil::CountSinglePointEyes2(const GoBoard& board, SgPoint p)
{
if (! board.Occupied(p))
return 0;
SgBlackWhite color = board.GetColor(p);
int numeyes = 0;
for (GoBoard::LibertyIterator lib(board, p); lib; ++lib)
{
if (IsSinglePointEye2(board, *lib, color))
numeyes++;
}
return numeyes;
}