Add files via upload

This commit is contained in:
rektdie authored and GitHub committed 2024-03-02 22:23:36 +01:00
1 parent 98e3f3ca87
commit 9976cb0968
3 files changed
+90 -9

No files matched your search

+2 -1
View File
@@ -9,7 +9,8 @@ int main() {
initLeaperAttacks(); initLeaperAttacks();
pawnAttacks[White][e4].PrintBoard(); system("Color 0a");
maskBishopAttacks(e6).PrintBoard();
return 0; return 0;
} }
+77 -8
View File
@@ -1,17 +1,17 @@
#include "movegen.h" #include "movegen.h"
Bitboard pawnAttacks[2][64]; Bitboard pawnAttacks[2][64];
Bitboard knightAttacks[64];
Bitboard kingAttacks[64];
static Bitboard notAfile = ~files[A];
static Bitboard notHfile = ~files[H];
static Bitboard notABfile = notAfile & ~files[B];
static Bitboard notHGfile = notHfile & ~files[G];
Bitboard maskPawnAttacks(int side, int square) { Bitboard maskPawnAttacks(int side, int square) {
Bitboard attacks; Bitboard attacks;
Bitboard attacker; Bitboard attacker = Bitboard::GetSquare(square);
Bitboard notAfile = ~files[A];
Bitboard notHfile = ~files[H];
Bitboard notABfile = notAfile & ~files[B];
Bitboard notHGfile = notHfile & ~files[G];
attacker.SetBit(square);
// White // White
if (!side) { if (!side) {
@@ -26,9 +26,78 @@ Bitboard maskPawnAttacks(int side, int square) {
return attacks; return attacks;
} }
Bitboard maskKnightAttacks(int square) {
Bitboard attacks;
Bitboard attacker = Bitboard::GetSquare(square);
if (((attacker << noEa + north) & notAfile).GetBoard()) attacks |= (attacker << noEa + north);
if (((attacker << noWe + north) & notHfile).GetBoard()) attacks |= (attacker << noWe + north);
if (((attacker << noWe + west) & notHGfile).GetBoard()) attacks |= (attacker << noWe + west);
if (((attacker << noEa + east) & notABfile).GetBoard()) attacks |= (attacker << noEa + east);
if (((attacker << soWe + south) & notHfile).GetBoard()) attacks |= (attacker << soWe + south);
if (((attacker << soEa + south) & notAfile).GetBoard()) attacks |= (attacker << soEa + south);
if (((attacker << soEa + east) & notABfile).GetBoard()) attacks |= (attacker << soEa + east);
if (((attacker << soWe + west) & notHGfile).GetBoard()) attacks |= (attacker << soWe + west);
return attacks;
}
Bitboard maskKingAttacks(int square) {
Bitboard attacks;
Bitboard attacker = Bitboard::GetSquare(square);
attacks |= (attacker << north);
attacks |= (attacker << south);
if (((attacker << west) & notHfile).GetBoard()) attacks |= (attacker << west);
if (((attacker << soWe) & notHfile).GetBoard()) attacks |= (attacker << soWe);
if (((attacker << soEa) & notAfile).GetBoard()) attacks |= (attacker << soEa);
if (((attacker << east) & notAfile).GetBoard()) attacks |= (attacker << east);
if (((attacker << noEa) & notAfile).GetBoard()) attacks |= (attacker << noEa);
if (((attacker << noWe) & notHfile).GetBoard()) attacks |= (attacker << noWe);
return attacks;
}
Bitboard maskBishopAttacks(int square) {
Bitboard attacks;
// ranks and files
int r, f;
// target rank and files
int tr = square / 8;
int tf = square % 8;
// mask relevant occupancy bits
// North West
for (r = tr + 1, f = tf - 1; r <= 6 && f >= 1; r++, f--) {
attacks |= (1ULL << (r * 8 + f));
}
// North East
for (r = tr + 1, f = tf + 1; r <= 6 && f <= 6; r++, f++) {
attacks |= (1ULL << (r * 8 + f));
}
//South West
for (r = tr - 1, f = tf - 1; r >= 1 && f >= 1; r--, f--) {
attacks |= (1ULL << (r * 8 + f));
}
//South East
for (r = tr - 1, f = tf + 1; r >= 1 && f <= 6; r--, f++) {
attacks |= (1ULL << (r * 8 + f));
}
return attacks;
}
void initLeaperAttacks() { void initLeaperAttacks() {
for (int square = 0; square < 64; square++) { for (int square = 0; square < 64; square++) {
pawnAttacks[White][square] = maskPawnAttacks(White, square); pawnAttacks[White][square] = maskPawnAttacks(White, square);
pawnAttacks[Black][square] = maskPawnAttacks(Black, square); pawnAttacks[Black][square] = maskPawnAttacks(Black, square);
knightAttacks[square] = maskKnightAttacks(square);
kingAttacks[square] = maskKingAttacks(square);
} }
} }
+11
View File
@@ -4,8 +4,19 @@
// pawn attacks table [side][square] // pawn attacks table [side][square]
extern Bitboard pawnAttacks[2][64]; extern Bitboard pawnAttacks[2][64];
extern Bitboard knightAttacks[64];
extern Bitboard kingAttacks[64];
// generate pawn attacks // generate pawn attacks
Bitboard maskPawnAttacks(int square, int side); Bitboard maskPawnAttacks(int square, int side);
// generate knight attacks
Bitboard maskKnightAttacks(int square);
// generate king attacks
Bitboard maskKingAttacks(int square);
// generate bishop attacks
Bitboard maskBishopAttacks(int square);
void initLeaperAttacks(); void initLeaperAttacks();