?? plygenerator.java
字號:
} // Add the en passant attacks. if( ( ( ( pawnPos & BitBoard._NOT_LINE_H) >>> 7) & 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) & _emptySquares, 39, 32, 16); // Add all the 1 square plies. long movedPawns = (pawnPos >>> 8) & _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. boolean capture = ( ( ( 1L << destinationSquare) & _attackablePieces) != 0L); addTransformationPly( sourceSquare, destinationSquare, Piece.QUEEN, capture, QUEEN_TRANSFORMATION); addTransformationPly( sourceSquare, destinationSquare, Piece.KNIGHT, capture, KNIGHT_TRANSFORMATION); addTransformationPly( sourceSquare, destinationSquare, Piece.ROOK, capture, ROOK_TRANSFORMATION); addTransformationPly( sourceSquare, destinationSquare, Piece.BISHOP, capture, 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) { boolean capture = ( (bitmask & _attackablePieces) != 0L); addRegularPly( orgPos, square, capture, capture ? MATERIAL_WIN : REGULAR_PLY); // If we attacked a piece, we cannot move further if( capture) { break; } } else { break; } square -= 7; bitmask >>>= 7; } } 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) { boolean capture = ( (bitmask & _attackablePieces) != 0L); addRegularPly( orgPos, square, capture, capture ? MATERIAL_WIN : REGULAR_PLY); // If we attacked a piece, we cannot move further if( capture) { break; } } else { break; } square -= 9; bitmask >>>= 9; } } } 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) { boolean capture = ( (bitmask & _attackablePieces) != 0L); addRegularPly( orgPos, square, capture, capture ? MATERIAL_WIN : REGULAR_PLY); // If we attacked a piece, we cannot move further if( capture) { 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) { boolean capture = ( (bitmask & _attackablePieces) != 0L); addRegularPly( orgPos, square, capture, capture ? MATERIAL_WIN : REGULAR_PLY); // If we attacked a piece, we cannot move further if( capture) { 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; if( ( bitmask & (_emptySquares | _attackablePieces)) != 0) { boolean capture = ( (bitmask & _attackablePieces) != 0L); addRegularPly( orgPos, square, capture, capture ? MATERIAL_WIN : REGULAR_PLY); // If we attacked a piece, we cannot move further if( capture) { break; } } else { break; } } // Compute plies downwards. square = orgPos; bitmask = 1L << square; while( square > 8) { square -= 8; bitmask >>>= 8; if( ( bitmask & (_emptySquares | _attackablePieces)) != 0) { boolean capture = ( (bitmask & _attackablePieces) != 0L); addRegularPly( orgPos, square, capture, capture ? MATERIAL_WIN : REGULAR_PLY); // If we attacked a piece, we cannot move further if( capture) { 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) { boolean capture = ( (bitmask & _attackablePieces) != 0L); addRegularPly( orgPos, square, capture, capture ? MATERIAL_WIN : REGULAR_PLY); // If we attacked a piece, we cannot move further if( capture) { break; } } else { break; } } // Compute plies upwards. square = orgPos; bitmask = 1L << square; while( square < 56) { square += 8; bitmask <<= 8; if( ( bitmask & (_emptySquares | _attackablePieces)) != 0) { boolean capture = ( (bitmask & _attackablePieces) != 0L); addRegularPly( orgPos, square, capture, capture ? MATERIAL_WIN : REGULAR_PLY); // If we attacked a piece, we cannot move further if( capture) { 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 + -