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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/* board.h
*
*/
/*
fics - An internet chess server.
Copyright (C) 1993 Richard V. Nash
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/* Revision history:
name email yy/mm/dd Change
Richard Nash 93/10/22 Created
Markus Uhlin 23/12/24 Revised
*/
#ifndef _BOARD_H
#define _BOARD_H
#define WHITE 0x00
#define BLACK 0x80
#define CString(c) (((c) == WHITE) ? "White" : "Black")
#define CToggle(c) (((c) == BLACK) ? WHITE : BLACK)
/*
* These are indexes into an array so their values are not arbitrary.
*/
#define NOPIECE 0x00
#define PAWN 0x01
#define KNIGHT 0x02
#define BISHOP 0x03
#define ROOK 0x04
#define QUEEN 0x05
#define KING 0x06
#define MAX_BOARD_STRING_LEGTH 1280 /* Arbitrarily 80 * 16 */
#define MAX_STYLES 13
#define MoveToHalfMove(gs) \
((((gs)->moveNum - 1) * 2) + (((gs)->onMove == WHITE) ? 0 : 1))
#define W_PAWN (PAWN | WHITE)
#define W_KNIGHT (KNIGHT | WHITE)
#define W_BISHOP (BISHOP | WHITE)
#define W_ROOK (ROOK | WHITE)
#define W_QUEEN (QUEEN | WHITE)
#define W_KING (KING | WHITE)
#define B_PAWN (PAWN | BLACK)
#define B_KNIGHT (KNIGHT | BLACK)
#define B_BISHOP (BISHOP | BLACK)
#define B_ROOK (ROOK | BLACK)
#define B_QUEEN (QUEEN | BLACK)
#define B_KING (KING | BLACK)
#define isblack(p) ((p) & BLACK)
#define iswhite(p) (!isblack(p))
#define iscolor(p, color) (((p) & BLACK) == (color))
#define colorval(p) ((p) & 0x80)
#define piecetype(p) ((p) & 0x7f)
#define square_color(r, f) ((((r) + (f)) & 0x01) ? BLACK : WHITE)
/* Treated as [file][rank] */
typedef int board_t[8][8];
typedef struct _game_state_t {
board_t board;
/*
* For bughouse
*/
int holding[2][5];
/*
* For castling
*/
unsigned char wkmoved, wqrmoved, wkrmoved;
unsigned char bkmoved, bqrmoved, bkrmoved;
/*
* For ep
*/
int ep_possible[2][8];
/*
* For draws
*/
int lastIrreversable;
int onMove;
int moveNum;
int gameNum;
} game_state_t;
/*
* If a drop move, then 'fromFile' is ALG_DROP and 'fromRank' is
* piece.
*/
#define ALG_DROP -2
typedef struct _move_t {
int color;
int fromFile, fromRank;
int toFile, toRank;
int pieceCaptured;
int piecePromotionTo;
int enPassant; // 0 = No, 1 = Higher, -1 = Lower
int doublePawn; // Only used for board display
char moveString[8];
char algString[8];
unsigned char FENpos[74];
unsigned int atTime;
unsigned int tookTime;
} move_t;
extern char *wpstring[];
extern char *bpstring[];
extern int pieceValues[7];
extern int style1();
extern int style2();
extern int style3();
extern int style4();
extern int style5();
extern int style6();
extern int style7();
extern int style8();
extern int style9();
extern int style10();
extern int style11();
extern int style12();
extern int style13();
extern char *board_to_string(char *, char *, int, int, game_state_t *,
move_t *, int, int, int, int);
extern char *move_and_time(move_t *);
extern int board_init(game_state_t *, char *, char *);
extern int board_read_file(char *, char *, game_state_t *);
extern void board_calc_strength(game_state_t *, int *, int *);
extern void update_holding(int, int);
extern void wild_init(void);
extern void wild_update(int);
#endif
|