aboutsummaryrefslogtreecommitdiff
path: root/src/board.h
blob: b63b4941a716dbc23ab957238ac8b22f035f1471 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "bitboard.h"

#define WHITE  0b0000
#define BLACK  0b0001

#define PAWN   0b0000
#define KNIGHT 0b0010
#define BISHOP 0b0100
#define ROOK   0b0110
#define QUEEN  0b1000
#define KING   0b1010

typedef struct {
  Bitboard pieces[12];
  BYTE side;
  BYTE castlingRights;
  BYTE enPassantSquare;
} Board;

typedef enum enumSquare {
  a1, b1, c1, d1, e1, f1, g1, h1,
  a2, b2, c2, d2, e2, f2, g2, h2,
  a3, b3, c3, d3, e3, f3, g3, h3,
  a4, b4, c4, d4, e4, f4, g4, h4,
  a5, b5, c5, d5, e5, f5, g5, h5,
  a6, b6, c6, d6, e6, f6, g6, h6,
  a7, b7, c7, d7, e7, f7, g7, h7,
  a8, b8, c8, d8, e8, f8, g8, h8
} enumSquare;

static const char* notation[64] = {
  "a1", "b1", "c1", "d1", "e1", "f1", "g1", "h1",
  "a2", "b2", "c2", "d2", "e2", "f2", "g2", "h2",
  "a3", "b3", "c3", "d3", "e3", "f3", "g3", "h3",
  "a4", "b4", "c4", "d4", "e4", "f4", "g4", "h4",
  "a5", "b5", "c5", "d5", "e5", "f5", "g5", "h5",
  "a6", "b6", "c6", "d6", "e6", "f6", "g6", "h6",
  "a7", "b7", "c7", "d7", "e7", "f7", "g7", "h7",
  "a8", "b8", "c8", "d8", "e8", "f8", "g8", "h8"
};

static const char* pieces[] = {
  "♟︎", "♙",
  "♞", "♘",
  "♝", "♗",
  "♜", "♖",
  "♛", "♕",
  "♚", "♔",
};

#define notAFile 0xFEFEFEFEFEFEFEFE
#define notBFile 0xFDFDFDFDFDFDFDFD
#define notGFile 0xBFBFBFBFBFBFBFBF
#define notHFile 0x7F7F7F7F7F7F7F7F

Board parseFEN(char* FEN);

void printBoard(Board board);

void precomputeKnightAttackTable(Bitboard table[64]);
void precomputeKingAttackTable(Bitboard table[64]);
void precomputePawnAttackTable(Bitboard table[64], BYTE color);

extern Bitboard KNIGHT_ATTACKS[64];
extern Bitboard WHITE_PAWN_ATTACKS[64];
extern Bitboard BLACK_PAWN_ATTACKS[64];

Bitboard attacksToSquare(Board board, enumSquare sq);