aboutsummaryrefslogtreecommitdiff
path: root/src/board.c
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-09-14 19:15:50 +0300
committereug-vs <eugene@eug-vs.xyz>2022-09-14 19:15:50 +0300
commit318067f9e66b363b14e684492b7a1af021eb6a20 (patch)
tree61008e7dc3b9aa4efb8e07ff83bcc42db2acabb0 /src/board.c
parenta881be4856c6d3dc7675059d5a635d34434b5797 (diff)
downloadj1chess-318067f9e66b363b14e684492b7a1af021eb6a20.tar.gz
feat: add initial attacksToSquare
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);
+};