⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plygenerator.java

📁 elcome to the Java-Chess project! As you might know, we aim at creating a fully functional chess
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			    addPly( new EnPassantPlyImpl( new PositionImpl( attackableIndex + 9)			                 	          , new PositionImpl( attackableIndex)				                          , new PositionImpl( destinationIndex))				    , MATERIAL_WIN);			}			// Add the en passant attacks.			if( ( ( ( pawnPos & BitBoard._NOT_LINE_H) >> 7) & 0x01FFFFFFFFFFFFFFL & attackablePawnBitmask) != 0L) {			    addPly( new EnPassantPlyImpl( new PositionImpl( attackableIndex + 7)			                 	          , new PositionImpl( attackableIndex)				                          , new PositionImpl( destinationIndex))				    , MATERIAL_WIN);			}		    }		}	    }	    // Add all the 2 square plies. Since the square in front of the pawn has to be free, I have to	    // add the bit and with the shifted empty squares.	    addRelativePliesDownward( ( ( pawnPos & BitBoard._ROW_7 & ( _emptySquares << 8) ) >> 16)  & 0x0000FFFFFFFFFFFFL & _emptySquares, 39, 32, 16);	    // Add all the 1 square plies.	    long movedPawns = (pawnPos >> 8) & 0x00FFFFFFFFFFFFFFL & _emptySquares;	    addRelativePliesDownward( movedPawns & BitBoard._NOT_ROW_1, 56, 8, 8);	    	    // Now take care of the last row.	    movedPawns &= BitBoard._ROW_1;	    while( movedPawns != 0L) {		int destinationSquare = BitUtils.getHighestBit( movedPawns);		int sourceSquare = destinationSquare + 8;		// Add all transformation types as plies.		addTransformationPly( sourceSquare, destinationSquare, Piece.QUEEN, QUEEN_TRANSFORMATION);		addTransformationPly( sourceSquare, destinationSquare, Piece.KNIGHT, KNIGHT_TRANSFORMATION);		addTransformationPly( sourceSquare, destinationSquare, Piece.ROOK, ROOK_TRANSFORMATION);		addTransformationPly( sourceSquare, destinationSquare, Piece.BISHOP, BISHOP_TRANSFORMATION);		movedPawns &= ~( 1L << destinationSquare);	    }	}    }    /**     * Compute the knight plies for each square. This is done at startup,     * so we can get the plies by a simple array access.     */    private final void precomputeKnightPlies() {	for( int i = 0; i < 64; i++) {	    long currentMask = 0L;	    int line = i & 7;	    int row = i >> 3;	    for( int currentPlyIndex = 0; currentPlyIndex < _knightPlyOffset.length; currentPlyIndex++) {		int [] curOffsets = _knightPlyOffset[ currentPlyIndex];		int targetRow = row + curOffsets[1];		int targetLine = line + curOffsets[0];		if( targetRow >= 0 && targetRow < 8 && targetLine >= 0 && targetLine < 8) {		    currentMask |= 1L << ((targetRow << 3) + targetLine);		}	    }	    _knightMask[i] = currentMask; 	}    }    /**     * Compute the king moves for each square in advance.     */     private final void precomputeKingPlies() {	 for( int i = 0; i < 64; i++) {	     long currentMask = 0L;	     int line = i & 7;	     int row = i >> 3;	     for( int currentPlyIndex = 0; currentPlyIndex < _kingPlyOffset.length; currentPlyIndex++) {		 int [] curOffsets = _kingPlyOffset[ currentPlyIndex];		 int targetRow = row + curOffsets[1];		 int targetLine = line + curOffsets[0];		 if( targetRow >= 0 && targetRow < 8 && targetLine >= 0 && targetLine < 8) {		     currentMask |= 1L << ((targetRow << 3) + targetLine);		 }	     }	     _kingMask[i] = currentMask; 	}      }    /**     * Add all the plies for knights of the current color.     */    private final void addPliesForKnights() {	long knightPositions = getBoard().getPositionOfPieces( _white ? Piece.KNIGHT << 1 | 1 : Piece.KNIGHT << 1 );		while( knightPositions != 0) {	    int highestBit = BitUtils.getHighestBit( knightPositions);	    long curMoves = _knightMask[ highestBit] & (_emptySquares | _attackablePieces);	    int startBitRange = highestBit - 17;	    if( startBitRange < 0) {		startBitRange = 0;	    }	    int endBitRange = highestBit + 17;	    if( endBitRange > 63) {		endBitRange = 63;	    }	    addAbsolutePlies( curMoves, startBitRange, endBitRange, highestBit);	    knightPositions &= ~(1L << highestBit);	}    }    /**     * Add the plies for bishops.     */    public final void addPliesForBishops() {	long bishopPositions = getBoard().getPositionOfPieces( _white ? Piece.BISHOP << 1 | 1 : Piece.BISHOP << 1);	while( bishopPositions != 0) {	    int highestBit = BitUtils.getHighestBit( bishopPositions);	    addPliesForBishopPos( highestBit);	    bishopPositions &= ~(1L << highestBit);	}    }    /**     * Add the plies for a bishop position.     *     * @param square The square index of the bishop pos.     */    private final void addPliesForBishopPos( int square) {	int orgPos = square;  // Save the original position.	int squareRow = square >> 3;	int squareLine = square & 7;	long bitmask;	if( squareRow > 0) {  // If we are not on row 1	    if( squareLine < 7) {		// Compute plies to the lower right.		square -= 7;		bitmask = 1L << square;		while( square >= 0 && ( ( square & 7) > 0)) {		    if( ( bitmask & (_emptySquares | _attackablePieces)) != 0L) {			addRegularPly( orgPos, square, (bitmask & _attackablePieces) != 0L ? MATERIAL_WIN : REGULAR_PLY);						// If we attacked a piece, we cannot move further			if( ( bitmask & _attackablePieces) != 0L) {			    break;			}		    } else {			break;		    }		    square -= 7;		    bitmask >>= 7;		    bitmask &= 0x01FFFFFFFFFFFFFFL;  // This is just to work around the signed extension		    // , that causes Java to shift 1 bits into the mask		}	    }	    if( squareLine > 0) {		// Compute plies to the lower left.		square = orgPos - 9;		bitmask = 1L << square;		while( square >= 0 && ( ( square & 7) != 7)) {		    if( ( bitmask & (_emptySquares | _attackablePieces)) != 0L) {			addRegularPly( orgPos, square, (bitmask & _attackablePieces) != 0L ? MATERIAL_WIN : REGULAR_PLY);						// If we attacked a piece, we cannot move further			if( ( bitmask & _attackablePieces) != 0L) {			    break;			}		    } else {			break;		    }		    square -= 9;		    bitmask >>= 9;		    bitmask &= 0x007FFFFFFFFFFFFFL;  // Workaround for signed bit extension.		}	    }	}	if( squareRow < 7) {	    if( squareLine > 0) {		// Compute plies to the upper left.		square = orgPos + 7;		bitmask = 1L << square;		while( square < 64 && ( ( square & 7) != 7)) {		    if( ( bitmask & (_emptySquares | _attackablePieces)) != 0L) {			addRegularPly( orgPos, square, (bitmask & _attackablePieces) != 0L ? MATERIAL_WIN : REGULAR_PLY);						// If we attacked a piece, we cannot move further			if( ( bitmask & _attackablePieces) != 0L) {			    break;			}		    } else {			break;		    }		    square += 7;		    bitmask <<= 7;		}	    }	    if( squareLine < 7) {		// Compute plies to the upper right.		square = orgPos + 9;		bitmask = 1L << square;		while( square < 64 && ( ( square & 7) > 0)) {		    if( ( bitmask & (_emptySquares | _attackablePieces)) != 0L) {			addRegularPly( orgPos, square, (bitmask & _attackablePieces) != 0L ? MATERIAL_WIN : REGULAR_PLY);						// If we attacked a piece, we cannot move further			if( ( bitmask & _attackablePieces) != 0L) {			    break;			}		    } else {			break;		    }		    square += 9;		    bitmask <<= 9;		}	    }	}    }    /**     * Add the plies for rooks.     */    public final void addPliesForRooks() {	long rookPositions = getBoard().getPositionOfPieces( _white ? Piece.ROOK << 1 | 1 : Piece.ROOK << 1);	while( rookPositions != 0) {	    int highestBit = BitUtils.getHighestBit( rookPositions);	    addPliesForRookPos( highestBit);	    rookPositions &= ~(1L << highestBit);	}    }    /**     * Add the plies for one rook position.     *     * @param square The square index of the rook pos.     */    private final void addPliesForRookPos( int square) {	int orgPos = square;  // Save the original position.	long bitmask;	// Compute plies to the left.	bitmask = 1L << square;	while( ( square & 7) > 0) {	    square -= 1;	    bitmask >>= 1;	    bitmask &= 0x7FFFFFFFFFFFFFFFL;	    if( ( bitmask & (_emptySquares | _attackablePieces)) != 0) {		addRegularPly( orgPos, square, (bitmask & _attackablePieces) != 0L ? MATERIAL_WIN : REGULAR_PLY);				// If we attacked a piece, we cannot move further		if( ( bitmask & _attackablePieces) != 0) {		    break;		}	    } else {		break;	    }	}	// Compute plies downwards.	square = orgPos;	bitmask = 1L << square;	while( square > 8) {	    square -= 8;	    bitmask >>= 8;	    bitmask &= 0x00FFFFFFFFFFFFFFL;	    if( ( bitmask & (_emptySquares | _attackablePieces)) != 0) {		addRegularPly( orgPos, square, (bitmask & _attackablePieces) != 0L ? MATERIAL_WIN : REGULAR_PLY);				// If we attacked a piece, we cannot move further		if( ( bitmask & _attackablePieces) != 0) {		    break;		}	    } else {		break;	    }	}	// Compute plies to the right.	square = orgPos;	bitmask = 1L << square;	while( ( square & 7) < 7) {	    square += 1;	    bitmask <<= 1;	    if( ( bitmask & (_emptySquares | _attackablePieces)) != 0) {		addRegularPly( orgPos, square, (bitmask & _attackablePieces) != 0L ? MATERIAL_WIN : REGULAR_PLY);				// If we attacked a piece, we cannot move further		if( ( bitmask & _attackablePieces) != 0) {		    break;		}	    } else {		break;	    }	}	// Compute plies upwards.	square = orgPos;	bitmask = 1L << square;	while( square < 56) {	    square += 8;	    bitmask <<= 8;	    if( ( bitmask & (_emptySquares | _attackablePieces)) != 0) {		addRegularPly( orgPos, square, (bitmask & _attackablePieces) != 0L ? MATERIAL_WIN : REGULAR_PLY);				// If we attacked a piece, we cannot move further		if( ( bitmask & _attackablePieces) != 0) {		    break;		}	    } else {		break;	    }	}    }    /**     * Add the plies for queens.     */    public final void addPliesForQueens() {	long queenPositions = getBoard().getPositionOfPieces( _white ? Piece.QUEEN << 1 | 1 : Piece.QUEEN << 1);	while( queenPositions != 0) {	    int highestBit = BitUtils.getHighestBit( queenPositions);	    addPliesForQueenPos( highestBit);	    queenPositions &= ~(1L << highestBit);	}    }    /**     * Add the plies for one queen position.     *     * @param square The square index of the queen position.     */    private final void addPliesForQueenPos( int square) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -