diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-09-14 05:27:30 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-09-14 05:27:30 +0300 |
commit | 6f7cfbfcde39a57a59db17882339fa26055b75a0 (patch) | |
tree | b2477a1b5c9fef015b62664e96b054f374ac3e14 /src/board.c | |
parent | 8e1d090e0f5c8d2e72fc1e90c22404a9ef808606 (diff) | |
download | j1chess-6f7cfbfcde39a57a59db17882339fa26055b75a0.tar.gz |
feat: precompute king attack tables
Diffstat (limited to 'src/board.c')
-rw-r--r-- | src/board.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/board.c b/src/board.c index 83fe8ce..a0b1bb7 100644 --- a/src/board.c +++ b/src/board.c @@ -18,7 +18,7 @@ void print_bitboard(Bitboard bb) { void precompute_knight_attack_table(Bitboard attacks[64]) { for (int index = 0; index < 64; index++) { - U64 position = (U64)1 << index; + U64 position = BIT << index; attacks[index] = ((position & notAFile & notBFile) << 6) | @@ -32,6 +32,17 @@ void precompute_knight_attack_table(Bitboard attacks[64]) { } } +void precompute_king_attack_table(Bitboard attacks[64]) { + for (int index = 0; index < 64; index++) { + U64 position = BIT << index; + + attacks[index] = + (position & notAFile) << 7 | (position << 8) | (position & notHFile) << 9 | + (position & notAFile) >> 1 | (position & notHFile) << 1 | + (position & notAFile) >> 9 | (position >> 8) | (position & notHFile) >> 7; + } +} + Board parse_FEN(char* FEN) { Board board; for (int i = 0; i < 12; i++) board.pieces[i] = 0; @@ -42,7 +53,7 @@ Board parse_FEN(char* FEN) { for (int k = 0; k < strlen(FEN); k++) { int c = FEN[k]; int index = rank * 8 + file; - Bitboard position = (Bitboard)1 << index; + Bitboard position = BIT << index; if (c > '0' && c <= '8') file += c - '0'; else { @@ -87,8 +98,6 @@ Board parse_FEN(char* FEN) { rank--; file = -1; // So that it becomes 0 break; - case ' ': // TODO: parse everything after - return board; } file++; } @@ -103,7 +112,7 @@ void print_board(Board board) { printf("%i|", rank + 1); for (int file = 0; file < 8; file++) { int index = rank * 8 + file; - Bitboard position = (Bitboard)1 << index; + Bitboard position = BIT << index; int found = 0; for (int piece = 0; piece < 12; piece++) { |