21 #include "SideState.h" 24 long g_nIsAttacking = 0;
25 long g_nHeuristic = 0;
27 unsigned char initialPawns[] = {0,0,0,0,0,0,0,0,
35 unsigned char initialKnights[] = {0,1,0,0,0,0,1,0,
43 unsigned char initialRooks[] = {1,0,0,0,0,0,0,1,
51 unsigned char initialBishops[] = {0,0,1,0,0,1,0,0,
59 unsigned char initialQueen[] = {0,0,0,1,0,0,0,0,
67 unsigned char initialKing[] = {0,0,0,0,1,0,0,0,
79 knights(initialKnights),
80 bishops(initialBishops),
99 Square SideState::firstRook()
106 Square SideState::firstKnight()
113 Square SideState::firstBishop()
120 Square SideState::firstQueen()
127 Square SideState::firstKing()
136 return nextBoard.getAndClearFirstSetBit();
144 sqBoard.
set(sq.row, sq.col);
147 Bitboard frBoard =
pawns | rooks | knights | bishops | king | queen;
150 Bitboard all = enemyPieces | frBoard;
156 if ( pawnAttackOnly(all, enemyPieces,
Bitboard(), i) & sqBoard )
159 for (
Square i = firstRook();
163 if ( rookMoves(all, enemyPieces, i) & sqBoard )
166 for (
Square i = firstBishop();
170 if ( bishopMoves(all, enemyPieces, i) & sqBoard )
173 for (
Square i = firstQueen();
177 if ( queenMoves(all, enemyPieces, i) & sqBoard )
180 if (!firstKing().invalid() &&
181 (kingMoves (all, enemyPieces, firstKing(),
true,
true,
true)) & sqBoard)
190 return (k.col == m.sCol && k.row == m.eRow &&
191 (m.eCol-m.sCol > 1 || m.eCol-m.sCol < -1));
196 Square startSq(m.sCol, m.sRow);
197 Square endSq(m.eCol, m.eRow);
199 Bitboard allPieces =
pawns|knights|rooks|bishops|queen|king|enemyPieces;
203 if ( pawnMoves(allPieces, enemyPieces, enemyPawnsEnPassant, startSq) &
Bitboard(endSq) )
206 else if (knights &
Bitboard(startSq))
209 if ( knightMoves(allPieces, enemyPieces, startSq) &
Bitboard(endSq) )
215 if ( rookMoves(allPieces, enemyPieces, startSq) &
Bitboard(endSq) )
218 else if (bishops &
Bitboard(startSq))
221 if ( bishopMoves(allPieces, enemyPieces, startSq) &
Bitboard(endSq) )
227 if ( queenMoves(allPieces, enemyPieces, startSq) &
Bitboard(endSq) )
242 mb.
set(m.sRow, m.sCol);
243 mb2.
set(m.eRow, m.eCol);
244 bool operationCompleted =
false;
248 if ( (
pawns & mb) && (m.eRow == 7))
253 case Pawn:
pawns.
set(m.eRow, m.eCol);
break;
254 case Knight: knights.
set(m.eRow, m.eCol);
break;
255 case Bishop: bishops.
set(m.eRow, m.eCol);
break;
256 case Queen: queen.
set(m.eRow, m.eCol);
break;
257 case Rook: rooks.
set(m.eRow, m.eCol);
break;
258 default: printf(
"Oh fuck.\n");
260 operationCompleted =
true;
262 else if ( (
pawns & mb) && ( m.eRow - m.sRow == 2 ) )
266 enPassant.
set(m.sRow+1, m.sCol);
268 else if ( (king & mb) && ( (m.sCol - m.eCol > 1) || (m.eCol - m.sCol > 1)) )
272 king.
set(m.eRow, m.eCol);
291 operationCompleted =
true;
294 if (!operationCompleted)
303 knights = knights & ~mb;
304 knights = knights | mb2;
313 bishops = bishops & ~mb;
314 bishops = bishops | mb2;
333 mb.
set(m.sRow, m.sCol);
334 mb2.
set(m.eRow, m.eCol);
336 bool operationCompleted =
false;
338 if ( (enemyPawns & mb) &&
343 operationCompleted =
true;
349 if (!operationCompleted)
352 rooks = rooks & nmb2;
353 bishops = bishops & nmb2;
354 knights = knights & nmb2;
355 queen = queen & nmb2;
360 extern unsigned char pawnAttack[];
361 unsigned char knightCentre[]={0,0,0,0,0,0,0,0,
370 long SideState::heuristic()
378 for (
Square sq = _pawns.getAndClearFirstSetBit();
380 sq = _pawns.getAndClearFirstSetBit())
384 attack.shift(sq.col-1, sq.row);
386 Bitboard finalAttack = attack & (
pawns|knights|rooks|bishops|queen);
387 while (!finalAttack.getAndClearFirstSetBit().invalid())
395 for (
Square sq = _rooks.getAndClearFirstSetBit();
397 sq = _rooks.getAndClearFirstSetBit())
406 for (
Square sq = _knights.getAndClearFirstSetBit();
408 sq = _knights.getAndClearFirstSetBit())
412 while (!knightsInCentre.getAndClearFirstSetBit().invalid())
420 for (
Square sq = _bishops.getAndClearFirstSetBit();
422 sq = _bishops.getAndClearFirstSetBit())
431 for (
Square sq = _queens.getAndClearFirstSetBit();
433 sq = _queens.getAndClearFirstSetBit())
void friendlyMove(Move m, Piece promotion=Pawn)
bool isAttacking(Square sq, Bitboard enemyPieces)
bool set(int rank, int file)
bool isLegal(Move m, Bitboard enemyPieces, Bitboard enemyPawnsEnPassant)
bool clear(int rank, int file)