2 Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3 Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
4 Copyright (C) 2008 Marco Costalba
6 Stockfish is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Stockfish is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #if !defined(PIECE_H_INCLUDED)
22 #define PIECE_H_INCLUDED
39 PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6
43 NO_PIECE = 0, WP = 1, WN = 2, WB = 3, WR = 4, WQ = 5, WK = 6,
44 BP = 9, BN = 10, BB = 11, BR = 12, BQ = 13, BK = 14,
45 EMPTY = 16, OUTSIDE = 17
50 //// Constants and variables
53 const PieceType PieceTypeMin = PAWN;
54 const PieceType PieceTypeMax = KING;
56 extern const int SlidingArray[18];
57 extern const SquareDelta Directions[16][16];
58 extern const SquareDelta PawnPush[2];
65 inline Piece operator+ (Piece p, int i) { return Piece(int(p) + i); }
66 inline void operator++ (Piece &p, int) { p = Piece(int(p) + 1); }
67 inline Piece operator- (Piece p, int i) { return Piece(int(p) - i); }
68 inline void operator-- (Piece &p, int) { p = Piece(int(p) - 1); }
69 inline PieceType operator+ (PieceType p, int i) {return PieceType(int(p) + i);}
70 inline void operator++ (PieceType &p, int) { p = PieceType(int(p) + 1); }
71 inline PieceType operator- (PieceType p, int i) {return PieceType(int(p) - i);}
72 inline void operator-- (PieceType &p, int) { p = PieceType(int(p) - 1); }
74 inline PieceType type_of_piece(Piece p) {
75 return PieceType(int(p) & 7);
78 inline Color color_of_piece(Piece p) {
79 return Color(int(p) >> 3);
82 inline Piece piece_of_color_and_type(Color c, PieceType pt) {
83 return Piece((int(c) << 3) | int(pt));
86 inline Piece pawn_of_color(Color c) {
87 return piece_of_color_and_type(c, PAWN);
90 inline Piece knight_of_color(Color c) {
91 return piece_of_color_and_type(c, KNIGHT);
94 inline Piece bishop_of_color(Color c) {
95 return piece_of_color_and_type(c, BISHOP);
98 inline Piece rook_of_color(Color c) {
99 return piece_of_color_and_type(c, ROOK);
102 inline Piece queen_of_color(Color c) {
103 return piece_of_color_and_type(c, QUEEN);
106 inline Piece king_of_color(Color c) {
107 return piece_of_color_and_type(c, KING);
110 inline int piece_is_slider(Piece p) {
111 return SlidingArray[int(p)];
114 inline int piece_type_is_slider(PieceType pt) {
115 return SlidingArray[int(pt)];
118 inline SquareDelta pawn_push(Color c) {
127 extern char piece_type_to_char(PieceType pt, bool upcase);
128 extern PieceType piece_type_from_char(char c);
129 extern bool piece_is_ok(Piece pc);
130 extern bool piece_type_is_ok(PieceType pt);
133 #endif // !defined(PIECE_H_INCLUDED)