aboutsummaryrefslogtreecommitdiff
path: root/src/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/board.c')
-rw-r--r--src/board.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/board.c b/src/board.c
index c5c4eb2..e87a666 100644
--- a/src/board.c
+++ b/src/board.c
@@ -2,6 +2,10 @@
#include <string.h>
#include "board.h"
+Bitboard KNIGHT_ATTACKS[64];
+Bitboard WHITE_PAWN_ATTACKS[64];
+Bitboard BLACK_PAWN_ATTACKS[64];
+
Board parseFEN(char* FEN) {
Board board;
for (int i = 0; i < 12; i++) board.pieces[i] = 0;
@@ -125,3 +129,15 @@ void precomputePawnAttackTable(Bitboard attacks[64], BYTE color) {
}
}
+
+/* Given a TO square return all pseudo-legal FROM squares which attack or protect that square
+ * In order to be color-specific, intersect the result with appropriate color bitboard */
+Bitboard attacksToSquare(Board board, enumSquare sq) {
+ Bitboard knights = board.pieces[KNIGHT] | board.pieces[KNIGHT | BLACK];
+ Bitboard whitePawns = board.pieces[PAWN];
+ Bitboard blackPawns = board.pieces[PAWN | BLACK];
+
+ return (KNIGHT_ATTACKS[sq] & knights)
+ | (BLACK_PAWN_ATTACKS[sq] & whitePawns)
+ | (WHITE_PAWN_ATTACKS[sq] & blackPawns);
+};