2 Glaurung, a UCI chess playing engine.
3 Copyright (C) 2004-2008 Tord Romstad
5 Glaurung 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 3 of the License, or
8 (at your option) any later version.
10 Glaurung 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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #if !defined(PIECE_H_INCLUDED)
21 #define PIECE_H_INCLUDED
38 PAWN
= 1, KNIGHT
= 2, BISHOP
= 3, ROOK
= 4, QUEEN
= 5, KING
= 6
42 NO_PIECE
= 0, WP
= 1, WN
= 2, WB
= 3, WR
= 4, WQ
= 5, WK
= 6,
43 BP
= 9, BN
= 10, BB
= 11, BR
= 12, BQ
= 13, BK
= 14,
44 EMPTY
= 16, OUTSIDE
= 17
49 //// Constants and variables
52 const PieceType PieceTypeMin
= PAWN
;
53 const PieceType PieceTypeMax
= KING
;
55 extern const int SlidingArray
[18];
56 extern const SquareDelta Directions
[16][16];
57 extern const SquareDelta PawnPush
[2];
64 inline Piece
operator+ (Piece p
, int i
) { return Piece(int(p
) + i
); }
65 inline void operator++ (Piece
&p
, int) { p
= Piece(int(p
) + 1); }
66 inline Piece
operator- (Piece p
, int i
) { return Piece(int(p
) - i
); }
67 inline void operator-- (Piece
&p
, int) { p
= Piece(int(p
) - 1); }
68 inline PieceType
operator+ (PieceType p
, int i
) {return PieceType(int(p
) + i
);}
69 inline void operator++ (PieceType
&p
, int) { p
= PieceType(int(p
) + 1); }
70 inline PieceType
operator- (PieceType p
, int i
) {return PieceType(int(p
) - i
);}
71 inline void operator-- (PieceType
&p
, int) { p
= PieceType(int(p
) - 1); }
73 inline PieceType
type_of_piece(Piece p
) {
74 return PieceType(int(p
) & 7);
77 inline Color
color_of_piece(Piece p
) {
78 return Color(int(p
) >> 3);
81 inline Piece
piece_of_color_and_type(Color c
, PieceType pt
) {
82 return Piece((int(c
) << 3) | int(pt
));
85 inline Piece
pawn_of_color(Color c
) {
86 return piece_of_color_and_type(c
, PAWN
);
89 inline Piece
knight_of_color(Color c
) {
90 return piece_of_color_and_type(c
, KNIGHT
);
93 inline Piece
bishop_of_color(Color c
) {
94 return piece_of_color_and_type(c
, BISHOP
);
97 inline Piece
rook_of_color(Color c
) {
98 return piece_of_color_and_type(c
, ROOK
);
101 inline Piece
queen_of_color(Color c
) {
102 return piece_of_color_and_type(c
, QUEEN
);
105 inline Piece
king_of_color(Color c
) {
106 return piece_of_color_and_type(c
, KING
);
109 inline int piece_is_slider(Piece p
) {
110 return SlidingArray
[int(p
)];
113 inline int piece_type_is_slider(PieceType pt
) {
114 return SlidingArray
[int(pt
)];
117 inline SquareDelta
pawn_push(Color c
) {
126 extern char piece_type_to_char(PieceType pt
, bool upcase
);
127 extern PieceType
piece_type_from_char(char c
);
128 extern bool piece_is_ok(Piece pc
);
129 extern bool piece_type_is_ok(PieceType pt
);
132 #endif // !defined(PIECE_H_INCLUDED)