Check-in Lasker-2.2.3 tar ball from samba.org
[capablanca.git] / lasker-2.2.3 / src / board.h
1 /*
2    Copyright (c) 1993 Richard V. Nash.
3    Copyright (C) Andrew Tridgell 2002
4    
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20
21 #ifndef _BOARD_H
22 #define _BOARD_H
23
24 #define WHITE 0x00
25 #define BLACK 0x80
26 #define CString( c ) (  ((c) == WHITE) ? "White" : "Black" )
27 #define CToggle( c ) (  ((c) == BLACK) ? WHITE : BLACK )
28
29 /* These will go into an array */
30
31 #define NOPIECE 0x00
32 #define PAWN 0x01
33 #define KNIGHT 0x02
34 #define BISHOP 0x03
35 #define ROOK 0x04
36 #define QUEEN 0x05
37 #define KING 0x06
38
39 #define MAX_BOARD_STRING_LEGTH 1280     /* Abitrarily 80 * 16 */
40 #define MAX_STYLES 13
41
42 #define W_PAWN (PAWN | WHITE)
43 #define W_KNIGHT (KNIGHT | WHITE)
44 #define W_BISHOP (BISHOP | WHITE)
45 #define W_ROOK (ROOK | WHITE)
46 #define W_QUEEN (QUEEN | WHITE)
47 #define W_KING (KING | WHITE)
48
49 #define B_PAWN (PAWN | BLACK)
50 #define B_KNIGHT (KNIGHT | BLACK)
51 #define B_BISHOP (BISHOP | BLACK)
52 #define B_ROOK (ROOK | BLACK)
53 #define B_QUEEN (QUEEN | BLACK)
54 #define B_KING (KING | BLACK)
55
56 #define isblack(p) ((p) & BLACK)
57 #define iswhite(p) (!isblack(p))
58 #define iscolor(p,color) (((p) & BLACK) == (color))
59 #define piecetype(p) ((p) & 0x7f)
60 #define colorval(p) ((p) & 0x80)
61 #define square_color(r,f) ((((r)+(f)) & 0x01) ? BLACK : WHITE)
62
63 extern int pieceValues[7];
64
65 /* Treated as [file][rank] */
66 typedef int board_t[8][8];
67
68 GENSTRUCT struct game_state_t {
69         int board[8][8];
70         /* for bughouse */
71         int holding[2][5];
72         /* For castling */
73         unsigned char wkmoved, wqrmoved, wkrmoved;
74         unsigned char bkmoved, bqrmoved, bkrmoved;
75         /* for ep */
76         int ep_possible[2][8];
77         /* For draws */
78         int lastIrreversable;
79         int onMove;
80         int moveNum;
81         /* Game num not saved, must be restored when read */
82         int gameNum;
83 };
84
85 #define ALG_DROP -2
86
87 /* bughouse: if a drop move, then fromFile is ALG_DROP and fromRank is piece */
88
89 GENSTRUCT struct move_t {
90         int color;
91         int fromFile, fromRank;
92         int toFile, toRank;
93         int pieceCaptured;
94         int piecePromotionTo;
95         int enPassant; /* 0 = no, 1=higher -1= lower */
96         int doublePawn; /* Only used for board display */
97         char moveString[8]; _NULLTERM
98         char algString[8]; _NULLTERM
99         unsigned char FENpos[74]; _NULLTERM
100         unsigned atTime;
101         unsigned tookTime;
102
103         /* these are used when examining a game */
104         int wTime;
105         int bTime;
106 };
107
108 #define MoveToHalfMove( gs ) ((((gs)->moveNum - 1) * 2) + (((gs)->onMove == WHITE) ? 0 : 1))
109
110 extern const char *wpstring[];
111 extern const char *bpstring[];
112
113 /* the FEN for the default initial position */
114 #define INITIAL_FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w"
115
116 #endif