Esempio n. 1
0
void GArc::setFillColor(const std::string& color) {
    fillColor = color;
    if (fillColor == "") {
        if (isFilled()) {
            setFilled(false);
        }
    } else {
        fillColor = convertRGBToColor(convertColorToRGB(color));
        if (!isFilled()) {
            setFilled(true);
        }
    }
    stanfordcpplib::getPlatform()->gobject_setFillColor(this, fillColor);
}
Esempio n. 2
0
GRectangle GArc::getBounds() const {
    if (transformed) {
        return stanfordcpplib::getPlatform()->gobject_getBounds(this);
    }
    double rx = frameWidth / 2;
    double ry = frameHeight / 2;
    double cx = x + rx;
    double cy = y + ry;
    double startRadians = start * PI / 180;
    double sweepRadians = sweep * PI / 180;
    double p1x = cx + cos(startRadians) * rx;
    double p1y = cy - sin(startRadians) * ry;
    double p2x = cx + cos(startRadians + sweepRadians) * rx;
    double p2y = cy - sin(startRadians + sweepRadians) * ry;
    double xMin = std::min(p1x, p2x);
    double xMax = std::max(p1x, p2x);
    double yMin = std::min(p1y, p2y);
    double yMax = std::max(p1y, p2y);
    if (containsAngle(0)) xMax = cx + rx;
    if (containsAngle(90)) yMin = cy - ry;
    if (containsAngle(180)) xMin = cx - rx;
    if (containsAngle(270)) yMax = cy + ry;
    if (isFilled()) {
        xMin = std::min(xMin, cx);
        yMin = std::min(yMin, cy);
        xMax = std::max(xMax, cx);
        yMax = std::max(yMax, cy);
    }
    return GRectangle(xMin, yMin, xMax - xMin, yMax - yMin);
}
Esempio n. 3
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void OriginSymbol::customDraw(const Map::Canvas *, QPainter& painter) {
	QPen pen;
	pen.setColor(_color);
	pen.setWidth(SCScheme.colors.originSymbol.classic ? 4 : 2);
	pen.setJoinStyle(Qt::MiterJoin);
	painter.setPen(pen);

	if ( SCScheme.colors.originSymbol.classic ) {
		if ( isFilled() )
			painter.setBrush(_fillColor.isValid() ? _fillColor : _color);
	}
	else
		painter.setBrush(_fillColor.isValid() ? _fillColor : (isFilled() ? _color : QColor(_color.red(), _color.green(), _color.black(), 128)));

	int rx = size().width()/2;
	int ry = size().height()/2;
	painter.drawEllipse(QRect(x()-rx, y()-ry, size().width(), size().height()));
}
Esempio n. 4
0
int main() {
	char playAgain;

	do {
		nodes_expanded = 0;
		//initialize the board.
		char *board = newBoard();

		//get player and computer characters.
		char playerPiece = askUser("\nPlease choose your character (x or o): ", X, O);
		char computerPiece = getOpponentPiece(playerPiece);

		//check if player wants to play first.
		char ch = askUser("\nDo you want to play first ? (y or n): ", 'y', 'n');
		if(ch == 'y') {
			makePlayerMove(board, playerPiece);			
		}
		else if(ch == 'n') {
		}

		char winner;
		int turn = COMPUTER;

		//game loop.
		while(!isFilled(board) && (winner = whoWon(board)) == NONE) {

			if(turn == COMPUTER) {
				makeComputerMove(board, computerPiece);
				turn = PLAYER;
			}
			else {
				makePlayerMove(board, playerPiece);
				turn = COMPUTER;
			}
		}

		printBoard(board);

		//print results.
		if(winner == playerPiece) {
			printf("\n$ Congratulations! you have won. $\n");
		}
		else if(winner == NONE) {
			printf("\n* The game is a draw. *\n");
		}
		else {
			printf("\n@ You Lose!! @\n");
		}

		printf("\nNumber of nodes expanded: %d", nodes_expanded);

		//ask if user wants to play again.
		playAgain = askUser("\n Do you want to play again? (y or n): ", 'y', 'n');
	}while(playAgain == 'y');

	return 0;
}
Esempio n. 5
0
void MiscWidget::clear()
{
	if(!isFilled())	return;

	nameEdit->clear();
	pmpEdit->clear();
	pmpView->clear();
	pmpPaletteView->clear();
	pmdEdit->clear();
	pvpEdit->clear();
	pvpEdit2->clear();

	PageWidget::clear();
}
Esempio n. 6
0
// Draw function
void OcclusionCircle::drawFunc()
{
   BEGIN_DLIST
   GLUquadricObj* qobj = gluNewQuadric();
   if (isFilled()) {
      gluQuadricDrawStyle(qobj, GLU_FILL);
   }
   else {
      gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
   }
   gluDisk( qobj, getRadius(),  outerRadius, getSlices(), 1);
   gluDeleteQuadric(qobj);
   END_DLIST
}
Esempio n. 7
0
// Draw function
void OcclusionArc::drawFunc()
{
   BEGIN_DLIST
   GLUquadricObj* qobj = gluNewQuadric();
   if (isFilled()) {
      gluQuadricDrawStyle(qobj, GLU_FILL);
   }
   else {
      gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
   }

   gluPartialDisk(qobj, getRadius(), outerRadius, getSlices(), 2, getStartAngle(), getArcLength());

   gluDeleteQuadric(qobj);
   END_DLIST
}
Esempio n. 8
0
// Draw function
void Arc::drawFunc()
{
   BEGIN_DLIST
   GLUquadricObj* qobj = gluNewQuadric();
   if (isFilled()) {
      gluQuadricDrawStyle(qobj, GLU_FILL);
   }
   else {
      gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
   }
   if (connected) {
      gluPartialDisk(qobj, 0, getRadius(), getSlices(), 2, startAngle, arcLength);
   }
   else {
      gluPartialDisk(qobj, getRadius(), getRadius(), getSlices(), 2, startAngle, arcLength);
   }
   gluDeleteQuadric(qobj);
   END_DLIST
}
Esempio n. 9
0
	void applyInverse(const KpointRotation& Q) { // it is not assumed that the indices in Q are sorted
		vector<int> missing;
		for (int i = 0; i < Q.k; i++)
			if (!isFilled(Q.ix[i]))
				missing.push_back(Q.ix[i]);
		if (missing.size() == Q.k)
			return;
		for (int i = 0; i < missing.size(); i++)
			insert(missing[i], 0);
		for (int i = 0; i < Q.k; i++) {
			auto it = find(Q.ix[i]);
			Q.tempp[i] = &it->second;
			Q.temp[i] = it->second;
		}
		for (int i = 0; i < Q.k; i++) {
			double s = 0;
			for (int j = 0; j < Q.k; j++)
				s += Q.q[i * Q.k + j] * Q.temp[j];
			*Q.tempp[i] = s;
		}
	}
