aboutsummaryrefslogtreecommitdiff
path: root/src/board.c
blob: 59b604330fad376fb3be44181a6a5914b0a83287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include "board.h"

int pop_count(Bitboard bb){
  if (bb == 0) return 0;
  return pop_count(bb >> 1) + (bb & 1);
}

void print_bitboard(Bitboard bb) {
  for (U64 index = 0; index < 64; index++) {
    printf("%lu", (bb >> index) & 1);
    if ((index + 1) % 8 == 0) printf("\n");
  }
  printf("\n\n");
}


void precompute_knight_attack_table(Bitboard attacks[64]) {
  for (int index = 0; index < 64; index++) {
    U64 position = (U64)1 << index;

    attacks[index] =
      ((position & notAFile & notBFile) << 6) |
      ((position & notGFile & notHFile) << 10) |
      ((position & notAFile) << 15) |
      ((position & notHFile) << 17) |
      ((position & notGFile & notHFile) >> 6) |
      ((position & notAFile & notBFile) >> 10) |
      ((position & notHFile) >> 15) |
      ((position & notAFile) >> 17);
  }
}