-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.h
73 lines (53 loc) · 1.43 KB
/
board.h
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
70
71
72
73
#ifndef BOARD_H
#define BOARD_H
#define BACKGROUND_DEFAULT "\033[37m\033[40m"
#define BOARD_SIZE 8
#define HISTSIZE 4096 // Max number of moves that will be stored in the history
// This is used for the player color
typedef enum {
BLACK = 0,
WHITE = 1
} Color;
// This struct is a position on the board; i is the vertical index, j is the horizontal index
typedef struct {
unsigned char i:3;
unsigned char j:3;
} Pos;
// This is the structure of a move; It contains the source and destination positions
typedef struct {
Pos src;
Pos dst;
} Move;
// This enumerates the pieces; When you add each one to the character at index [2] of the BASE string you get the string of that piece
typedef enum {
KING_B,
QUEEN_B,
ROOK_B,
BISHOP_B,
KNIGHT_B,
PAWN_B,
KING_W,
QUEEN_W,
ROOK_W,
BISHOP_W,
KNIGHT_W,
PAWN_W,
EMPTY
} Piece;
typedef enum {
WAITING,
MY_TURN,
BAD_MOVE,
CHECKED
} Status;
void initialize_board();
void print_board(const Move *, const Move *, const Color, const bool selected);
Status move_piece(const Move *, const Move *, const Color);
Piece pieceat(const Pos *);
Piece pieceatindex(const int i, const int j);
void setpiece(const Pos *, const Piece);
void setpiece_index(int, int, const Piece);
bool has_moved(const Pos);
bool threatened(const Pos*, const Color, const Move *);
bool threatened_index(int, int, const Color, const Move *);
#endif