aboutsummaryrefslogtreecommitdiff
path: root/src/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/board.c')
-rw-r--r--src/board.c19
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++) {