本文整理汇总了C++中Stone::posX方法的典型用法代码示例。如果您正苦于以下问题:C++ Stone::posX方法的具体用法?C++ Stone::posX怎么用?C++ Stone::posX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stone
的用法示例。
在下文中一共展示了Stone::posX方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: countLibertiesOnMatrix
int StoneHandler::countLibertiesOnMatrix(Group *group, Matrix *m)
{
CHECK_PTR(group);
CHECK_PTR(m);
int liberties = 0;
Q3ValueList<int> libCounted;
// Walk through the horizontal and vertial directions, counting the
// liberties of this group.
for (unsigned int i=0; i<group->count(); i++)
{
Stone *tmp = group->at(i);
CHECK_PTR(tmp);
int x = tmp->posX(),
y = tmp->posY();
// North
checkNeighbourLibertyOnMatrix(x, y-1, libCounted, liberties, m);
// West
checkNeighbourLibertyOnMatrix(x-1, y, libCounted, liberties, m);
// South
checkNeighbourLibertyOnMatrix(x, y+1, libCounted, liberties, m);
// East
checkNeighbourLibertyOnMatrix(x+1, y, libCounted, liberties, m);
}
return liberties;
}
示例2: isAttachedTo
bool Group::isAttachedTo(Stone *s)
{
CHECK_PTR(s);
int stoneX = s->posX();
int stoneY = s->posY();
int x, y;
StoneColor col = s->getColor(), c;
Stone *tmp;
if (isEmpty())
return false;
for (unsigned int i=0; i<size(); i++)
{
tmp = at(i);
x = tmp->posX();
y = tmp->posY();
c = tmp->getColor();
if (((stoneX == x && (stoneY == y-1 || stoneY == y+1)) ||
(stoneY == y && (stoneX == x-1 || stoneX == x+1))) &&
c == col)
return true;
}
return false;
}
示例3: debug
void Group::debug()
{
qDebug(QString("Count: %1 - Liberties: %2").arg(count()).arg(liberties));
const_iterator i;
for (i = constBegin(); i != constEnd(); i++)
{
Stone *s = *i;
qDebug(" (%d, %d) %s", s->posX(), s->posY(),
s->getColor() == stoneBlack ? "B" : "W");
}
}
示例4: checkPosition
//bool StoneHandler::checkPosition(Stone *stone)
bool StoneHandler::checkPosition(Stone *stone, Matrix *m, bool koStone)
{
//CHECK_PTR(stone);
// CHECK_PTR(m); // SL added eb 8
if (!stone->isVisible())
return true;
Group *active = NULL;
// No groups existing? Create one.
if (groups->isEmpty())
{
Group *g = assembleGroup(stone,m);
CHECK_PTR(g);
groups->append(g);
active = g;
}
// We already have one or more groups.
else
{
bool flag = false;
Group *tmp;
for (unsigned int i=0; i<groups->count(); i++)
{
tmp = groups->at(i);
//CHECK_PTR(tmp);
// Check if the added stone is attached to an existing group.
// If yes, update this group and replace the old one.
// If the stone is attached to two groups, remove the second group.
// This happens if the added stone connects two groups.
if (tmp->isAttachedTo(stone))
{
// Group attached to stone
if (!flag)
{
if (!groups->remove(i))
qFatal("StoneHandler::checkPosition(Stone *stone):"
"Oops, removing an attached group failed.");
active = assembleGroup(stone,m);
groups->insert(i, active);
flag = true;
}
// Groups connected, remove one
else
{
if (active != NULL && active == groups->at(i))
active = tmp;
if (!groups->remove(i))
qFatal("StoneHandler::checkPosition(Stone *stone): "
"Oops, removing a connected group failed.");
i--;
}
}
}
// The added stone isnt attached to an existing group. Create a new group.
if (!flag)
{
Group *g = assembleGroup(stone,m);
CHECK_PTR(g);
groups->append(g);
active = g;
}
}
// active->debug();
// Now we have to sort the active group as last in the groups QPtrList,
// so if this one is out of liberties, we beep and abort the operation.
// This prevents suicide moves.
groups->append(groups->take(groups->findRef(active)));
// Check the liberties of every group. If a group has zero liberties, remove it.
for (unsigned int i=0; i<groups->count(); i++)
{
Group *tmp = groups->at(i);
//CHECK_PTR(tmp);
tmp->setLiberties(countLiberties(tmp, m)); //SL added eb 8
// qDebug("Group #%d with %d liberties:", i, tmp->getLiberties());
// tmp->debug();
// Oops, zero liberties.
if (tmp->getLiberties() == 0)
{
// Suicide move?
if (tmp == active)
{
if (active->count() == 1)
{
groups->remove(i);
removeStone(stone->posX(), stone->posY(), false);
//.........这里部分代码省略.........