Pseudo legal #28
No files matched your search
@@ -14,6 +14,7 @@ void Board::Reset() {
|
||||
|
||||
pieces = std::array<Bitboard, 6>();
|
||||
colors = std::array<Bitboard, 2>();
|
||||
threatMaps = std::array<std::array<U64, 64>, 2>();
|
||||
|
||||
moveList = std::array<Move, 218>();
|
||||
|
||||
@@ -128,6 +129,14 @@ void Board::ResetMoves() {
|
||||
currentMoveIndex = 0;
|
||||
}
|
||||
|
||||
U64 Board::GetThreatMaps(bool side) {
|
||||
U64 combined = 0ULL;
|
||||
for (int type = Pawn; type <= King; type++) {
|
||||
combined |= threatMaps[side][type];
|
||||
}
|
||||
return combined;
|
||||
}
|
||||
|
||||
void Board::ListMoves() {
|
||||
for (int i = 0; i < currentMoveIndex; i++) {
|
||||
std::cout << i+1 << ". ";
|
||||
|
||||
@@ -21,6 +21,8 @@ public:
|
||||
|
||||
Bitboard occupied;
|
||||
|
||||
std::array<std::array<U64, 64>, 2> threatMaps;
|
||||
|
||||
std::array<Move, 218> moveList;
|
||||
int currentMoveIndex = 0;
|
||||
|
||||
@@ -40,6 +42,7 @@ public:
|
||||
void ResetMoves();
|
||||
void ListMoves();
|
||||
|
||||
U64 GetThreatMaps(bool side);
|
||||
int GetPieceType(int square);
|
||||
int GetPieceColor(int square);
|
||||
|
||||
|
||||
+31
-1
@@ -412,4 +412,34 @@ static bool IsPinned(Board &board, int square) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void GenThreatMaps(Board &board) {
|
||||
for (int color = White; color <= Black; color++) {
|
||||
for (int type = Pawn; type <= King; type++) {
|
||||
board.threatMaps[color][type] = 0ULL;
|
||||
Bitboard pieces = board.pieces[type] & board.colors[color];
|
||||
|
||||
while (pieces) {
|
||||
int square = pieces.getLS1BIndex();
|
||||
if (type == Pawn) {
|
||||
board.threatMaps[color][type] |= pawnAttacks[color][square];
|
||||
} else if (type == Knight) {
|
||||
board.threatMaps[color][type] |= knightAttacks[square];
|
||||
} else if (type == King) {
|
||||
board.threatMaps[color][type] |= kingAttacks[square];
|
||||
} else if (type == Rook) {
|
||||
board.threatMaps[color][type] |= getRookAttack(square, board.occupied
|
||||
& ~(board.colors[!color] & board.pieces[King]));
|
||||
} else if (type == Bishop) {
|
||||
board.threatMaps[color][type] |= getBishopAttack(square, board.occupied
|
||||
& ~(board.colors[!color] & board.pieces[King]));
|
||||
} else if (type == Queen) {
|
||||
board.threatMaps[color][type] |= getQueenAttack(square, board.occupied
|
||||
& ~(board.colors[!color] & board.pieces[King]));
|
||||
}
|
||||
pieces.PopBit(square);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -39,7 +39,7 @@ void GenKingMoves(Board &board);
|
||||
template <MovegenMode mode>
|
||||
void GenerateMoves(Board &board);
|
||||
|
||||
|
||||
void GenThreatMaps(Board &board);
|
||||
|
||||
// bishop relevant occupancy bit count
|
||||
constexpr int bishopRelevantBits[64] = {
|
||||
@@ -199,4 +199,4 @@ constexpr U64 bishopMagicNumbers[64] = {
|
||||
0x4010011029020020ULL
|
||||
};
|
||||
#include "movegen.tpp"
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -314,7 +314,8 @@ void GenKingMoves(Board &board) {
|
||||
U64 QueenSide = board.sideToMove ? 0x1f00000000000000 : 0x1f;
|
||||
U64 mask = board.sideToMove ? 0x1c00000000000000 : 0x1c;
|
||||
int targetSquare = board.sideToMove ? c8 : c1;
|
||||
if ((Bitboard(QueenSide) & board.occupied).PopCount() == 2) {
|
||||
if ((Bitboard(QueenSide) & board.occupied).PopCount() == 2
|
||||
&& !(mask & board.GetThreatMaps(!board.sideToMove))) {
|
||||
board.AddMove(Move(kingSquare, targetSquare, queenCastle));
|
||||
}
|
||||
}
|
||||
@@ -323,7 +324,8 @@ void GenKingMoves(Board &board) {
|
||||
U64 KingSide = board.sideToMove ? 0xf000000000000000 : 0xf0;
|
||||
U64 mask = board.sideToMove ? 0x7000000000000000 : 0x70;
|
||||
int targetSquare = board.sideToMove ? g8 : g1;
|
||||
if ((Bitboard(KingSide) & board.occupied).PopCount() == 2) {
|
||||
if ((Bitboard(KingSide) & board.occupied).PopCount() == 2
|
||||
&& !(mask & board.GetThreatMaps(!board.sideToMove))) {
|
||||
board.AddMove(Move(kingSquare, targetSquare, kingCastle));
|
||||
}
|
||||
}
|
||||
@@ -332,6 +334,8 @@ void GenKingMoves(Board &board) {
|
||||
template <MovegenMode mode>
|
||||
void GenerateMoves(Board &board) {
|
||||
board.ResetMoves();
|
||||
board.threatMaps = std::array<std::array<U64, 64>, 2>();
|
||||
GenThreatMaps(board);
|
||||
|
||||
GenPawnMoves<mode>(board);
|
||||
GenKnightMoves<mode>(board);
|
||||
@@ -339,4 +343,4 @@ void GenerateMoves(Board &board) {
|
||||
GenBishopMoves<mode>(board);
|
||||
GenRookMoves<mode>(board);
|
||||
GenQueenMoves<mode>(board);
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user