From 318067f9e66b363b14e684492b7a1af021eb6a20 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 14 Sep 2022 19:15:50 +0300 Subject: feat: add initial attacksToSquare --- src/board.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/board.c') 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 #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); +}; -- cgit v1.2.3