summaryrefslogtreecommitdiffstats
path: root/gnu/games/chess/Xchess/xchess.h
blob: 355731d8b4039b3da5061df410cca692ba81c56e (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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301

/* This file contains code for X-CHESS.
   Copyright (C) 1986 Free Software Foundation, Inc.

This file is part of X-CHESS.

X-CHESS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.  No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing.  Refer to the X-CHESS General Public
License for full details.

Everyone is granted permission to copy, modify and redistribute
X-CHESS, but only under the conditions described in the
X-CHESS General Public License.   A copy of this license is
supposed to have been given to you along with X-CHESS so you
can know your rights and responsibilities.  It should be in a
file named COPYING.  Among other things, the copyright notice
and this notice must be preserved on all copies.  */


/* RCS Info: $Revision: 1.5 $ on $Date: 86/11/26 12:11:39 $
 *           $Source: /users/faustus/xchess/RCS/xchess.h,v $
 * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
 *	Permission is granted to do anything with this code except sell it
 *	or remove this message.
 *
 * Definitions for the X chess program.
 */

#include "std.h"
#include <X11/Xlib.h>
#include "scrollText/scrollText.h"

#define SIZE	8

typedef enum piecetype { PAWN, ROOK, KNIGHT, BISHOP, QUEEN, KING } piecetype;
typedef enum movetype { MOVE, QCASTLE, KCASTLE, CAPTURE } movetype;
typedef enum color { WHITE, BLACK, NONE } color;

typedef struct piece {
	enum piecetype type;
	enum color color;
} piece;

/* The board has y=0 and black at the top...  This probably isn't the best
 * place to keep track of who can castle, but it's part of the game state...
 */

typedef struct board {
	piece square[SIZE][SIZE];
	bool white_cant_castle_k;
	bool white_cant_castle_q;
	bool black_cant_castle_k;
	bool black_cant_castle_q;
} board;

typedef struct move {
	movetype type;
	piece piece;
	piece taken;
	int fromx, fromy;
	int tox, toy;
	struct move *next;
	bool enpassant;
	bool check;
} move;

#define iswhite(win, i, j)	(!(((i) + (j)) % 2))

/* Stuff for the display. */

typedef struct windata {
	Display *display;
	Window basewin;
	Window boardwin;
	Window recwin;
	Window wclockwin;
	Window bclockwin;
	Window messagewin;
	Window buttonwin;
	Window jailwin;
	Window icon;
	Pixmap iconpixmap;
	XColor blackpiece;
	XColor whitepiece;
	XColor blacksquare;
	XColor whitesquare;
	XColor border;
	XColor textcolor;
	XColor textback;
	XColor errortext;
	XColor playertext;
	XColor cursorcolor;
	XFontStruct *small;
	XFontStruct *medium;
	XFontStruct *large;
	bool bnw;
	color color;
	bool flipped;
	double whitehands[3];
	double blackhands[3];
	char *txtassoc;
} windata;

#define SMALL_FONT	"6x10"
#define MEDIUM_FONT	"8x13"
#define LARGE_FONT	"9x15"
#define JAIL_FONT	"6x10"

#define SQUARE_WIDTH	80
#define SQUARE_HEIGHT	80

#define BORDER_WIDTH	3

#define BOARD_WIDTH	8 * SQUARE_WIDTH + 7 * BORDER_WIDTH
#define BOARD_HEIGHT	8 * SQUARE_HEIGHT + 7 * BORDER_WIDTH
#define BOARD_XPOS	0
#define BOARD_YPOS	0

#define RECORD_WIDTH	265	/* 40 chars * 6 pixels / character. */
#define RECORD_HEIGHT	433
#define RECORD_XPOS	BOARD_WIDTH + BORDER_WIDTH
#define RECORD_YPOS	0

#define JAIL_WIDTH	RECORD_WIDTH
#define JAIL_HEIGHT	163
#define JAIL_XPOS	RECORD_XPOS
#define JAIL_YPOS	RECORD_YPOS + RECORD_HEIGHT + BORDER_WIDTH

#define CLOCK_WIDTH	131
#define CLOCK_HEIGHT	131 + BORDER_WIDTH + 20
#define WCLOCK_XPOS	RECORD_XPOS
#define WCLOCK_YPOS	RECORD_HEIGHT + JAIL_HEIGHT + BORDER_WIDTH * 2
#define BCLOCK_XPOS	WCLOCK_XPOS + CLOCK_WIDTH + BORDER_WIDTH
#define BCLOCK_YPOS	WCLOCK_YPOS

#define MESS_WIDTH	329
#define MESS_HEIGHT	92
#define MESS_XPOS	0
#define MESS_YPOS	BOARD_HEIGHT + BORDER_WIDTH

#define BUTTON_WIDTH	MESS_WIDTH
#define BUTTON_HEIGHT	MESS_HEIGHT
#define BUTTON_XPOS	MESS_WIDTH + BORDER_WIDTH
#define BUTTON_YPOS	MESS_YPOS

#define BASE_WIDTH	BOARD_WIDTH + RECORD_WIDTH + BORDER_WIDTH * 3
#define BASE_HEIGHT	BOARD_HEIGHT + MESS_HEIGHT + BORDER_WIDTH * 3

#define BASE_XPOS	50
#define BASE_YPOS	50

#define BLACK_PIECE_COLOR	"#202020"
#define WHITE_PIECE_COLOR	"#FFFFCC"
#define BLACK_SQUARE_COLOR	"#77A26D"
#define WHITE_SQUARE_COLOR	"#C8C365"
#define BORDER_COLOR		"#902E39"
#define TEXT_COLOR		"#006D6D"
#define TEXT_BACK		"#FFFFDD"
#define ERROR_TEXT		"Red"
#define PLAYER_TEXT		"Blue"
#define CURSOR_COLOR		"#FF606F"

#define DEF_RECORD_FILE		"xchess.game"

#define NUM_FLASHES		5
#define FLASH_SIZE		10

/* xchess.c */

extern void main();
extern bool debug;
extern char *progname;
extern char *proghost;
extern char *piecenames[];
extern char *colornames[];
extern char *movetypenames[];
extern char *dispname1, *dispname2;
extern bool oneboard;
extern bool bnwflag;
extern bool progflag;
extern bool blackflag;
extern bool quickflag;
extern int num_flashes;
extern int flash_size;
extern char *black_piece_color;
extern char *white_piece_color;
extern char *black_square_color;
extern char *white_square_color;
extern char *border_color;
extern char *text_color;
extern char *text_back;
extern char *error_text;
extern char *player_text;
extern char *cursor_color;

/* board.c */

extern void board_setup();
extern void board_drawall();
extern void board_move();
extern board *chessboard;
extern void board_init();

/* window.c */

extern bool win_setup();
extern void win_redraw();
extern void win_restart();
extern void win_drawboard();
extern void win_drawpiece();
extern void win_erasepiece();
extern void win_process();
extern void win_flash();
extern windata *win1, *win2;
extern bool win_flashmove;

/* control.c */

extern void button_pressed();
extern void button_released();
extern void move_piece();
extern void prog_move();
extern move *moves;
extern move *foremoves;
extern color nexttomove;
extern void replay();
extern void forward();
extern void cleanup();
extern void restart();
extern bool noisyflag;

/* valid.c */

extern bool valid_move();

/* record.c */

extern void record_move();
extern void record_reset();
extern void record_save();
extern void record_back();
extern void record_init();
extern void record_end();
extern bool record_english;
extern char *record_file;
extern int movenum;
extern bool saveflag;

/* message.c */

extern void message_init();
extern void message_add();
extern void message_send();

/* clock.c */

extern void clock_init();
extern void clock_draw();
extern void clock_update();
extern void clock_switch();
extern bool clock_started;
extern int movesperunit;
extern int timeunit;
extern int whiteseconds;
extern int blackseconds;

/* button.c */

extern void button_draw();
extern void button_service();

/* jail.c */

extern void jail_init();
extern void jail_draw();
extern void jail_add();
extern void jail_remove();

/* program.c */
extern bool program_init();
extern void program_end();
extern void program_send();
extern void program_undo();
extern move *program_get();

/* parse.c */

extern void load_game();
extern move *parse_file();
extern move *parse_move();
extern move *parse_imove();
extern bool loading_flag;
extern bool loading_paused;

/* popup.c */

extern bool pop_question();

OpenPOWER on IntegriCloud