separate attack maps by color and piece type | bench 902872
This commit is contained in:
1 parent
809da11544
commit
120f36ebb6
4 files changed
+23
-32
No files matched your search
+5
-10
@@ -14,7 +14,9 @@ void Board::Reset() {
|
|||||||
|
|
||||||
pieces = std::array<Bitboard, 6>();
|
pieces = std::array<Bitboard, 6>();
|
||||||
colors = std::array<Bitboard, 2>();
|
colors = std::array<Bitboard, 2>();
|
||||||
threatMaps = std::array<std::array<U64, 64>, 2>();
|
|
||||||
|
pieceThreats = std::array<Bitboard, 6>();
|
||||||
|
colorThreats = std::array<Bitboard, 2>();
|
||||||
|
|
||||||
moveList = std::array<Move, 218>();
|
moveList = std::array<Move, 218>();
|
||||||
|
|
||||||
@@ -65,6 +67,7 @@ void Board::SetByFen(std::string_view fen) {
|
|||||||
|
|
||||||
occupied = colors[White] | colors[Black];
|
occupied = colors[White] | colors[Black];
|
||||||
hashKey = UTILS::GetHashKey(*this);
|
hashKey = UTILS::GetHashKey(*this);
|
||||||
|
MOVEGEN::GenThreatMaps(*this);
|
||||||
MOVEGEN::GenerateMoves<All>(*this);
|
MOVEGEN::GenerateMoves<All>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,14 +132,6 @@ void Board::ResetMoves() {
|
|||||||
currentMoveIndex = 0;
|
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() {
|
void Board::ListMoves() {
|
||||||
for (int i = 0; i < currentMoveIndex; i++) {
|
for (int i = 0; i < currentMoveIndex; i++) {
|
||||||
std::cout << i+1 << ". ";
|
std::cout << i+1 << ". ";
|
||||||
@@ -161,7 +156,7 @@ int Board::GetPieceColor(int square) {
|
|||||||
bool Board::InCheck() {
|
bool Board::InCheck() {
|
||||||
Bitboard myKingSquare = colors[sideToMove] & pieces[King];
|
Bitboard myKingSquare = colors[sideToMove] & pieces[King];
|
||||||
|
|
||||||
return GetThreatMaps(!sideToMove) & myKingSquare;
|
return colorThreats[!sideToMove] & myKingSquare;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::SetPiece(int piece, int square, bool color) {
|
void Board::SetPiece(int piece, int square, bool color) {
|
||||||
|
|||||||
+2
-2
@@ -21,7 +21,8 @@ public:
|
|||||||
|
|
||||||
Bitboard occupied;
|
Bitboard occupied;
|
||||||
|
|
||||||
std::array<std::array<U64, 64>, 2> threatMaps;
|
std::array<Bitboard, 6> pieceThreats;
|
||||||
|
std::array<Bitboard, 2> colorThreats;
|
||||||
|
|
||||||
std::array<Move, 218> moveList;
|
std::array<Move, 218> moveList;
|
||||||
int currentMoveIndex = 0;
|
int currentMoveIndex = 0;
|
||||||
@@ -42,7 +43,6 @@ public:
|
|||||||
void ResetMoves();
|
void ResetMoves();
|
||||||
void ListMoves();
|
void ListMoves();
|
||||||
|
|
||||||
U64 GetThreatMaps(bool side);
|
|
||||||
int GetPieceType(int square);
|
int GetPieceType(int square);
|
||||||
int GetPieceColor(int square);
|
int GetPieceColor(int square);
|
||||||
|
|
||||||
|
|||||||
+11
-17
@@ -415,30 +415,24 @@ static bool IsPinned(Board &board, int square) {
|
|||||||
|
|
||||||
void GenThreatMaps(Board &board) {
|
void GenThreatMaps(Board &board) {
|
||||||
for (int color = White; color <= Black; color++) {
|
for (int color = White; color <= Black; color++) {
|
||||||
|
board.colorThreats[color] = 0ULL;
|
||||||
|
|
||||||
for (int type = Pawn; type <= King; type++) {
|
for (int type = Pawn; type <= King; type++) {
|
||||||
board.threatMaps[color][type] = 0ULL;
|
board.pieceThreats[type] = 0ULL;
|
||||||
|
|
||||||
Bitboard pieces = board.pieces[type] & board.colors[color];
|
Bitboard pieces = board.pieces[type] & board.colors[color];
|
||||||
|
|
||||||
while (pieces) {
|
while (pieces) {
|
||||||
int square = pieces.getLS1BIndex();
|
int square = pieces.getLS1BIndex();
|
||||||
if (type == Pawn) {
|
|
||||||
board.threatMaps[color][type] |= pawnAttacks[color][square];
|
board.pieceThreats[type] |= MOVEGEN::getPieceAttacks(square, type, color, board.occupied
|
||||||
} else if (type == Knight) {
|
& ~(board.colors[!color] & board.pieces[King]));
|
||||||
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);
|
pieces.PopBit(square);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
board.colorThreats[color] |= board.pieceThreats[type];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-3
@@ -315,8 +315,9 @@ void GenKingMoves(Board &board) {
|
|||||||
U64 mask = board.sideToMove ? 0x1c00000000000000 : 0x1c;
|
U64 mask = board.sideToMove ? 0x1c00000000000000 : 0x1c;
|
||||||
int targetSquare = board.sideToMove ? c8 : c1;
|
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))) {
|
&& !(mask & board.colorThreats[!board.sideToMove])) {
|
||||||
board.AddMove(Move(kingSquare, targetSquare, queenCastle));
|
board.AddMove(Move(kingSquare, targetSquare, queenCastle));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,7 +326,7 @@ void GenKingMoves(Board &board) {
|
|||||||
U64 mask = board.sideToMove ? 0x7000000000000000 : 0x70;
|
U64 mask = board.sideToMove ? 0x7000000000000000 : 0x70;
|
||||||
int targetSquare = board.sideToMove ? g8 : g1;
|
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))) {
|
&& !(mask & board.colorThreats[!board.sideToMove])) {
|
||||||
board.AddMove(Move(kingSquare, targetSquare, kingCastle));
|
board.AddMove(Move(kingSquare, targetSquare, kingCastle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,7 +335,8 @@ void GenKingMoves(Board &board) {
|
|||||||
template <MovegenMode mode>
|
template <MovegenMode mode>
|
||||||
void GenerateMoves(Board &board) {
|
void GenerateMoves(Board &board) {
|
||||||
board.ResetMoves();
|
board.ResetMoves();
|
||||||
board.threatMaps = std::array<std::array<U64, 64>, 2>();
|
board.pieceThreats = std::array<Bitboard, 6>();
|
||||||
|
board.colorThreats = std::array<Bitboard, 2>();
|
||||||
GenThreatMaps(board);
|
GenThreatMaps(board);
|
||||||
|
|
||||||
GenPawnMoves<mode>(board);
|
GenPawnMoves<mode>(board);
|
||||||
|
|||||||
Reference in new issue
Block a user