removed attack maps

This commit is contained in:
rektdie committed 2025-03-24 02:08:26 +01:00
1 parent f0cd9d0ee0
commit d0ba47c956
6 files changed
+14 -38

No files matched your search

+4 -11
View File
@@ -16,7 +16,6 @@ void Board::Reset() {
colors = std::array<Bitboard, 2>();
moveList = std::array<Move, 218>();
attackMaps = std::array<std::array<U64, 64>, 2>();
currentMoveIndex = 0;
@@ -149,18 +148,12 @@ int Board::GetPieceColor(int square) {
return (colors[Black].IsSet(square));
}
U64 Board::GetAttackMaps(bool side) {
U64 combined = 0ULL;
for (int type = Pawn; type <= King; type++) {
combined |= attackMaps[side][type];
}
return combined;
bool Board::InCheck() {
// TODO
}
bool Board::InCheck() {
Bitboard myKingSquare = colors[sideToMove] & pieces[King];
return GetAttackMaps(!sideToMove) & myKingSquare;
bool Board::IsLegal(Move &move) {
// TODO
}
void Board::SetPiece(int piece, int square, bool color) {
+2 -4
View File
@@ -18,8 +18,6 @@ public:
std::array<Bitboard, 6> pieces;
std::array<Bitboard, 2> colors;
std::array<std::array<U64, 64>, 2> attackMaps;
//U64 attackMaps[2][64];
Bitboard occupied;
@@ -44,9 +42,9 @@ public:
int GetPieceType(int square);
int GetPieceColor(int square);
U64 GetAttackMaps(bool side);
bool InCheck();
bool IsLegal(Move &move);
void SetPiece(int piece, int square, bool color);
void RemovePiece(int piece, int square, bool color);
-12
View File
@@ -299,18 +299,6 @@ Bitboard getPawnPushes(int square, bool color, Bitboard &occupancy) {
return pushes;
}
// Returns bitboard of checkers
static Bitboard Checkers(Board &board, bool color) {
int kingSquare = (board.colors[color] & board.pieces[King]).getLS1BIndex();
Bitboard checkerBoard = 0ULL;
for (int type = Pawn; type < King; type++) {
Bitboard targets = getPieceAttacks(kingSquare, type, color, board.occupied);
checkerBoard |= targets & board.pieces[type] & board.colors[!color];
}
return checkerBoard;
}
// Returns the direction to target from square
static int GetDirection(int square, int target) {
int rankDiff = (target / 8) - (square / 8);
+1
View File
@@ -21,6 +21,7 @@ Bitboard getBishopAttack(int square, U64 occupancy);
Bitboard getRookAttack(int square, U64 occupancy);
Bitboard getQueenAttack(int square, U64 occupancy);
Bitboard getPawnPushes(int square, bool color, Bitboard &occupancy);
Bitboard getPieceAttacks(int square, int piece, int color, U64 occupancy);
template <MovegenMode mode>
void GenPawnMoves(Board &board);
+3 -5
View File
@@ -272,7 +272,7 @@ template <MovegenMode mode>
void GenKingMoves(Board &board) {
int kingSquare = (board.colors[board.sideToMove] & board.pieces[King]).getLS1BIndex();
Bitboard moves = (kingAttacks[kingSquare] & ~board.GetAttackMaps(!board.sideToMove)) & ~board.colors[board.sideToMove];
Bitboard moves = (kingAttacks[kingSquare] & ~board.colors[board.sideToMove]);
Bitboard captures = moves & board.colors[!board.sideToMove];
moves &= ~board.colors[!board.sideToMove];
@@ -313,8 +313,7 @@ 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
&& !(mask & board.GetAttackMaps(!board.sideToMove))) {
if ((Bitboard(QueenSide) & board.occupied).PopCount() == 2) {
board.AddMove(Move(kingSquare, targetSquare, queenCastle));
}
}
@@ -323,8 +322,7 @@ 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
&& !(mask & board.GetAttackMaps(!board.sideToMove))) {
if ((Bitboard(KingSide) & board.occupied).PopCount() == 2) {
board.AddMove(Move(kingSquare, targetSquare, kingCastle));
}
}
+4 -6
View File
@@ -12,10 +12,9 @@ static U64 HelperPerft(Board board, int depth) {
for (int i = 0; i < board.currentMoveIndex; i++) {
Board copy = board;
board.MakeMove(board.moveList[i]);
nodes += HelperPerft(board, depth - 1);
copy.MakeMove(board.moveList[i]);
nodes += HelperPerft(copy, depth - 1);
positionIndex--;
board = copy;
}
return nodes;
}
@@ -28,10 +27,9 @@ void Perft(Board &board, int depth) {
Stopwatch sw;
for (int i = 0; i < board.currentMoveIndex; i++) {
Board copy = board;
board.MakeMove(board.moveList[i]);
U64 nodeCount = HelperPerft(board, depth - 1);
copy.MakeMove(board.moveList[i]);
U64 nodeCount = HelperPerft(copy, depth - 1);
positionIndex--;
board = copy;
totalNodes += nodeCount;
board.moveList[i].PrintMove();