Example #1
0
void play(char *position)
{
    pieces = initPieces(position);
    char player = 'w';
    int from, to;
    int legal;
    while(1)
    {
        if(isMate(pieces, player))
            return;
        char *posString = createPosString(pieces);
        printBoard(posString);
        free(posString);
        from = -1;
        to = -1;
        legal = 0;
        printMoves(pieces, player);
        while(!legal)
        {
            readMove(&from, &to);
            legal = legalMove(pieces, from, to, player);
            char *fromSt, *toSt;
            if(!legal)
            {
                printf("%s %s is illegal\n", fromSt = stringPosToSquare(from), toSt = stringPosToSquare(to));
                free(fromSt); free(toSt);
            }

        }
        movePiece(pieces, from, to);
        player = player == 'w' ? 'b' : 'w';
    }
}
void CWall3D::fracturePiecesInYRange( float t, float y1, float y2, TIntVector& pcs )
{
	if( !mPiecesInited )
		initPieces();

	// fetch the pieces
	pcs.resize( 0 );

	// TODO: optimize, right now linear search!
	float pieceRestoreTime = t + 1.0e6f;

	int n = mWall2D.getPieceCount();
	for( int i = 0; i < n; ++i ) {
		const CWallPiece2D& p = mWall2D.getPiece( i );
		SVector2 c = p.getAABB().getCenter();
		float y = c.y;
		if( mMatrix.getAxisY().y < 0.5f ) {
			SVector3 wc;
			D3DXVec3TransformCoord( &wc, &SVector3(c.x,c.y,0), &mMatrix );
			y = wc.y;
		}
		if( y >= y1 && y <= y2 ) {
			mPieceRestoreTimes[i] = pieceRestoreTime;
			if( mFracturedPieces[i] )
				continue;
			pcs.push_back( i );
			fractureOutPiece( i );
		}
	}
}
Example #3
0
//! Resets the board, restores pieces and their position.
void Board::reset()
{
	// Remove old pieces
	clearPieces();

	// Add new pieces
	initPieces(mFlipped);
}
void CWall3D::update( float t )
{
	if( !mPiecesInited )
		initPieces();

	// update restoration texture
	if( mRestoreTexture ) {
		const float RESTORE_FADE_TIME = 0.2f;

		bool hadZeros = false;
		bool had255s = false;
		bool hadOthers = false;

		D3DLOCKED_RECT lr;
		mRestoreTexture->getObject()->LockRect( 0, &lr, NULL, D3DLOCK_DISCARD );

		BYTE* texptr = (BYTE*)lr.pBits;
		float* resval = mResTimeGrid;
		for( int iy = 0; iy < RESGRID_Y; ++iy ) {
			for( int ix = 0; ix < RESGRID_X; ++ix, ++resval ) {
				BYTE v;
				float rt = *resval;
				if( rt < 0.0f ) {
					v = 255;
					hadZeros = true;
				} else if( t <= rt - RESTORE_FADE_TIME ) {
					v = 0;
					hadZeros = true;
				} else {
					float alpha = (t-rt+RESTORE_FADE_TIME) / RESTORE_FADE_TIME;
					if( alpha >= 1.0f ) {
						// fully restored
						v = 255;
						*resval = -1.0f;
						had255s = true;
					} else {
						v = int(alpha*255);
						hadOthers = true;
					}
				}
				texptr[ix] = v;
			}
			texptr += lr.Pitch;
		}

		mRestoreTexture->getObject()->UnlockRect( 0 );

		mNeedsRenderFadeMesh = (hadOthers) || (hadZeros && had255s);

		// restore needed pieces
		int n = mWall2D.getPieceCount();
		for( int i = 0; i < n; ++i ) {
			if( mFracturedPieces[i] && t>=mPieceRestoreTimes[i] )
				fractureInPiece( i );
		}
	}
}
Example #5
0
void newGame(int l, int p, int t)
{
	//Setup the new game features
	clearScreen();
	setupblocks();
	initMap();
	initPieces(current, next);
	time_l = rows_del = 0; //Initialize the variable that checks time of the level
	bonus[0] = bonus[1] = bonus[2] = 0;
}
Example #6
0
void Puzzle::execute() {
	_active = true;
	_vm->getTimerManager()->installTimerProc(&hintTimerCallback, kPuzzleHintTime, this);

	initPieces();

	showPieces();

	_vm->_interface->setMode(kPanelConverse);
	clearHint();
	//_solved = true; // Cheat
	//exitPuzzle();
}
Example #7
0
/**
@param squareSize The width and height for each square.
*/
Board::Board(int squareSize, bool flipped)
{
	// Load the textures
	mBlack = gGraphics->loadTexture("imgs\\black.bmp");
	mWhite = gGraphics->loadTexture("imgs\\white.bmp");
	mBorder = gGraphics->loadTexture("imgs\\border.bmp");
	mTextures = new Textures();
	mFlipped = flipped;

	// Set board position and square size
	mSquareSize = squareSize;
	mTopLeft = Vector(20, 20);

	// Create the pieces and place them at the correct locations
	initPieces(flipped);

	// Set off screen positions
	mInvalid = Position(-10, -10);
	mSelected = Position(-10, -10);
}
Example #8
0
BoardWidget::BoardWidget(Board& b, QWidget *parent)
    : PieceWidget(10,9,parent), board(b)
{
    pList =0;
    gettingMove = false;
    editMode = false;
    renderMode = false;

    /* setup cursors */

#define createCursor(bitmap,name) \
    static QBitmap bitmap = QBitmap::fromData(QSize(bitmap##_width, bitmap##_height), \
    (unsigned char *) bitmap##_bits);        \
    static QBitmap bitmap##Mask = QBitmap::fromData(QSize(bitmap##Mask_width, bitmap##Mask_height), \
    (unsigned char *) bitmap##Mask_bits);    \
    name = new QCursor(bitmap, bitmap##Mask, bitmap##_x_hot, bitmap##_y_hot);

    createCursor(Arrow1, arrow[1]);
    createCursor(Arrow2, arrow[2]);
    createCursor(Arrow3, arrow[3]);
    createCursor(Arrow4, arrow[4]);
    createCursor(Arrow5, arrow[5]);
    createCursor(Arrow6, arrow[6]);

    setCursor(Qt::CrossCursor);

    //  boardColor   = new QColor("lightblue");
    boardColor   = new QColor(palette().color(backgroundRole()));
    redColor     = new QColor("red");
    yellowColor  = new QColor("yellow");
    redHColor    = new QColor("orange");
    yellowHColor = new QColor("green");

    initPieces();
    updatePosition();
}
void CWall3D::fracturePiecesInSphere( float t, const SVector3& pos, float radius, TIntVector& pcs,
		float restoreAfter, float restoreDuration, bool noRestore )
{
	if( !mPiecesInited )
		initPieces();

	pcs.resize( 0 );
	
	// to local space
	SVector3 locPos;
	D3DXVec3TransformCoord( &locPos, &pos, &mInvMatrix );

	if( locPos.z < -radius || locPos.z > radius )
		return;

	// remember restore times
	if( mResTimeGrid && !noRestore ) {
		float rad = radius*2.0f;
		float lx1 = (locPos.x - rad) / mWall2D.getSize().x * RESGRID_X;
		float lx2 = (locPos.x + rad) / mWall2D.getSize().x * RESGRID_X;
		float ly1 = (locPos.y - rad) / mWall2D.getSize().y * RESGRID_Y;
		float ly2 = (locPos.y + rad) / mWall2D.getSize().y * RESGRID_Y;
		int ix1 = (int)clamp( lx1, 0, RESGRID_X-1 );
		int ix2 = (int)clamp( lx2, 0, RESGRID_X-1 );
		int iy1 = (int)clamp( ly1, 0, RESGRID_Y-1 );
		int iy2 = (int)clamp( ly2, 0, RESGRID_Y-1 );
		float dx = mWall2D.getSize().x / RESGRID_X;
		float dy = mWall2D.getSize().y / RESGRID_Y;
		for( int iy = iy1; iy <= iy2; ++iy ) {
			float* resval = mResTimeGrid + RESGRID_X*iy + ix1;
			float fy = iy * dy;
			for( int ix = ix1; ix <= ix2; ++ix, ++resval ) {
				float fx = ix * dx;

				// don't touch restore grid outside the circle
				float diffX = fx-locPos.x;
				float diffY = fy-locPos.y;
				float diffR2 = diffX*diffX + diffY*diffY;
				if( diffR2 > rad*rad )
					continue;

				// restore time for this grid point - start at
				// t+restoreAfter at circle boundaries, later at circle
				// center
				float resTime = t + restoreAfter + (1.0f-diffR2/(rad*rad)) * restoreDuration;

				if( *resval < 0.0f )
					*resval = resTime;
				else
					*resval = max( (*resval), resTime );
			}
		}
	}

	// fetch the pieces

	float pieceRestoreTime;
	if( noRestore ) {
		pieceRestoreTime = t + 1.0e9f;
	} else {
		pieceRestoreTime = t + restoreAfter + restoreDuration;
	}

	// TODO: optimize, right now linear search!
	int n = mWall2D.getPieceCount();
	for( int i = 0; i < n; ++i ) {
		const CWallPiece2D& p = mWall2D.getPiece( i );
		SVector2 c = p.getAABB().getCenter();
		SVector3 tocenter = locPos - SVector3(c.x,c.y,0);
		if( tocenter.lengthSq() < radius*radius ) {
			mPieceRestoreTimes[i] = pieceRestoreTime;
			if( mFracturedPieces[i] )
				continue;
			pcs.push_back( i );
			fractureOutPiece( i );
		}
	}
}
Example #10
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
  isHumanTurnToChoose = false;
  isHumanTurnToPutPiece = true;

  isPieceSelected = false;
  isBoardPositionSelected = false;

  currentPieceId = -1;
  currentBoardPositionId = -1;

  // Main Widget of the MainWindow
  QWidget *widget = new QWidget;
  setCentralWidget( widget );

  // Board layout
  boardLayout = new QGridLayout;
  //boardLayout->setVerticalSpacing ( 0 );
  //boardLayout->setColumnMinimumWidth( 8 );
  //boardLayout->setRowMinimumHeight( 8 );

  // Init the board
  initBoard();

  // Piece layout
  pieceLayout = new QGridLayout;
  // init the piece layout
  initPieces();

  // Right layout controls
  selectPieceButton = new QPushButton( "Select piece" );
  selectPieceButton->setDisabled( true );
  connect( selectPieceButton, SIGNAL( clicked() ), this, SLOT( clickSelectButton() ) );

  selectedPiece = new QLabel();
  selectedPiece->setFrameStyle( QFrame::Panel | QFrame::Sunken );

  // Layout where is shown the selected piece
  QHBoxLayout *selectedPieceLayout = new QHBoxLayout;
  selectedPieceLayout->addWidget( selectPieceButton );
  selectedPieceLayout->addWidget( selectedPiece );

  // Right layout
  QVBoxLayout *rightLayout = new QVBoxLayout;
  rightLayout->addLayout(pieceLayout);
  rightLayout->addLayout(selectedPieceLayout);

  QFrame *verticalLine = new QFrame;
  verticalLine->setFrameStyle( QFrame::VLine | QFrame::Sunken );

  // Main layout
  QHBoxLayout *mainLayout = new QHBoxLayout;
  //mainLayout->setMargin(5);
  mainLayout->addLayout(boardLayout);
  mainLayout->addWidget(verticalLine);
  mainLayout->addLayout(rightLayout);

  widget->setLayout(mainLayout);

  // Setting some properties of the main window
  setWindowTitle( tr("uQuarto") );
  setMinimumSize( 640, 480 );
  resize( 640, 480 );
}
Example #11
0
Board::Board(){	
	dim = 8;
	initPieces();
}