예제 #1
0
Group* StoneHandler::checkNeighbour(int x, int y, StoneColor color, Group *group, Matrix *m) //SL added eb 8
{
//	CHECK_PTR(group);
//	CHECK_PTR(m); //added eb 8
  bool visible = false ;
  int size = boardHandler->board->getBoardSize();     //end add eb 8

  Stone *tmp = stones->find(Matrix::coordsToKey(x, y));
  
  // Okay, this is dirty and synthetic :
  // Because we use this function where the matrix can be NULL, we need to check this
  // Furthermore, since this has been added after the first code, we keep the 'stone->visible' test where one should only use the 'matrix' code
  if (m != NULL && x-1 >= 0 && x-1 < size && y-1 >= 0 && y-1 < size) //SL added eb 8
   visible = (m->at(x - 1, y - 1) != stoneNone); //SL added eb 9 We do this in order not to pass a null matrix to the matrix->at function (seen in handicap games)

  // again we priviledge matrix over stone visibility (we might be browsing a game)
	if (tmp != NULL && tmp->getColor() == color && (tmp->isVisible()|| visible)) //SL added eb 8
	{
		if (!group->contains(tmp))
		{
			group->append(tmp);
			tmp->checked = true;
		}
	}
	return group;
}
예제 #2
0
파일: group.cpp 프로젝트: alserkli/q4Go
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
0
파일: group.cpp 프로젝트: alserkli/q4Go
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
0
void StoneHandler::updateDeadMarks(int &black, int &white)
{
	Q3IntDictIterator<Stone> it(*stones);
	Stone *s;
	
	while (it.current())
	{
		s = it.current();
		CHECK_PTR(s);
		if (s->isDead())
		{
			if (s->getColor() == stoneBlack)
				white ++;
			else
				black ++;
		}
		++it;
	}    
}
예제 #5
0
bool StoneHandler::markSekiGroup(int x, int y, int &caps, StoneColor &col, bool &seki)
{
	if (hasStone(x, y) != 1)
		return false;
	
	Stone *s = getStoneAt(x, y);
	CHECK_PTR(s);
	col = s->getColor();
	
	if (!s->isSeki())
		seki = true;
	
	Group *g = assembleGroup(s, NULL);        //SL added eb 8
	CHECK_PTR(g);
	
	// Mark stones of this group as seki
	QListIterator<Stone *> it(*g);
	while (it.hasNext())
	{
		Stone *s = it.next();
		CHECK_PTR(s);
		if (seki && s->isDead())
			caps ++;
		s->setSeki(seki);
		if (seki)
		{
			s->togglePixmap(boardHandler->board->getImageHandler()->getGhostPixmaps(),
					false);
		}	
		else
		{
			s->togglePixmap(boardHandler->board->getImageHandler()->getStonePixmaps(),
					true);
		}
	}
	
	delete g;
	return true;
}
예제 #6
0
bool StoneHandler::removeDeadGroup(int x, int y, int &caps, StoneColor &col, bool &dead)
{
	if (hasStone(x, y) != 1)
		return false;
	
	Stone *s = getStoneAt(x, y);
	CHECK_PTR(s);
	col = s->getColor();
	
	if (!s->isDead())
		dead = true;
	
	Group *g = assembleGroup(s, NULL);        //SL added eb 8
	CHECK_PTR(g);
	
	caps = g->count();
	
	// Mark stones of this group as dead or alive again
	QListIterator<Stone *> it(*g);
	while (it.hasNext())
	{
		Stone *s = it.next();
		CHECK_PTR(s);
		s->setDead(dead);
		if (dead)
		{
			s->togglePixmap(boardHandler->board->getImageHandler()->getGhostPixmaps(),
					false);
		}
		else
		{
			s->togglePixmap(boardHandler->board->getImageHandler()->getStonePixmaps(),
					true);
		}
	}
	
	delete g;
	return true;
}
예제 #7
0
파일: stonehandler.cpp 프로젝트: rd8/qGo
bool StoneHandler::markSekiGroup(int x, int y, int &caps, StoneColor &col, bool &seki)
{
	if (hasStone(x, y) != 1)
		return false;
	
	Stone *s = getStoneAt(x, y);
	CHECK_PTR(s);
	col = s->getColor();
	
	if (!s->isSeki())
		seki = true;
	
	Group *g = assembleGroup(s, NULL);        //SL added eb 8
	CHECK_PTR(g);
	
	// Mark stones of this group as seki
	QListIterator<Stone> it(*g);
	for (; it.current(); ++it)
	{
		s = it.current();
		CHECK_PTR(s);
		if (seki && s->isDead())
			caps ++;
		s->setSeki(seki);
		if (seki)
		{
			s->setSequence(boardHandler->board->getImageHandler()->getGhostPixmaps());
			s->shadow->hide();
		}	
		else
		{
			s->setSequence(boardHandler->board->getImageHandler()->getStonePixmaps());
			s->shadow->show();
		}
	}
	
	delete g;
	return true;
}
예제 #8
0
파일: stonehandler.cpp 프로젝트: rd8/qGo
bool StoneHandler::removeDeadGroup(int x, int y, int &caps, StoneColor &col, bool &dead)
{
	if (hasStone(x, y) != 1)
		return false;
	
	Stone *s = getStoneAt(x, y);
	CHECK_PTR(s);
	col = s->getColor();
	
	if (!s->isDead())
		dead = true;
	
	Group *g = assembleGroup(s, NULL);        //SL added eb 8
	CHECK_PTR(g);
	
	caps = g->count();
	
	// Mark stones of this group as dead or alive again
	QListIterator<Stone> it(*g);
	for (; it.current(); ++it)
	{
		s = it.current();
		CHECK_PTR(s);
		s->setDead(dead);
		if (dead)
		{
			s->setSequence(boardHandler->board->getImageHandler()->getGhostPixmaps());
			s->shadow->hide();
		}
		else
		{
			s->setSequence(boardHandler->board->getImageHandler()->getStonePixmaps());
			s->shadow->show();
		}
	}
	
	delete g;
	return true;
}
예제 #9
0
void StoneHandler::debug()
{
	qDebug("StoneHandler::debug()");
	
#if 0
	Q3IntDictIterator<Stone> its(*stones);
	Stone *s;
	
	while (its.current())
	{
		s = its.current();
		qDebug("%d -> %s", its.currentKey(), s->getColor() == stoneBlack ? "Black" : "White");
		++its;
	}
#endif
	
	Q3PtrListIterator<Group> it(*groups);
	for (; it.current(); ++it)
	{
		Group *g = it.current();
		g->debug();
	}
}
예제 #10
0
bool StoneHandler::updateAll(Matrix *m, bool toDraw)
{
	// qDebug("StoneHandler::updateAll(Matrix *m) - toDraw = %d", toDraw);
	
	CHECK_PTR(m);
	
	// m->debug();
	
	Stone *stone;
	bool modified = false, fake = false;
	short data;
	
	/*
	* Synchronize the matrix with the stonehandler data and
	* update the canvas.
	* This is usually called when navigating through the tree.
	*/
	
	for (int y=1; y<=boardHandler->board->getBoardSize(); y++)
	{
		for (int x=1; x<=boardHandler->board->getBoardSize(); x++)
		{
			// Extract the data for the stone from the matrix
			data = abs(m->at(x-1, y-1) % 10);
			switch (data)
			{
			case stoneBlack:
				if ((stone = stones->find(Matrix::coordsToKey(x, y))) == NULL)
				{
					addStone(boardHandler->board->addStoneSprite(stoneBlack, x, y, fake), true, false);
					modified = true;
					break;
				}
				else if (!stone->isVisible())
				{
					stone->show();
					modified = true;
				}
				
				if (stone->getColor() == stoneWhite)
				{
					stone->setColor(stoneBlack);
					modified = true;
				}
				
				break;
				
			case stoneWhite:
				if ((stone = stones->find(Matrix::coordsToKey(x, y))) == NULL)
				{
					addStone(boardHandler->board->addStoneSprite(stoneWhite, x, y, fake), true, false);
					modified = true;
					break;
				}
				else if (!stone->isVisible())
				{
					stone->show();
					modified = true;
				}
				
				if (stone->getColor() == stoneBlack)
				{
					stone->setColor(stoneWhite);
					modified = true;
				}
				
				break;
				
			case stoneNone:
			case stoneErase:
				if ((stone = stones->find(Matrix::coordsToKey(x, y))) != NULL &&
					stone->isVisible())
				{
					stone->hide();
					modified = true;
				}
				break;
				
			default:
				qWarning("Bad matrix data <%d> at %d/%d in StoneHandler::updateAll(Matrix *m) !",
					data, x, y);
			}
			
			// Skip mark drawing when reading sgf
			if (!toDraw)
				continue;
			
			// Extract the mark data from the matrix
			data = abs(m->at(x-1, y-1) / 10);
			switch (data)
			{
			case markSquare:
				modified = true;
				boardHandler->board->setMark(x, y, markSquare, false);
				break;
				
			case markCircle:
				modified = true;
				boardHandler->board->setMark(x, y, markCircle, false);
				break;
				
			case markTriangle:
				modified = true;
				boardHandler->board->setMark(x, y, markTriangle, false);
				break;
				
			case markCross:
				modified = true;
				boardHandler->board->setMark(x, y, markCross, false);
				break;
				
			case markText:
				modified = true;
				boardHandler->board->setMark(x, y, markText, false, m->getMarkText(x, y));
				break;
				
			case markNumber:
				modified = true;
				boardHandler->board->setMark(x, y, markNumber, false, m->getMarkText(x, y));
				break;
				
			case markTerrBlack:
				modified = true;
				boardHandler->board->setMark(x, y, markTerrBlack, false);
				break;
				
			case markTerrWhite:
				modified = true;
				boardHandler->board->setMark(x, y, markTerrWhite, false);
				break;
				
			case markNone:
				if (boardHandler->board->hasMark(x, y))
				{
					modified = true;
					boardHandler->board->removeMark(x, y, false);
				}
			}
	}
    }
    
    return modified;
}