当前位置: 首页>>代码示例>>C++>>正文


C++ Stone::posY方法代码示例

本文整理汇总了C++中Stone::posY方法的典型用法代码示例。如果您正苦于以下问题:C++ Stone::posY方法的具体用法?C++ Stone::posY怎么用?C++ Stone::posY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stone的用法示例。


在下文中一共展示了Stone::posY方法的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;
}
开发者ID:alserkli,项目名称:q4Go,代码行数:32,代码来源:stonehandler.cpp

示例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;
}
开发者ID:alserkli,项目名称:q4Go,代码行数:27,代码来源:group.cpp

示例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");
	}	
}
开发者ID:alserkli,项目名称:q4Go,代码行数:12,代码来源:group.cpp

示例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);
//.........这里部分代码省略.........
开发者ID:alserkli,项目名称:q4Go,代码行数:101,代码来源:stonehandler.cpp


注:本文中的Stone::posY方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。