Ejemplo n.º 1
0
int canReach(int *matr){
	int pos = firstOne(&(*matr));
	int x;
	tos=stack;
	p1=stack;
	int reachSize=SIZE*2;
	int canReach[reachSize];
	int i=1,reachMax=0;
	for(i=0;i<reachSize;i++){
		canReach[i]=NULL;
	}
	push(pos);
	while(1==1){
		x=pop();
		if(exists(canReach,reachMax,x)==0){
			canReach[reachMax]=x;
			reachMax++;
		}
		/* Fetch neighbour not in canReach */
		int c=x%width;
		int r=(1+(x-c)/width);
		if((matr[x-1]==1) && (x%width!=1)){ // Not left edge.
			if(exists(canReach,reachMax,(x-1))==0){
				push(x-1);
			}
		}
		if((matr[x+1]==1) && (x%width!=0)){ // Not right edge.
			if(exists(canReach,reachMax,(x+1))==0){
				push(x+1);
			}
		}
		if(x>width){ // Not first row
			if(matr[x-width]==1){ // On top.
				if(exists(canReach,reachMax,(x-width))==0){
					push(x-width);
				}
			}
		}
		if(x<=(height-1)*width){ // Not last row
			if(matr[x+width]==1){ // Below.
				if(exists(canReach,reachMax,(x+width))==0){
					push(x+width);
				}
			}
		}
		if(empty()==1){
			break;
		}
	}
	int g=0,tot=0;
	while(g<reachMax){
		tot++;
		g++;
	}
	return tot;
}
Ejemplo n.º 2
0
BOOLTYPE isAttacked(BitMap &targetBitmap, const unsigned char &fromSide)
{
 
//  ===========================================================================
//  isAttacked is used mainly as a move legality test to see if targetBitmap is
//  attacked by white or black.
//  Returns true at the first attack found, and returns false if no attack is found.
//  It can be used for:
//  - check detection, and
//  - castling legality: test to see if the king passes through, or ends up on,
//  a square that is attacked
//  ===========================================================================
 
       BitMap tempTarget;
       BitMap slidingAttackers;
       int to;
 
       tempTarget = targetBitmap;
       if (fromSide) // test for attacks from BLACK to targetBitmap
       {
              while (tempTarget)
              {
                     to = firstOne(tempTarget);
 
                     if (board.blackPawns & WHITE_PAWN_ATTACKS[to]) return true;
                     if (board.blackKnights & KNIGHT_ATTACKS[to]) return true;
                     if (board.blackKing & KING_ATTACKS[to]) return true;
 
                     // file / rank attacks
                     slidingAttackers = board.blackQueens | board.blackRooks;
                     if (slidingAttackers)
                     {
                         if (RANK_ATTACKS[to][((board.occupiedSquares & RANKMASK[to]) >> RANKSHIFT[to])] & slidingAttackers) return true;
                           if (FILE_ATTACKS[to][((board.occupiedSquares & FILEMASK[to]) * FILEMAGIC[to]) >> 57] & slidingAttackers) return true;
                     }
 
                     // diagonals
                     slidingAttackers = board.blackQueens | board.blackBishops;
                     if (slidingAttackers)
                     {
                if (DIAGA8H1_ATTACKS[to][((board.occupiedSquares & DIAGA8H1MASK[to]) * DIAGA8H1MAGIC[to]) >> 57] & slidingAttackers) return true;
                if (DIAGA1H8_ATTACKS[to][((board.occupiedSquares & DIAGA1H8MASK[to]) * DIAGA1H8MAGIC[to]) >> 57] & slidingAttackers) return true;
                     }
 
                     tempTarget ^= BITSET[to];
              }
       }
       else // test for attacks from WHITE to targetBitmap
       {
              while (tempTarget)
Ejemplo n.º 3
0
int captgen(int index)
{
 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// generate pseudo-legal captures and promotions generator,
// using magic multiplication instead of rotated bitboards.
// The first free location in moveBuffer[] is supplied in index,
// and the new first free location is returned
//  
// this function keeps the move list sorted (using SEE) and shortens 
// the list by discarding 'bad' moves. 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
       unsigned char opponentSide;
       unsigned int from, to;
	   int ifirst;
       BitMap tempPiece, tempMove;
       BitMap targetBitmap, freeSquares;
       Move move;
 
	   ifirst = index;
       move.clear();
       opponentSide = !board.nextMove;
       freeSquares = ~board.occupiedSquares;
 
       // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       // Black to move
       // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
		if (board.nextMove) // black to move
		{
			targetBitmap = board.whitePieces;  // we want captures only!
 
			// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			// Black Pawns
			// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			move.setPiec(BLACK_PAWN);
			tempPiece = board.blackPawns;
			while (tempPiece)   
			{
				from = firstOne(tempPiece);
				move.setFrom(from);
				tempMove = BLACK_PAWN_ATTACKS[from] & targetBitmap; // pawn captures
				if ((RANKS[from]) == 2) tempMove |= BLACK_PAWN_MOVES[from] & freeSquares; // promotions
 				while (tempMove)
				{
					to = firstOne(tempMove);
					move.setTosq(to);
					move.setCapt(board.square[to]);
					if ((RANKS[to]) == 1)
					{
						move.setProm(BLACK_QUEEN);		board.moveBuffer[index].moveInt = move.moveInt;
														board.addCaptScore(ifirst,index);
														index++;
						move.setProm(BLACK_ROOK);		board.moveBuffer[index].moveInt = move.moveInt;
														board.addCaptScore(ifirst,index);
														index++;
						move.setProm(BLACK_BISHOP);		board.moveBuffer[index].moveInt = move.moveInt;
														board.addCaptScore(ifirst,index);
														index++;
						move.setProm(BLACK_KNIGHT);		board.moveBuffer[index].moveInt = move.moveInt;
														board.addCaptScore(ifirst,index);
														index++;
						move.setProm(EMPTY);
					}
					else
					{
						board.moveBuffer[index].moveInt = move.moveInt;
						board.addCaptScore(ifirst,index);
						index++;
					}
					tempMove ^= BITSET[to];
				}
				if (board.epSquare)
				{
					if (BLACK_PAWN_ATTACKS[from] & BITSET[board.epSquare])
					{
						move.setProm(BLACK_PAWN);
						move.setCapt(WHITE_PAWN);
						move.setTosq(board.epSquare);
						board.moveBuffer[index].moveInt = move.moveInt;
						board.addCaptScore(ifirst,index);
						index++;
					}
				}
				tempPiece ^= BITSET[from];
				move.setProm(EMPTY);
			}                         

			  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              // Black Knights
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              move.setPiec(BLACK_KNIGHT);
              tempPiece = board.blackKnights;
              while (tempPiece)
              {
                     from = firstOne(tempPiece);
                     move.setFrom(from);
                     tempMove = KNIGHT_ATTACKS[from] & targetBitmap;
                     while (tempMove)          
                     {
                           to = firstOne(tempMove);
                           move.setTosq(to);
                           move.setCapt(board.square[to]);
                           board.moveBuffer[index].moveInt = move.moveInt;
						   board.addCaptScore(ifirst,index);
						   index++;
                           tempMove ^= BITSET[to];
                     }
                     tempPiece ^= BITSET[from];
              }
 
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              // Black Bishops
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              move.setPiec(BLACK_BISHOP);
              tempPiece = board.blackBishops;
              while (tempPiece)
              {
                     from = firstOne(tempPiece);
                     move.setFrom(from);
                     tempMove = BISHOPMOVES(from);   // see Macro's
                     while (tempMove)
                     {
                           to = firstOne(tempMove);
                           move.setTosq(to);
                           move.setCapt(board.square[to]);
                           board.moveBuffer[index].moveInt = move.moveInt;
						   board.addCaptScore(ifirst,index);
						   index++;
                           tempMove ^= BITSET[to];
                     }
                     tempPiece ^= BITSET[from];
              }
 
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              // Black Rooks
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              move.setPiec(BLACK_ROOK);
              tempPiece = board.blackRooks;
              while (tempPiece)
              {
                     from = firstOne(tempPiece);
                     move.setFrom(from);
                     tempMove = ROOKMOVES(from);   // see Macro's
                     while (tempMove)
                     {
                           to = firstOne(tempMove);
                           move.setTosq(to);
                           move.setCapt(board.square[to]);
                           board.moveBuffer[index].moveInt = move.moveInt;
						   board.addCaptScore(ifirst,index);
						   index++;
                           tempMove ^= BITSET[to];
                     }
                     tempPiece ^= BITSET[from];
              }
 
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              // Black Queens
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              move.setPiec(BLACK_QUEEN);
              tempPiece = board.blackQueens;
              while (tempPiece)
              {
                     from = firstOne(tempPiece);
                     move.setFrom(from);
                     tempMove = QUEENMOVES(from);   // see Macro's
                     while (tempMove)
                     {
                           to = firstOne(tempMove);
                           move.setTosq(to);
                           move.setCapt(board.square[to]);
                           board.moveBuffer[index].moveInt = move.moveInt;
						   board.addCaptScore(ifirst,index);
						   index++;
                           tempMove ^= BITSET[to];
                     }
                     tempPiece ^= BITSET[from];
              }
 
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              // Black King
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              move.setPiec(BLACK_KING);
              tempPiece = board.blackKing;
              while (tempPiece)
              {
                     from = firstOne(tempPiece);
                     move.setFrom(from);
                     tempMove = KING_ATTACKS[from] & targetBitmap;
                     while (tempMove)
                     {
                           to = firstOne(tempMove);
                           move.setTosq(to);
                           move.setCapt(board.square[to]);
                           board.moveBuffer[index].moveInt = move.moveInt;
						   board.addCaptScore(ifirst,index);
						   index++;
                           tempMove ^= BITSET[to];
                     } 
                     tempPiece ^= BITSET[from];
                     move.setProm(EMPTY);
              }
       }
 
       // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       // White to move
       // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
		else 
		{
			targetBitmap = board.blackPieces;
 
			// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			// White Pawns
			// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			move.setPiec(WHITE_PAWN);
			tempPiece = board.whitePawns;
			while (tempPiece)   
			{
				from = firstOne(tempPiece);
				move.setFrom(from);
				tempMove = WHITE_PAWN_ATTACKS[from] & targetBitmap; // pawn captures
				if ((RANKS[from]) == 7) tempMove |= WHITE_PAWN_MOVES[from] & freeSquares; // promotions
 				while (tempMove)
				{
					to = firstOne(tempMove);
					move.setTosq(to);
					move.setCapt(board.square[to]);
					if ((RANKS[to]) == 8)
					{
						move.setProm(WHITE_QUEEN);		board.moveBuffer[index].moveInt = move.moveInt;
														board.addCaptScore(ifirst,index);
														index++;
						move.setProm(WHITE_ROOK);		board.moveBuffer[index].moveInt = move.moveInt;
														board.addCaptScore(ifirst,index);
														index++;
						move.setProm(WHITE_BISHOP);		board.moveBuffer[index].moveInt = move.moveInt;
														board.addCaptScore(ifirst,index);
														index++;
						move.setProm(WHITE_KNIGHT);		board.moveBuffer[index].moveInt = move.moveInt;
														board.addCaptScore(ifirst,index);
														index++;
						move.setProm(EMPTY);
					}
					else
					{
						board.moveBuffer[index].moveInt = move.moveInt;
						board.addCaptScore(ifirst,index);
						index++;
					}
					tempMove ^= BITSET[to];
				}
				if (board.epSquare)
				{
					if (WHITE_PAWN_ATTACKS[from] & BITSET[board.epSquare])
					{
						move.setProm(WHITE_PAWN);
						move.setCapt(BLACK_PAWN);
						move.setTosq(board.epSquare);
						board.moveBuffer[index].moveInt = move.moveInt;
						board.addCaptScore(ifirst,index);
						index++;
					}
				}
				tempPiece ^= BITSET[from];
				move.setProm(EMPTY);
			}                         
 
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              // White Knights
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              move.setPiec(WHITE_KNIGHT);
              tempPiece = board.whiteKnights;
              while (tempPiece)
              {
                     from = firstOne(tempPiece);
                     move.setFrom(from);
                     tempMove = KNIGHT_ATTACKS[from] & targetBitmap;
                     while (tempMove)          
                     {
                           to = firstOne(tempMove);
                           move.setTosq(to);
                           move.setCapt(board.square[to]);
                           board.moveBuffer[index].moveInt = move.moveInt;
						   board.addCaptScore(ifirst,index);
						   index++;
                           tempMove ^= BITSET[to];
                     }
                     tempPiece ^= BITSET[from];
              }
 
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              // White Bishops
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              move.setPiec(WHITE_BISHOP);
              tempPiece = board.whiteBishops;
              while (tempPiece)
              {
                     from = firstOne(tempPiece);
                     move.setFrom(from);
                     tempMove = BISHOPMOVES(from);   // see Macro's
                     while (tempMove)
                     {
                           to = firstOne(tempMove);
                           move.setTosq(to);
                           move.setCapt(board.square[to]);
                           board.moveBuffer[index].moveInt = move.moveInt;
						   board.addCaptScore(ifirst,index);
						   index++;
                           tempMove ^= BITSET[to];
                     }
                     tempPiece ^= BITSET[from];
              }
 
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              // White Rooks
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              move.setPiec(WHITE_ROOK);
              tempPiece = board.whiteRooks;
              while (tempPiece)
              {
                     from = firstOne(tempPiece);
                     move.setFrom(from);
                     tempMove = ROOKMOVES(from);   // see Macro's
                     while (tempMove)
                     {
                           to = firstOne(tempMove);
                           move.setTosq(to);
                           move.setCapt(board.square[to]);
                           board.moveBuffer[index].moveInt = move.moveInt;
						   board.addCaptScore(ifirst,index);
						   index++;
                           tempMove ^= BITSET[to];
                     }
                     tempPiece ^= BITSET[from];
              }
 
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              // White Queens
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              move.setPiec(WHITE_QUEEN);
              tempPiece = board.whiteQueens;
              while (tempPiece)
              {
                     from = firstOne(tempPiece);
                     move.setFrom(from);
                     tempMove = QUEENMOVES(from);   // see Macro's
                     while (tempMove)
                     {
                           to = firstOne(tempMove);
                           move.setTosq(to);
                           move.setCapt(board.square[to]);
                           board.moveBuffer[index].moveInt = move.moveInt;
						   board.addCaptScore(ifirst,index);
						   index++;
                           tempMove ^= BITSET[to];
                     }
                     tempPiece ^= BITSET[from];
              }
 
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              // White king
              // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              move.setPiec(WHITE_KING);
              tempPiece = board.whiteKing;
              while (tempPiece)
              {
                     from = firstOne(tempPiece);
                     move.setFrom(from);
                     tempMove = KING_ATTACKS[from] & targetBitmap;
                     while (tempMove)
                     {
                           to = firstOne(tempMove);
                           move.setTosq(to);
                           move.setCapt(board.square[to]);
                           board.moveBuffer[index].moveInt = move.moveInt;
						   board.addCaptScore(ifirst, index);
						   index++;
                           tempMove ^= BITSET[to];
                     } 
                     tempPiece ^= BITSET[from];
                     move.setProm(EMPTY);
              }
       }     
        return index;
}
Ejemplo n.º 4
0
int movegen(int index)
{
 
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	// This is KENNY's pseudo-legal bitmap move generator,
	// using magic multiplication instead of rotated bitboards.
	// There is no check if a move leaves the king in check
	// The first free location in moveBuffer[] is supplied in index,
	// and the new first free location is returned
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
	unsigned char opponentSide;
	unsigned int from, to;
	BitMap tempPiece, tempMove;
	BitMap targetBitmap, freeSquares;
	Move move;
 
	move.clear();
	opponentSide = !board.nextMove;
	freeSquares = ~board.occupiedSquares;
 
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	// Black to move
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
	if (board.nextMove) // black to move
	{
		targetBitmap = ~board.blackPieces; // we cannot capture one of our own pieces!
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// Black Pawns
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(BLACK_PAWN);
		tempPiece = board.blackPawns;
		while (tempPiece)   
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = BLACK_PAWN_MOVES[from] & freeSquares;                // normal moves
			if (RANKS[from] == 7 && tempMove)                               
			tempMove |= (BLACK_PAWN_DOUBLE_MOVES[from] & freeSquares);  // add double moves
			tempMove |= BLACK_PAWN_ATTACKS[from] & board.whitePieces;       // add captures
			while (tempMove)
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				if ((RANKS[to]) == 1)                                       // add promotions
				{
					move.setProm(BLACK_QUEEN);   board.moveBuffer[index++].moveInt = move.moveInt;
					move.setProm(BLACK_ROOK);    board.moveBuffer[index++].moveInt = move.moveInt;
					move.setProm(BLACK_BISHOP);  board.moveBuffer[index++].moveInt = move.moveInt;
					move.setProm(BLACK_KNIGHT);  board.moveBuffer[index++].moveInt = move.moveInt;
					move.setProm(EMPTY);      
				}
				else
				{
					board.moveBuffer[index++].moveInt = move.moveInt;
				}
				tempMove ^= BITSET[to];
			}
			// add en-passant captures:
			if (board.epSquare)   // do a quick check first
			{
				if (BLACK_PAWN_ATTACKS[from] & BITSET[board.epSquare])
				{
					if (board.whitePawns & BITSET[board.epSquare + 8])  // final check to protect against same color capture during null move
					{
						move.setProm(BLACK_PAWN);
						move.setCapt(WHITE_PAWN);
						move.setTosq(board.epSquare);
						board.moveBuffer[index++].moveInt = move.moveInt;
					}
				}
			}
			tempPiece ^= BITSET[from];
			move.setProm(EMPTY);
		}                         
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// Black Knights
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(BLACK_KNIGHT);
		tempPiece = board.blackKnights;
		while (tempPiece)
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = KNIGHT_ATTACKS[from] & targetBitmap;
			while (tempMove)          
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				board.moveBuffer[index++].moveInt = move.moveInt;
				tempMove ^= BITSET[to];
			}
			tempPiece ^= BITSET[from];
		}
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// Black Bishops
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(BLACK_BISHOP);
		tempPiece = board.blackBishops;
		while (tempPiece)
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = BISHOPMOVES(from);   // see Macro's
			while (tempMove)
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				board.moveBuffer[index++].moveInt = move.moveInt;
				tempMove ^= BITSET[to];
			}
			tempPiece ^= BITSET[from];
		}
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// Black Rooks
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(BLACK_ROOK);
		tempPiece = board.blackRooks;
		while (tempPiece)
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = ROOKMOVES(from);   // see Macro's
			while (tempMove)
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				board.moveBuffer[index++].moveInt = move.moveInt;
				tempMove ^= BITSET[to];
			}
			tempPiece ^= BITSET[from];
		}
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// Black Queens
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(BLACK_QUEEN);
		tempPiece = board.blackQueens;
		while (tempPiece)
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = QUEENMOVES(from);   // see Macro's
			while (tempMove)
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				board.moveBuffer[index++].moveInt = move.moveInt;
				tempMove ^= BITSET[to];
			}
		tempPiece ^= BITSET[from];
		}
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// Black King
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(BLACK_KING);
		tempPiece = board.blackKing;
		while (tempPiece)
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = KING_ATTACKS[from] & targetBitmap;
			while (tempMove)
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				board.moveBuffer[index++].moveInt = move.moveInt;
				tempMove ^= BITSET[to];
			}
 
			//     Black 0-0 Castling:
			if (board.castleBlack & CANCASTLEOO)
			{
				if (!(maskFG[1] & board.occupiedSquares))
				{
					if (!isAttacked(maskEG[BLACK_MOVE], WHITE_MOVE))
					{
						board.moveBuffer[index++].moveInt = BLACK_OO_CASTL;   // predefined unsigned int
					}
				}
			}
			//     Black 0-0-0 Castling:
			if (board.castleBlack & CANCASTLEOOO)
			{
				if (!(maskBD[1] & board.occupiedSquares))
				{
					if (!isAttacked(maskCE[BLACK_MOVE], WHITE_MOVE))
					{
						board.moveBuffer[index++].moveInt = BLACK_OOO_CASTL; // predefined unsigned int
					}
				}
			}
			tempPiece ^= BITSET[from];
			move.setProm(EMPTY);
		}
	}
 
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	// White to move
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
	else 
	{
		targetBitmap = ~board.whitePieces; // we cannot capture one of our own pieces!
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// White Pawns
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(WHITE_PAWN);
		tempPiece = board.whitePawns;
		while (tempPiece)   
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = WHITE_PAWN_MOVES[from] & freeSquares;                // normal moves
			if (RANKS[from] == 2 && tempMove)                               
			tempMove |= (WHITE_PAWN_DOUBLE_MOVES[from] & freeSquares);  // add double moves
			tempMove |= WHITE_PAWN_ATTACKS[from] & board.blackPieces;       // add captures
			while (tempMove)
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				if ((RANKS[to]) == 8)                                       // add promotions
				{
					move.setProm(WHITE_QUEEN);   board.moveBuffer[index++].moveInt = move.moveInt;
					move.setProm(WHITE_ROOK);    board.moveBuffer[index++].moveInt = move.moveInt;
					move.setProm(WHITE_BISHOP);  board.moveBuffer[index++].moveInt = move.moveInt;
					move.setProm(WHITE_KNIGHT);  board.moveBuffer[index++].moveInt = move.moveInt;
					move.setProm(EMPTY);      
				}
				else
				{
					board.moveBuffer[index++].moveInt = move.moveInt;
				}
				tempMove ^= BITSET[to];
			}
			// add en-passant captures:
			if (board.epSquare)   // do a quick check first
			{
				if (WHITE_PAWN_ATTACKS[from] & BITSET[board.epSquare])
				{
					if (board.blackPawns & BITSET[board.epSquare - 8])  // final check to protect against same color capture during null move
					{
						move.setProm(WHITE_PAWN);
						move.setCapt(BLACK_PAWN);
						move.setTosq(board.epSquare);
						board.moveBuffer[index++].moveInt = move.moveInt;
					}
				}
			}
			tempPiece ^= BITSET[from];
			move.setProm(EMPTY);
		}                         
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// White Knights
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(WHITE_KNIGHT);
		tempPiece = board.whiteKnights;
		while (tempPiece)
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = KNIGHT_ATTACKS[from] & targetBitmap;
			while (tempMove)          
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				board.moveBuffer[index++].moveInt = move.moveInt;
				tempMove ^= BITSET[to];
			}
			tempPiece ^= BITSET[from];
		}
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// White Bishops
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(WHITE_BISHOP);
		tempPiece = board.whiteBishops;
		while (tempPiece)
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = BISHOPMOVES(from);   // see Macro's
			while (tempMove)
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				board.moveBuffer[index++].moveInt = move.moveInt;
				tempMove ^= BITSET[to];
			}
			tempPiece ^= BITSET[from];
		}
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// White Rooks
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(WHITE_ROOK);
		tempPiece = board.whiteRooks;
		while (tempPiece)
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = ROOKMOVES(from);   // see Macro's
			while (tempMove)
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				board.moveBuffer[index++].moveInt = move.moveInt;
				tempMove ^= BITSET[to];
			}
			tempPiece ^= BITSET[from];
		}
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// White Queens
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(WHITE_QUEEN);
		tempPiece = board.whiteQueens;
		while (tempPiece)
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = QUEENMOVES(from);   // see Macro's
			while (tempMove)
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				board.moveBuffer[index++].moveInt = move.moveInt;
				tempMove ^= BITSET[to];
			}
			tempPiece ^= BITSET[from];
		}
 
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// White king
		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		move.setPiec(WHITE_KING);
		tempPiece = board.whiteKing;
		while (tempPiece)
		{
			from = firstOne(tempPiece);
			move.setFrom(from);
			tempMove = KING_ATTACKS[from] & targetBitmap;
			while (tempMove)
			{
				to = firstOne(tempMove);
				move.setTosq(to);
				move.setCapt(board.square[to]);
				board.moveBuffer[index++].moveInt = move.moveInt;
				tempMove ^= BITSET[to];
			}
 
			//     White 0-0 Castling:
			if (board.castleWhite & CANCASTLEOO)
			{
				if (!(maskFG[0] & board.occupiedSquares))
				{
					if (!isAttacked(maskEG[WHITE_MOVE], BLACK_MOVE))
					{
						board.moveBuffer[index++].moveInt = WHITE_OO_CASTL; // predefined unsigned int
					}
				}
			}
 
			//     White 0-0-0 Castling:
			if (board.castleWhite & CANCASTLEOOO)
			{
				if (!(maskBD[0] & board.occupiedSquares))
				{
					if (!isAttacked(maskCE[WHITE_MOVE], BLACK_MOVE))
					{
						board.moveBuffer[index++].moveInt = WHITE_OOO_CASTL; // predefined unsigned int
					}
				}
			}
			tempPiece ^= BITSET[from];
			move.setProm(EMPTY);
		}
	}     
	return index;
}