aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: 97e5d14c1dce6ec17d02bd5b3f6626c6d0e0e46f (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
33
34
35
36
37
38
39
40
41
#include "unittest.h"
#include "board.h"

int main() {
  {
    start_test_section("Bitboards");
    unit_test(pop_count(0b01110) == 3, "Pop count of 01110 is 3");
  }

  {
    start_test_section("Test knight attacks");
    Bitboard attacks[64];
    precompute_knight_attack_table(attacks);

    int max_attacks = 0;
    for (int i = 0; i < 64; i++) {
      int attack_count = pop_count(attacks[i]);
      if (attack_count > max_attacks) max_attacks = attack_count;
    }
    unit_test(max_attacks == 8, "Max amount of knight attacks should be 8");

    {
      U64 bit = 1;
      unit_test(
          attacks[b7] == ((bit << d8) | (bit << d6) | (bit << c5) | (bit << a5)),
          "Knight on b7 attacks only d8, d6, c5, a5"
      );
    }
  }

  {
    start_test_section("FEN String");
    Board board = parse_FEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
    unit_test(pop_count(board.pieces[PAWN] | board.pieces[PAWN | BLACK]) == 16, "Default position has 16 pawns total");
    unit_test(pop_count(board.pieces[ROOK]) == 2, "Default position has 2 white rooks");
    unit_test(board.side == WHITE, "Side to moveSide to move is white");
  }

  report();
  return 0;
}