Exemple #1
0
void GoBlock::ImportBlock(GoBlock* block)
{
  if(block == 0x0)
    return;
  int newLiberties = 0;
  int i = 0;
  while(block->stones[i] != -1)
    {
//      if(board->North(*it) != -1 && board->State.stones[board->North(*it)] == NONE && !board->IsLibertyOfBlock(board->North(*it),anchor))
//        ++newLiberties;
//      if(board->South(*it) != -1 && board->State.stones[board->South(*it)] == NONE && !board->IsLibertyOfBlock(board->South(*it),anchor))
//        ++newLiberties;
//      if(board->West(*it) != -1 && board->State.stones[board->East(*it)] == NONE && !board->IsLibertyOfBlock(board->East(*it),anchor))
//        ++newLiberties;
//      if(board->East(*it) != -1 && board->State.stones[board->West(*it)] == NONE && !board->IsLibertyOfBlock(board->West(*it),anchor))
//        ++newLiberties;
      newLiberties += board->FindUniqueLiberties(block->stones[i], board->State.blockPointers[anchor]);
      //Import all stones
      addStone(block->stones[i]);
      board->State.blockPointers[block->stones[i]] = this;
      ++i;
    }

  liberties += newLiberties;
  block->reset();
  ++i;
}
Exemple #2
0
	void Chunk::stepByStepCreation(){
		switch(stepCreation){
			case 1:
				addLava();
				break;
			case 2:
				addWater();
				break;
			case 3:
				addSand();
				break;
			case 4:
				addStone();
				break;
			case 5:
				addDirt();
				break;
			case 6:
				addTree();
				break;
			case 7:
				// to avoid errors
		  		checkSizeChunk();
				// checkVisibleBlocks();
				saveChunkInFile();
				break;
			default:
				// start
				if(!readChunkFromFile()){
					// fail to open file, it's time to generate a new one
					checkSizeChunk(); // fill Chunk with zero
				}else{
					stepCreation = 6; // almost end of the generation
				}				
				break;
		}
		stepCreation++;
	}
Exemple #3
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;
}
Exemple #4
0
/*
 * This handles the main envent with qGo : something has been clicked on the board
 */
void qGoBoard::slotBoardClicked(bool , int x, int y , Qt::MouseButton mouseState)
{
	bool blackToPlay = getBlackTurn();
	
	switch (boardwindow->getGamePhase())
	{
		case phaseInit:
			//should not happen
			return ;
		
		case phaseNavTo:
		{
			boardwindow->getBoardHandler()->findMoveByPos(x, y); 
			return;
		}

		case phaseEdit:
		{
			switch (boardwindow->getEditMark())
			{
				case markNone:
				{
					if(tree->getCurrent()->getMatrix()->getStoneAt(x,y) == stoneNone)
						addStone(mouseState == Qt::LeftButton ? stoneBlack : stoneWhite, x, y);
					else
						addStone(stoneErase, x, y);
					setModified(true);
					return;
				}
				default:
				{
					if (mouseState == Qt::LeftButton)
						addMark(x,y, boardwindow->getEditMark());
					else
						removeMark(x,y);
					setModified(true);
					return;
				}
					
			}
			return;
		}

		case phaseEnded:
			return;

		case phaseScore:
		{
			localMarkDeadRequest(x,y);
			return;
		}

		case phaseOngoing:
			if (blackToPlay && boardwindow->getMyColorIsBlack())
				localMoveRequest(stoneBlack,x,y);

			if (!blackToPlay && boardwindow->getMyColorIsWhite())
				localMoveRequest(stoneWhite,x,y);
			return;
	}
}