示例#1
0
文件: ttt.c 项目: johnjones4/DinoDOS
/*
 * Start the game play. This function is terminated when the board is filled, or
 * when a player has won.
 */
void play()
{
	//X goes first
	char turn = 'X';
	//current number of moves
	int moves = 0;
	
	//draw the board
	initializeGame();
	//go until we find a winner or the board is filled
	while(!winner() && moves < 9) {
		//the current user input
		char c;
		int row, col;
		//wait until we get a valid charter
		while(!validChar(c = getchar()));
		
		//map the character to a row and column
		if(c == 'q' || c == 'w' || c == 'e') {
			//first row
			row = 0;
		} else if(c == 'a' || c == 's' || c == 'd') {
			//second row
			row = 1;
		} else {
			//third row
			row = 2;
		}
		//column check
		if(c == 'q' || c == 'a' || c == 'z') {
			//first col
			col = 0;
		} else if(c == 'w' || c == 's' || c == 'x') {
			//second col
			col = 1;
		} else {
			//third col
			col = 2;
		}
		
		//check if that space is free, otherwise loop goes again
		if (grid[row][col] == '\0') {
			//mark that spot
			grid[row][col] = turn;
			//draw it an change turns
			if (turn == 'X') {
				drawX(row,col);
				turn = 'O';
			} else if (turn == 'O') {
				drawO(row,col);
				turn = 'X';
			}
			//add the the move count
			moves++;
		}
	}
	//after the game is over, wait for the user to press any key to end
	getchar();
}
示例#2
0
void drawGamePiece(Move mv,gamePiece playPiece)
{
	if (playPiece==OPEN)
		return;
	if (playPiece==X)
		drawX(getPointFromSlot(mv));
	else
		drawO(getPointFromSlot(mv));
}
示例#3
0
文件: Main.cpp 项目: Seyfel/SGI
void drawIX() {
	glPushMatrix();
	glTranslatef(-0.2, 0.0, 0.0);

	glPushMatrix();
	glTranslatef(0.35, 0, 0);
	drawX();
	glPopMatrix();

	drawI();

	glPopMatrix();
}
示例#4
0
void Render::drawPosition(DrawVariables* dw)
{
	if (m_engine == nullptr)
		return;
	int rows, cols;
	rows = m_engine->getBoard().getRows();
	cols = m_engine->getBoard().getCols();

	for (int i = 0; i < rows; ++i)
	{
		for (int j = 0; j < cols; ++j)
		{
			if (m_engine->getBoard().getSquareValue({ i, j }) == Player::X)
				drawX(dw, { i, j });
			else if (m_engine->getBoard().getSquareValue({ i, j }) == Player::O)
				drawO(dw, { i, j });
		}
	}
}
示例#5
0
文件: graph.c 项目: chain78/none
int main(void){
    PMInfoBlock *pm = NULL;
    installGDT(0xa000 >> 3,0xa0000,0xffff,0,0,1,0,1,2);
    installGDT(0xb000 >> 3,0xb0000,0xffff,0,0,1,0,1,2);
    memcpy(VGABASE,(void*)(0xc0000),VGALIMIT);
    pm = getPMInfo();
    pm->biosDataSel = 0x10;
    entry = pm->entryPoint;


    memcpy((void*)0x1000,(void*)_int10,0x100);
    selectMode(M640x480x8);
#if 0
    drawX(0,640,0,480,33);
    drawX(40,600,40,440,60);
    drawX(40,600,40,60,150);
    drawX(60,580,60,420,200);
#endif

    BMPRGB c = {0xff,0xff,0xff};
    for(int i = 1;i < 140;i++){
        drawCircle(320,240,i,0,i);
        setPalett(c,i);
    }
    for(int i = 1,ver = 1;;c.red += 131,c.green += 13,c.blue += 17){
        do{
            i += ver;
            for(int delay = 0xfff;delay--;);
            setPalett(c,i - ver);
        } while((i > 1)&& (i < 140));
        ver = -ver;
    }
#if 0
    drawX(0,640,460,480,43);
    drawCircle(20,470,10,1,40);
    drawX(600,640,460,480,60);
#endif
#ifdef  PRINT_TEXT
    for(int i = 'A';i < 127;i++) gputc(i);
#endif
    //while(1);
    return 0;
}
示例#6
0
void Graph::
paintEvent(QPaintEvent */*event*/)
{
    QPainter painter(this);

    QBrush brush;brush.setColor(QColor(250,50,50));
    painter.fillRect(0,0,width(),height(),brush);
    
    QPen pen;
    pen.setWidth(1);
    pen.setColor(QColor(210,210,255));
    painter.setPen(pen);

    float powerx=(int)floor(log(xmax-xmin)/log(logBase));
    float powery=(int)floor(log(ymax-ymin)/log(logBase));

    int powerOffsetSmall=5;
    int powerOffsetBig=1;
    drawX(painter,powerx-powerOffsetSmall);
    drawY(painter,powery-powerOffsetSmall);
    
    pen.setWidth(2);
    pen.setColor(QColor(200,200,255));
    painter.setPen(pen);

    drawX(painter,powerx-powerOffsetBig,false);
    drawY(painter,powery-powerOffsetBig,false);

    pen.setColor(Qt::black);
    painter.setPen(pen);
    drawX(painter,powerx-powerOffsetBig,true);
    drawY(painter,powery-powerOffsetBig,true);


    pen.setWidth(2);
    pen.setColor(QColor(50,100,200));
    painter.setPen(pen);
    float x1,y1,x2,y2;
    xform(0,ymin,x1,y1);
    xform(0,ymax,x2,y2);
    painter.drawLine(x1,y1,x2,y2);
    xform(xmin,0,x1,y1);
    xform(xmax,0,x2,y2);
    painter.drawLine(x1,y1,x2,y2);

   



    painter.setRenderHints(QPainter::Antialiasing);
    for(int i=0;i<funcs.rowCount(QModelIndex());i++){
        plot(painter,i);
    }

    if(rootShow || minShow){
        pen.setColor(Qt::black);
        painter.setPen(pen);
        //std::cerr<<"drawing"<<std::endl;
        float dx,dy;
        xform(rootX,rootY,dx,dy);
        painter.drawEllipse(QPoint(dx,dy),3,3);
        QString text=QString("(%1,%2)").arg(rootX).arg(rootY);
        painter.drawText(QPoint(dx,dy),text);
    }


    if(minShow || operationCode==FIND_MIN || operationCode==FIND_MAX){
        QBrush brush(Qt::yellow);
        painter.setBrush(brush);
        //std::cerr<<"draw boundstart "<<boundStart<<" "<<boundEnd<<std::endl;
        xform(boundStart,ymin,x1,y1);
        xform(boundStart,ymax,x1,y2);
        xform(boundEnd,ymin,x2,y1);
        xform(boundEnd,ymax,x2,y2);
        //painter.drawLine(x1,y1,x1,y2);
        //painter.drawLine(x2,y1,x2,y2);
        painter.setOpacity(.2);
        painter.drawRect(x1,y1,x2-x1,y2-y1);
        painter.setOpacity(1);
    }

}
示例#7
0
void
BoundingBox::draw()
{
  if (m_emitUpdate)
    {
      bool ok = true;
      for (int i=0; i<6; i++)
	{      
	  if (m_bounds[i].grabsMouse())
	    {
	      ok = false;
	      break;
	    }
	}
      if (ok)
	{
	  emit updated();
	  m_emitUpdate = false;
	}
    }

  Vec bmin, bmax;  

  bounds(bmin, bmax);

  Vec lineColor = defaultColor;
  lineColor = Vec(0.8f, 0.8f, 0.6f);

  glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  glColor4f(boxColor.x, boxColor.y, boxColor.z, 0.9f);
  StaticFunctions::drawEnclosingCube(bmin,
				     bmax);
  glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

  for (int i=0; i<6; i++)
    {      
      if (m_bounds[i].grabsMouse())
	{
	  glLineWidth(2);
	  switch(i)
	    {
	    case 0 :
	      drawX(bmin.x, bmin, bmax, selectColor);
	      break;
	    case 1 :
	      drawX(bmax.x, bmin, bmax, selectColor);
	      break;	     
	    case 2 :
	      drawY(bmin.y, bmin, bmax, selectColor);
	      break;	      
	    case 3 :
	      drawY(bmax.y, bmin, bmax, selectColor);
	      break;	      
	    case 4 :
	      drawZ(bmin.z, bmin, bmax, selectColor);
	      break;	      
	    case 5 :
	      drawZ(bmax.z, bmin, bmax, selectColor);
	      break;
	    }
	}
      else
	{
	  glLineWidth(1);
	  switch(i)
	    {
	    case 0 :
	      drawX(bmin.x, bmin, bmax, lineColor);
	      break;
	    case 1 :
	      drawX(bmax.x, bmin, bmax, lineColor);
	      break;	     
	    case 2 :
	      drawY(bmin.y, bmin, bmax, lineColor);
	      break;	      
	    case 3 :
	      drawY(bmax.y, bmin, bmax, lineColor);
	      break;	      
	    case 4 :
	      drawZ(bmin.z, bmin, bmax, lineColor);
	      break;	      
	    case 5 :
	      drawZ(bmax.z, bmin, bmax, lineColor);
	      break;
	    }
	}
    }

  glLineWidth(1);
}
/************************************************************************************
绘制函数
该函数主要完成对绘制更新操作,主要过程如下:
1. 绘制相应的X轴信息
2. 绘制相应的Y轴信息
3. 绘制常规检索下的RP曲线
4. 绘制蜂群检索下的RP曲线
5. 绘制其它一些辅助信息(如检索用时等)
************************************************************************************/
void CRPResultDlg::OnPaint()
{
	CPaintDC dc(this);

	CFont font;
	font.CreatePointFont(100, "微软雅黑");
	CFont *pOldFont = (CFont *)dc.SelectObject(&font);

	//设置背景为透明
	dc.SetBkMode(0);

	RECT clientRect;
	GetClientRect(&clientRect);

	POINT originPos;
	originPos.x = clientRect.left + 30;
	originPos.y = clientRect.bottom - 70;

	POINT size;
	size.x = (clientRect.right - clientRect.left) - 50;
	size.y = (clientRect.bottom - clientRect.top) - 80;

	dc.MoveTo(originPos.x , originPos.y);
	dc.LineTo(originPos.x + size.x , originPos.y);

	dc.MoveTo(originPos.x , originPos.y);
	dc.LineTo(originPos.x , originPos.y - size.y);

	drawX(originPos.x , originPos.y , &dc , 0.0f);
	drawX(originPos.x + size.x * 0.5 , originPos.y , &dc , 0.5f);
	drawX(originPos.x + size.x , originPos.y , &dc , 1.0f);
	drawY(originPos.x , originPos.y - size.y * 0.5f , &dc , 0.5f);
	drawY(originPos.x , originPos.y - size.y , &dc , 1.0f);

	dc.TextOut(clientRect.right - 100 , clientRect.bottom - 45 , "横向-Recall");
	dc.TextOut(clientRect.right - 100 , clientRect.bottom - 25 , "纵向-Precision");

	// 绘制常规搜索下的结果
	{
		CPen pen(PS_SOLID , 1 , RGB(255, 0, 0));
		CPen *pOldPen = dc.SelectObject(&pen);

		POINT curPos;
		float lastX , lastY;

		int valueX , valueY;
		// 绘制在X轴上 50维度的曲线
		if(mRPResult.mRPDataList.GetListSize() > 0)
		{
			RPData* pRTData = mRPResult.mRPDataList.GetItemPtr(0);
			curPos.x = (LONG)(pRTData->recall * size.x + originPos.x);
			curPos.y = (LONG)(-pRTData->precision * size.y + originPos.y);
			dc.MoveTo(curPos.x , curPos.y);
			lastX = pRTData->recall;
			lastY = pRTData->precision;

			for(int i = 1 ; i < mRPResult.mRPDataList.GetListSize() ; i++)
			{
				if ((i % 20 == 0))
				{
					pRTData = mRPResult.mRPDataList.GetItemPtr(i);
					curPos.x = (int)(pRTData->recall * (float)size.x) + originPos.x;
					curPos.y = -(int)(pRTData->precision * (float)size.y) + originPos.y;
					dc.LineTo(curPos.x , curPos.y);

					valueX = (int)(pRTData->recall * 100.0f);
					valueY = (int)(pRTData->precision * 100.0f);

					dc.MoveTo(curPos.x , curPos.y);

					lastX = pRTData->recall;
					lastY = pRTData->precision;
				}
			}
		}

		dc.MoveTo(75 , clientRect.bottom - 15);
		dc.LineTo(120 , clientRect.bottom - 15);
		
		CString timeText;
		timeText.Format("时间:%3.6f 秒" , mRPResult.mUsedTime);
		dc.TextOut(160 , clientRect.bottom - 25 , timeText);
		dc.TextOut(15 , clientRect.bottom - 25 , "常规搜索");

		dc.SelectObject(pOldPen);
	}

	// 绘制蜂群搜索下的结果
	{
		CPen pen(PS_SOLID , 1 , RGB(0, 0, 255));
		CPen *pOldPen = dc.SelectObject(&pen);

		POINT curPos;
		float lastX , lastY;

		int valueX , valueY;

		int xStep = mRPResultBee.mRPDataList.GetListSize() / 50;
		if(mRPResultBee.mRPDataList.GetListSize() > 0)
		{
			RPData* pRTData = mRPResultBee.mRPDataList.GetItemPtr(0);
			curPos.x = (LONG)(pRTData->recall * size.x + originPos.x);
			curPos.y = (LONG)(-pRTData->precision * size.y + originPos.y);
			dc.MoveTo(curPos.x , curPos.y);
			lastX = pRTData->recall;
			lastY = pRTData->precision;

			for(int i = 1 ; i < mRPResultBee.mRPDataList.GetListSize() ; i++)
			{
				if ((i % xStep == 0))
				{
					pRTData = mRPResultBee.mRPDataList.GetItemPtr(i);
					curPos.x = (int)(pRTData->recall * (float)size.x) + originPos.x;
					curPos.y = -(int)(pRTData->precision * (float)size.y) + originPos.y;
					dc.LineTo(curPos.x , curPos.y);

					valueX = (int)(pRTData->recall * 100.0f);
					valueY = (int)(pRTData->precision * 100.0f);

					dc.MoveTo(curPos.x , curPos.y);

					lastX = pRTData->recall;
					lastY = pRTData->precision;
				}
			}
		}

		dc.MoveTo(75 , clientRect.bottom - 35);
		dc.LineTo(120 , clientRect.bottom - 35);

		CString timeText;
		timeText.Format("时间:%3.6f 秒" , mRPResultBee.mUsedTime);
		dc.TextOut(160 , clientRect.bottom - 45 , timeText);
		dc.TextOut(15 , clientRect.bottom - 45 , "蜂群搜索");

		dc.SelectObject(pOldPen);
	}
	dc.SelectObject(pOldFont);
}
示例#9
0
vector<Rect> CharacterSegmenter::filterMostlyEmptyBoxes(vector<Mat> thresholds, const vector<Rect> charRegions)
{
  // Of the n thresholded images, if box 3 (for example) is empty in half (for example) of the thresholded images, 
  // clear all data for every box #3.
  
  //const float MIN_AREA_PERCENT = 0.1;
  const float MIN_CONTOUR_HEIGHT_PERCENT = 0.65;
  
  Mat mask = getCharBoxMask(thresholds[0], charRegions);
  
  vector<int> boxScores(charRegions.size());
  
  for (int i = 0; i < charRegions.size(); i++)
    boxScores[i] = 0;
  
  for (int i = 0; i < thresholds.size(); i++)
  {
      
    for (int j = 0; j < charRegions.size(); j++)
    {
      //float minArea = charRegions[j].area() * MIN_AREA_PERCENT;
      
      Mat tempImg = Mat::zeros(thresholds[i].size(), thresholds[i].type());
      rectangle(tempImg, charRegions[j], Scalar(255,255,255), CV_FILLED);
      bitwise_and(thresholds[i], tempImg, tempImg);

      vector<vector<Point> > contours;
      findContours(tempImg, contours, RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
    
      float biggestContourHeight = 0;
      
      vector<Point> allPointsInBox;
      for (int c = 0; c < contours.size(); c++)
      {
	if (contours[c].size() == 0)
	  continue;

	for (int z = 0; z < contours[c].size(); z++)
	  allPointsInBox.push_back(contours[c][z]);
	
      }

      float height = 0;
      if (allPointsInBox.size() > 0)
      {
	height = boundingRect(allPointsInBox).height;
      }
	
	
      if (height >= ((float) charRegions[j].height * MIN_CONTOUR_HEIGHT_PERCENT))
      {
	boxScores[j] = boxScores[j] + 1;
      }
      else if (this->config->debugCharSegmenter)
      {
	drawX(imgDbgCleanStages[i], charRegions[j], COLOR_DEBUG_EMPTYFILTER, 3);
      }

      
    }
    
  }
  
  vector<Rect> newCharRegions;
  
  int maxBoxScore = 0;
  for (int i = 0; i < charRegions.size(); i++)
  {
    if (boxScores[i] > maxBoxScore)
      maxBoxScore = boxScores[i];
  }
  
  // Need a good char sample in at least 50% of the boxes for it to be valid.
  int MIN_FULL_BOXES = maxBoxScore * 0.49;
  
  // Now check each score.  If it's below the minimum, remove the charRegion
  for (int i = 0; i < charRegions.size(); i++)
  {
    if (boxScores[i] > MIN_FULL_BOXES)
      newCharRegions.push_back(charRegions[i]);
    else
    {
      // Erase the box from the Mat... mainly for debug purposes
      if (this->config->debugCharSegmenter)
      {
	cout << "Mostly Empty Filter: box index: " << i;
	cout << " this box had a score of : " << boxScores[i];;
	cout << " MIN_FULL_BOXES: " << MIN_FULL_BOXES << endl;;
      
	for (int z = 0; z < thresholds.size(); z++)
	{
	  rectangle(thresholds[z], charRegions[i], Scalar(0,0,0), -1);
	  
	  drawX(imgDbgCleanStages[z], charRegions[i], COLOR_DEBUG_EMPTYFILTER, 1);
	}
	
      }
    }
    
    if (this->config->debugCharSegmenter)
      cout << " Box Score: " << boxScores[i] << endl;
  }
  
  return newCharRegions;
}
int main()
{

	int drive, mode, width, height;
	int x[ 21 ], xx[ 21 ], y[ 21 ];
	int fixx,fixy;
	float b[21], xz[ 21 ];

	int i, j, num_eq, num_var, pointNUM;
	float coeff[ 20 ][ 20 ], inv_coeff[ 20 ][ 20 ], known[ 20 ];
	float var[ 20 ];
	float drawpoints[ 50 ];
	float  scope, interval;

	drive = DETECT;
	printf( "Enter the Number of Equations. : " );
	scanf( "%d", &num_eq );
	num_var = num_eq;
	for( i = 0; i < num_eq; i++ ){
		printf( "*********************************************\n" );
		printf( "Enter the Coefficients of eq. %d. \n", i + 1 );
		for( j = 0; j < num_var; j++ ){
			printf( "coefficient of variable %d. : ", j + 1 );
			scanf( "%f", &coeff[ i ][ j ] );
		}
		printf( "Enter the Known Value of eq. %d. : ", i + 1 );
		scanf( "%f", &known[ i ] );
	}
	
	printf( "*********************************************\n" );




	printf( "\n\n Entered Equations :\n" );
	for( i = 0; i < num_var; i++ ){
		for( j = 0; j < num_var; j++ ){
			printf( "%10.3f * X%d", coeff[ i ][ j ], j + 1);
			if( j != num_var - 1)
				printf( "+" );
			else
				printf( "=" );
		}
		printf("%10.3f\n", known[i] );
	}

matrix_inversion_using_element_operation( coeff, inv_coeff, num_eq );

	for( i = 0; i < num_var; i++ ){
		var[ i ] = 0.0;
		for( j = 0; j < num_eq; j++ )
			var[ i ] += inv_coeff[ i ][ j ] * known[ j ];
	}
	
	printf( "*********************************************\n" );
	printf( "Results : \n" );
	
	for( i = 0; i < num_var; i++ )
		printf( "X%d = %10.3f\n", i + 1, var[ i ] );

	for( i = num_eq; i >= 1; i-- ){
		printf( "%0.3fX^%d", var[ num_eq - i ], i - 1 );
		if( i > 1 )
			printf( " + " );

		xz[ num_eq - i ] = var[ num_eq - i];
	}
	
	

	printf( "\n\n" );
	printf( "Enter the scope of X: " );
	scanf( "%f", &scope );
	printf( "\n" );
	printf( "Enter the interval of test: " );
	scanf( "%f", &interval );
	printf( "\n\n" );


	pointNUM =( int )( scope / interval );

	for( i = 0; i <= pointNUM; i++ ){
		b[ i ] = ( xz[ num_eq - num_eq ] * i * i ) + ( xz[ num_eq - num_eq + 1 ] * i ) + ( xz[ num_eq - num_eq + 2 ] * ( num_eq - num_eq ) );
		printf( "%d B is :%10.3f\n", i, b[ i ] );
	}

	for( i = 0; i <= pointNUM; i++ ){
		printf( "Enter the %d number of X: ", i + 1);
		x[ i ] = i;
		xx[ i ] = x[ i ] * 46;
		printf( "%d\n", xx[ i ] );
	}

	for( i = 0; i <= pointNUM; i++ ){
		printf( "Enter the %d number of Y: ", i + 1);
		y[ i ] =(int)( 460 - b[ i ] * 46 );
		printf( "%d\n", y[ i ] );
	}
	printf( "\n\n\npass any key to draw the function line..." );
	getch();

	initgraph( &drive, &mode, "" );
	setbkcolor( BLUE );
	cleardevice();
	drawX();
	drawY();

	for( i = 0; i < pointNUM; i++ ){
		cleardevice();
		drawX();
		drawY();
		moveto( xx[ i + 1 ], y[ i + 1 ] );
		outtext( "*" );
		msDelay( 1000000 );
	}

	for( i = 0; i < pointNUM; i++ ){
		moveto( xx[ i + 1 ], y[ i + 1 ] );
		outtext( "*" );
		line( xx[ i ], y[ i ], xx[ i + 1], y[ i + 1 ] );
	}

	getch();
	closegraph();

}