Esempio n. 10
0
		bool backtrack(int solve[MAX][MAX]){
			int row=0, col=0;		
			int r = getRow();
			int c = getCol();
			
			//keep going through board to begin with empty tile
			while(board[r][c]!= 0){
				r = getRow();
				c = getCol();
			}

			row = r;
			col = c;	
			//may need more temp
					
 
    // check if the board is filled then it is a win
    	//if(std::find(grid[0], grid[row-1]+col,0))
        if (!isFilled(solve, row, col))
       return true; 
                 
    // go through the numbers 1-9 that will insist on what can be inserted
    for (int num = 1; num <= 9; num++){
    // checks valid input, then puts in num
    if (canPlace(solve, row, col, num)){
    	   solve[row][col] = num;
                                                               
    //when true recurse 
    if (backtrack(solve))
    return true;
                                                                                               
    else //otherwise take away the value 
    solve[row][col] = 0;
    				}
    }
    return false; // this triggers backtracking

		}
Esempio n. 11
0
void MiscWidget::fill()
{
	if(!isBuilded())	build();
	if(isFilled())		clear();

	if(!hasData())	return;

    if(data()->hasInfFile()) {
        nameEdit->setText(data()->getInfFile()->getMapName());
		pvpEdit2->setValue(data()->getInfFile()->pvp());
    }
	nameEdit->setEnabled(data()->hasInfFile());
	pvpEdit2->setEnabled(data()->hasInfFile());

	if(data()->hasPmpFile()) {
		pmpEdit->setText(data()->getPmpFile()->getPmpData().toHex());
		QPixmap pal = QPixmap::fromImage(data()->getPmpFile()->palette());
		if(!pal.isNull()) {
			pal = pal.scaledToWidth(256);
		}
		pmpPaletteView->setPixmap(pal);
		updatePmpView();
    }
	pmpEdit->setEnabled(data()->hasPmpFile());

	if(data()->hasPmdFile()) {
		pmdEdit->setText(data()->getPmdFile()->getPmdData().toHex());
	}
	pmdEdit->setEnabled(data()->hasPmdFile());

	if(data()->hasPvpFile()) {
		pvpEdit->setValue(data()->getPvpFile()->value());
	}

	PageWidget::fill();
}
Esempio n. 12
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void OriginSymbol::drawOriginSymbol(const Map::Canvas*, QPainter& painter) {
	painter.save();

	QPen pen;
	pen.setColor(_color);
	pen.setWidth(4);
	pen.setJoinStyle(Qt::MiterJoin);
	painter.setPen(pen);

	QBrush brush;
	brush.setColor(_color);
	brush.setStyle(Qt::NoBrush);
	if ( isFilled() )
		brush.setStyle(Qt::SolidPattern);

	/*
	QBrush brush;
	brush.setStyle(Qt::SolidPattern);
	if ( isFilled() )
		brush.setColor(_color);
	else
		brush.setColor(QColor(_color.red(), _color.green(), _color.blue(), 64));
	*/

	painter.setBrush(brush);

	const QSize& size = Seiscomp::Gui::Map::Symbol::size();
	int height = size.height(),
	    width = size.width(),
	    r = int(width / 2);
	QRect rect(_mapPosition.x() - r, _mapPosition.y() - r, width, height);
	_poly = rect;
	painter.drawEllipse(rect);

	painter.restore();
}
Esempio n. 13
0
int minimax(char *board, char playerPiece, char computerPiece, int isMaximizer, int alpha, int beta) {

	nodes_expanded ++;

	char winner = whoWon(board);

	/* Handle leaf node cases */

	//if i won.
	if(winner == playerPiece) {
		return 1;
	}
	//if my opponent won.
	else if(winner == computerPiece) {
		return -1;
	}
	//if it is a draw.
	else if(isFilled(board)) {
		return 0;
	}

	/* Minmax backtracking */

	int i, move, max, min;

	max = -2;
	min = 2;
	move = -1;

	for(i = 0; i < 9; i ++) {	
		if(board[i] == NONE) {			/* for each empty cell */

			if(isMaximizer)
				board[i] = playerPiece;
			else
				board[i] = computerPiece;

			int val = minimax(board, playerPiece, computerPiece, 1 - isMaximizer, alpha, beta);

			board[i] = NONE;

			if(isMaximizer) {

				if(val > max) {
					max = val;
					beta = max;
				}

				// 1 is the maximum possible value so break the search.
				// or max maybe greater than alpha.
				if(val == 1 || max >= alpha) {
					break;
				}
			}
			else {
				if(val < min) {
					min = val;
					alpha = min;
				}

				// -1 is the manimum possible value so break the search.
				if(val == -1 || min <= beta) {
					break;
				}
			}
		}
	}	
	if(isMaximizer)
		return max;
	else
		return min;
}