7 * 12x10 board notation:
9 * xx xx xx xx xx xx xx xx xx xx
10 * xx xx xx xx xx xx xx xx xx xx
11 * xx a1 b1 c1 d1 e1 f1 g1 h1 xx
12 * xx a2 b2 c2 d2 e2 f2 g2 h2 xx
13 * xx a3 b3 c3 d3 e3 f3 g3 h3 xx
14 * xx a4 b4 c4 d4 e4 f4 g4 h4 xx
15 * xx a5 b5 c5 d5 e5 f5 g5 h5 xx
16 * xx a6 b6 c6 d6 e6 f6 g6 h6 xx
17 * xx a7 b7 c7 d7 e7 f7 g7 h7 xx
18 * xx a8 b8 c8 d8 e8 f8 g8 h8 xx
19 * xx xx xx xx xx xx xx xx xx xx
20 * xx xx xx xx xx xx xx xx xx xx
22 * Lower three bits (0x07) encode piece type, fourth bit (0x08) color,
23 * upper four bits (0xf0) the piece index number.
25 #define SQUARE_TO_NUM(file, rank) ((file) + (rank) * 10 + 21)
26 #define NUM_TO_FILE(x) ((x-1) % 10) /* -1 might be faster than -21 */
27 #define NUM_TO_RANK(x) ((x-21) / 10)
30 #define NUM_SQUARES (12*10)
34 #define PIECE_KNIGHT 2
36 #define PIECE_INVALID 4
37 #define PIECE_BISHOP 5
41 #define IS_WHITE(x) (((x) & 0x08) == 0)
42 #define IS_BLACK(x) (((x) & 0x08) != 0)
44 #define SAME_COLOR(x,y) ((((x)^(y)) & 0x08) == 0)
45 #define OPPOSITE_COLOR(x,y) ((((x)^(y)) & 0x08) != 0)
46 #define CAN_GOTO(x,y) ((y) == PIECE_EMPTY || ((y) != PIECE_INVALID && OPPOSITE_COLOR((x),(y))))
48 #define MAKE_WHITE(x) ((x) & 0x07)
49 #define MAKE_BLACK(x) ((x) | 0x08)
50 #define MAKE_COLORLESS(x) ((x) & 0x07)
51 #define FIND_INDEX(x) (((x) & 0xf0) >> 4)
53 #define SLIDES_STRAIGHT(x) (((x) & 0x06) == 0x06)
54 #define SLIDES_DIAGONALLY(x) (((x) & 0x05) == 0x05)
57 unsigned char type; // colorless
61 signed char board[NUM_SQUARES];
62 struct piece black_pieces[16], white_pieces[16];
64 bool wc_short, wc_long, bc_short, bc_long;
65 unsigned char ep_square; // 0 if none
68 void init_position(struct position *pos);
69 void validate_position(const struct position * const pos);
70 char piece_to_char(int piece);
71 void print_position(struct position *pos);
72 void real_make_move(struct position *pos, unsigned from, unsigned to, struct piece *from_ptr, struct piece *to_ptr);
73 void make_move(struct position *pos, unsigned from, unsigned to);
75 #endif /* !defined(_POSITION_H) */