25 unsigned char rankLookupTable[256][256][8];
27 unsigned char doRankComparison(
unsigned char allPieces,
28 unsigned char enemyPieces,
32 void initLookupTable()
34 for(
int i = 0; i < 256; i++)
36 for (
int j = 0; j < 256; j++)
38 for (
int k = 0; k < 8; k++)
40 rankLookupTable[i][j][k] = doRankComparison(i, j, k);
47 unsigned char rankComparison(
unsigned char allPieces,
48 unsigned char enemyPieces,
51 return rankLookupTable[allPieces][enemyPieces][file];
55 inline unsigned char doRankComparison(
unsigned char allPieces,
56 unsigned char enemyPieces,
60 unsigned char toRet = 0;
112 for (
int i = file+1; i < 8; i++)
114 if ( ((allPieces << i) & 0x80) == 0)
123 if ((enemyPieces << i) & 0x80)
130 for (
int i = file-1; i >= 0; i--)
132 if ( ((allPieces << i) & 0x80) == 0)
139 if ((enemyPieces << i) & 0x80)
149 unsigned char rankAll = allPieces.
getRank(pos.row);
150 unsigned char rankEnemy = enemyPieces.
getRank(pos.row);
151 unsigned char retRank = rankComparison(rankAll, rankEnemy, pos.col);
154 toRet.
setRank(pos.row, retRank);
158 rankAll = allPieces.
getRank(pos.col);
159 rankEnemy = enemyPieces.
getRank(pos.col);
160 retRank = rankComparison(rankAll, rankEnemy, pos.row);
162 toRet2.
setRank(pos.col, retRank);
165 return toRet | toRet2;
170 int allPiecesFile, enemyPiecesFile;
171 unsigned char rankAll = allPieces.getDiagonalRank45(pos.row, pos.col, &allPiecesFile);
172 unsigned char rankEnemy = enemyPieces.getDiagonalRank45(pos.row, pos.col, &enemyPiecesFile);
173 unsigned char retRank = rankComparison(rankAll, rankEnemy, allPiecesFile);
176 toRet.setDiagonalRank45(pos.row, pos.col, retRank);
178 rankAll = allPieces.getDiagonalRank315(pos.row, pos.col, &allPiecesFile);
179 rankEnemy = enemyPieces.getDiagonalRank315(pos.row, pos.col, &enemyPiecesFile);
180 retRank = rankComparison(rankAll, rankEnemy, allPiecesFile);
183 toRet2.setDiagonalRank315(pos.row, pos.col, retRank);
185 return toRet | toRet2;
190 return rookMoves(allPieces, enemyPieces, pos) | bishopMoves(allPieces, enemyPieces, pos);
193 unsigned char kJumpTable[] = {0,1,0,1,0,0,0,0,
205 kTable.shift(pos.col-2, pos.row-2);
210 Bitboard noFriendlyPieces = noPieces | enemyPieces;
211 return kTable & noFriendlyPieces;
214 unsigned char KJumpTable[] = {1,1,1,0,0,0,0,0,
222 unsigned char leftCastleSquares[] = {0,1,1,1,0,0,0,0,
230 unsigned char rightCastleSquares[] = {0,0,0,0,0,1,1,0,
238 unsigned char leftCastleMove [] = {0,0,1,0,0,0,0,0,
246 unsigned char rightCastleMove [] = {0,0,0,0,0,0,1,0,
256 bool rightRookMoved,
bool kingMoved)
259 kTable.shift(pos.col-1, pos.row-1);
264 Bitboard noFriendlyPieces = noPieces | enemyPieces;
265 Bitboard toRet = kTable & noFriendlyPieces;
268 if (!kingMoved && (!rightRookMoved || !leftRookMoved))
273 if ( (allPieces &
Bitboard(rightCastleSquares)).empty() )
275 toRet = toRet |
Bitboard(rightCastleMove);
281 if ( (allPieces &
Bitboard(leftCastleSquares)).empty() )
283 toRet = toRet |
Bitboard(leftCastleMove);
290 unsigned char pawnMove[] = {0,0,0,0,0,0,0,0,
298 unsigned char pawnInitial[] ={0,0,0,0,0,0,0,0,
306 unsigned char pawnAttack[]={0,0,0,0,0,0,0,0,
325 move->shift(pos.col, pos.row);
332 attack.shift(pos.col-1, pos.row);
335 Bitboard finalMove = *move & (~allPieces);
340 Bitboard noFriendlyPieces = noPieces | enemyPieces;
341 finalMove = finalMove & noFriendlyPieces;
344 Bitboard finalAttack = attack & enemyPieces;
347 finalAttack = finalAttack | (attack & enemyPawnsEnPassant);
349 return finalMove | finalAttack;
356 attack.shift(pos.col-1, pos.row);
359 Bitboard finalAttack = attack & enemyPieces;
362 finalAttack = finalAttack | (attack & enemyPawnsEnPassant);
unsigned char getRank(int n)
void setRank(int n, unsigned char c)